]> granicus.if.org Git - docbook-dsssl/commitdiff
Support make.index.markup parameter
authorNorman Walsh <ndw@nwalsh.com>
Wed, 21 Aug 2002 13:57:59 +0000 (13:57 +0000)
committerNorman Walsh <ndw@nwalsh.com>
Wed, 21 Aug 2002 13:57:59 +0000 (13:57 +0000)
xsl/fo/autoidx.xsl

index 6025c2e11cb2b6ff725d95b6501991793f0de05c..decd0abd65abe8611f6e14131f2cc84a12bd0f70 100644 (file)
       <xsl:for-each select="$refs[generate-id() = generate-id(key('primary-section', concat($key, &sep;, &section.id;))[1])]">
         <xsl:apply-templates select="." mode="reference"/>
       </xsl:for-each>
+
+      <xsl:if test="$refs[not(secondary)]/*[self::see]">
+        <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &sep;, &sep;, see))[1])]"
+                             mode="index-see">
+          <xsl:sort select="see"/>
+        </xsl:apply-templates>
+      </xsl:if>
     </xsl:variable>
 
     <xsl:choose>
       </xsl:otherwise>
     </xsl:choose>
   </fo:block>
-  <xsl:if test="$refs/secondary or $refs[not(secondary)]/*[self::see or self::seealso]">
+  <xsl:if test="$refs/secondary or $refs[not(secondary)]/*[self::seealso]">
     <fo:block start-indent="1pc">
-      <fo:block>
-        <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &sep;, &sep;, see))[1])]"
-                             mode="index-see">
-          <xsl:sort select="see"/>
-        </xsl:apply-templates>
-        <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &sep;, &sep;, seealso))[1])]"
-                             mode="index-seealso">
-          <xsl:sort select="seealso"/>
-        </xsl:apply-templates>
-        <xsl:apply-templates select="$refs[secondary and count(.|key('secondary', concat($key, &sep;, &secondary;))[1]) = 1]" 
-                             mode="index-secondary">
-          <xsl:sort select="&secondary;"/>
-        </xsl:apply-templates>
-      </fo:block>
+      <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &sep;, &sep;, seealso))[1])]"
+                           mode="index-seealso">
+        <xsl:sort select="seealso"/>
+      </xsl:apply-templates>
+      <xsl:apply-templates select="$refs[secondary and count(.|key('secondary', concat($key, &sep;, &secondary;))[1]) = 1]"
+                           mode="index-secondary">
+        <xsl:sort select="&secondary;"/>
+      </xsl:apply-templates>
     </fo:block>
   </xsl:if>
 </xsl:template>
       <xsl:for-each select="$refs[generate-id() = generate-id(key('secondary-section', concat($key, &sep;, &section.id;))[1])]">
         <xsl:apply-templates select="." mode="reference"/>
       </xsl:for-each>
+
+      <xsl:if test="$refs[not(tertiary)]/*[self::see]">
+        <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, see))[1])]"
+                             mode="index-see">
+          <xsl:sort select="see"/>
+        </xsl:apply-templates>
+      </xsl:if>
     </xsl:variable>
 
     <xsl:choose>
       </xsl:otherwise>
     </xsl:choose>
   </fo:block>
-  <xsl:if test="$refs/tertiary or $refs[not(tertiary)]/*[self::see or self::seealso]">
+
+  <xsl:if test="$refs/tertiary or $refs[not(tertiary)]/*[self::seealso]">
     <fo:block start-indent="2pc">
-      <fo:block>
-        <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, see))[1])]"
-                             mode="index-see">
-          <xsl:sort select="see"/>
-        </xsl:apply-templates>
-        <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, seealso))[1])]"
-                             mode="index-seealso">
-          <xsl:sort select="seealso"/>
-        </xsl:apply-templates>
-        <xsl:apply-templates select="$refs[tertiary and count(.|key('tertiary', concat($key, &sep;, &tertiary;))[1]) = 1]" 
-                             mode="index-tertiary">
-          <xsl:sort select="&tertiary;"/>
-        </xsl:apply-templates>
-      </fo:block>
+      <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, seealso))[1])]"
+                           mode="index-seealso">
+        <xsl:sort select="seealso"/>
+      </xsl:apply-templates>
+      <xsl:apply-templates select="$refs[tertiary and count(.|key('tertiary', concat($key, &sep;, &tertiary;))[1]) = 1]" 
+                           mode="index-tertiary">
+        <xsl:sort select="&tertiary;"/>
+      </xsl:apply-templates>
     </fo:block>
   </xsl:if>
 </xsl:template>
       <xsl:for-each select="$refs[generate-id() = generate-id(key('tertiary-section', concat($key, &sep;, &section.id;))[1])]">
         <xsl:apply-templates select="." mode="reference"/>
       </xsl:for-each>
+
+      <xsl:if test="$refs/see">
+        <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, see))[1])]"
+                             mode="index-see">
+          <xsl:sort select="see"/>
+        </xsl:apply-templates>
+      </xsl:if>
     </xsl:variable>
 
     <xsl:choose>
       </xsl:otherwise>
     </xsl:choose>
   </fo:block>
-  <xsl:variable name="see" select="$refs/see | $refs/seealso"/>
-  <xsl:if test="$see">
+
+  <xsl:if test="$refs/seealso">
     <fo:block>
-      <fo:block>
-        <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, see))[1])]"
-                             mode="index-see">
-          <xsl:sort select="see"/>
-        </xsl:apply-templates>
-        <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, seealso))[1])]"
-                             mode="index-seealso">
-          <xsl:sort select="seealso"/>
-        </xsl:apply-templates>
-      </fo:block>
+      <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, seealso))[1])]"
+                           mode="index-seealso">
+        <xsl:sort select="seealso"/>
+      </xsl:apply-templates>
     </fo:block>
   </xsl:if>
 </xsl:template>
 </xsl:template>
 
 <xsl:template match="indexterm" mode="index-see">
-   <fo:block><xsl:value-of select="see"/></fo:block>
+   <fo:inline>
+     <xsl:text> (</xsl:text>
+     <xsl:call-template name="gentext">
+       <xsl:with-param name="key" select="'see'"/>
+     </xsl:call-template>
+     <xsl:text> </xsl:text>
+     <xsl:value-of select="see"/>
+     <xsl:text>)</xsl:text>
+   </fo:inline>
 </xsl:template>
 
 <xsl:template match="indexterm" mode="index-seealso">
-   <fo:block><xsl:value-of select="seealso"/></fo:block>
+   <fo:block>
+     <xsl:text>(</xsl:text>
+     <xsl:call-template name="gentext">
+       <xsl:with-param name="key" select="'seealso'"/>
+     </xsl:call-template>
+     <xsl:text> </xsl:text>
+     <xsl:value-of select="seealso"/>
+     <xsl:text>)</xsl:text>
+   </fo:block>
+</xsl:template>
+
+<!-- ====================================================================== -->
+
+<xsl:template name="generate-index-markup">
+  <xsl:variable name="terms" select="//indexterm[count(.|key('letter',
+                                     translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;))[1]) = 1]"/>
+  <xsl:variable name="alphabetical"
+                select="$terms[contains(concat(&lowercase;, &uppercase;),
+                                        substring(&primary;, 1, 1))]"/>
+  <xsl:variable name="others" select="$terms[not(contains(concat(&lowercase;,
+                                                 &uppercase;),
+                                             substring(&primary;, 1, 1)))]"/>
+
+  <xsl:text>&lt;index&gt;&#10;</xsl:text>
+  <xsl:if test="$others">
+    <xsl:text>&#10;&lt;indexdiv&gt;&#10;</xsl:text>
+    <xsl:text>&lt;title&gt;</xsl:text>
+    <xsl:call-template name="gentext">
+      <xsl:with-param name="key" select="'index symbols'"/>
+    </xsl:call-template>
+    <xsl:text>&lt;/title&gt;&#10;</xsl:text>
+    <xsl:apply-templates select="$others[count(.|key('primary',
+                                 &primary;)[1]) = 1]"
+                         mode="index-symbol-div-markup">
+      <xsl:sort select="&primary;"/>
+    </xsl:apply-templates>
+    <xsl:text>&lt;/indexdiv&gt;&#10;</xsl:text>
+  </xsl:if>
+
+  <xsl:apply-templates select="$alphabetical[count(.|key('letter',
+                               translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;))[1]) = 1]"
+                       mode="index-div-markup">
+    <xsl:sort select="&primary;"/>
+  </xsl:apply-templates>
+  <xsl:text>&lt;/index&gt;&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="*" mode="index-markup">
+  <xsl:text>&lt;</xsl:text>
+  <xsl:value-of select="name(.)"/>
+  <xsl:text>&gt;&#10;</xsl:text>
+  <xsl:apply-templates mode="index-markup"/>
+</xsl:template>
+
+<xsl:template match="indexterm" mode="index-div-markup">
+  <xsl:variable name="key" select="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
+  <xsl:text>&#10;&lt;indexdiv&gt;&#10;</xsl:text>
+  <xsl:text>&lt;title&gt;</xsl:text>
+  <xsl:value-of select="translate($key, &lowercase;, &uppercase;)"/>
+  <xsl:text>&lt;/title&gt;&#10;</xsl:text>
+
+  <xsl:apply-templates select="key('letter', $key)[count(.|key('primary', &primary;)[1]) = 1]"
+                       mode="index-primary-markup">
+    <xsl:sort select="&primary;"/>
+  </xsl:apply-templates>
+  <xsl:text>&lt;/indexdiv&gt;&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="indexterm" mode="index-symbol-div-markup">
+  <xsl:variable name="key" select="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
+
+  <xsl:apply-templates select="key('letter', $key)[count(.|key('primary', &primary;)[1]) = 1]"
+                       mode="index-primary-markup">
+    <xsl:sort select="&primary;"/>
+  </xsl:apply-templates>
+</xsl:template>
+
+<xsl:template match="indexterm" mode="index-primary-markup">
+  <xsl:variable name="key" select="&primary;"/>
+  <xsl:variable name="refs" select="key('primary', $key)"/>
+  <xsl:variable name="pages" select="$refs[generate-id() = generate-id(key('primary-section', concat($key, &sep;, &section.id;))[1])]"/>
+
+  <xsl:text>&#10;&lt;indexentry&gt;&#10;</xsl:text>
+  <xsl:text>&lt;primaryie&gt;</xsl:text>
+  <xsl:text>&lt;phrase&gt;</xsl:text>
+  <xsl:call-template name="escape-text">
+    <xsl:with-param name="text" select="string(primary)"/>
+  </xsl:call-template>
+  <xsl:text>&lt;/phrase&gt;</xsl:text>
+  <xsl:if test="$pages">,</xsl:if>
+  <xsl:text>&#10;</xsl:text>
+
+  <xsl:for-each select="$pages">
+    <xsl:apply-templates select="." mode="reference-markup"/>
+  </xsl:for-each>
+
+  <xsl:text>&lt;/primaryie&gt;&#10;</xsl:text>
+
+  <xsl:if test="$refs/secondary or $refs[not(secondary)]/*[self::see or self::seealso]">
+    <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &sep;, &sep;, see))[1])]"
+                         mode="index-see-markup">
+      <xsl:sort select="see"/>
+    </xsl:apply-templates>
+
+    <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &sep;, &sep;, seealso))[1])]"
+                         mode="index-seealso-markup">
+      <xsl:sort select="seealso"/>
+    </xsl:apply-templates>
+
+    <xsl:apply-templates select="$refs[secondary and count(.|key('secondary', concat($key, &sep;, &secondary;))[1]) = 1]" 
+                         mode="index-secondary-markup">
+      <xsl:sort select="&secondary;"/>
+    </xsl:apply-templates>
+  </xsl:if>
+  <xsl:text>&lt;/indexentry&gt;&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="indexterm" mode="index-secondary-markup">
+  <xsl:variable name="key" select="concat(&primary;, &sep;, &secondary;)"/>
+  <xsl:variable name="refs" select="key('secondary', $key)"/>
+  <xsl:variable name="pages" select="$refs[generate-id() = generate-id(key('secondary-section', concat($key, &sep;, &section.id;))[1])]"/>
+
+  <xsl:text>&lt;secondaryie&gt;</xsl:text>
+  <xsl:text>&lt;phrase&gt;</xsl:text>
+  <xsl:call-template name="escape-text">
+    <xsl:with-param name="text" select="string(secondary)"/>
+  </xsl:call-template>
+  <xsl:text>&lt;/phrase&gt;</xsl:text>
+  <xsl:if test="$pages">,</xsl:if>
+  <xsl:text>&#10;</xsl:text>
+
+  <xsl:for-each select="$pages">
+    <xsl:apply-templates select="." mode="reference-markup"/>
+  </xsl:for-each>
+
+  <xsl:text>&lt;/secondaryie&gt;&#10;</xsl:text>
+
+  <xsl:if test="$refs/tertiary or $refs[not(tertiary)]/*[self::see or self::seealso]">
+    <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, see))[1])]"
+                         mode="index-see-markup">
+      <xsl:sort select="see"/>
+    </xsl:apply-templates>
+    <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, seealso))[1])]"
+                         mode="index-seealso-markup">
+      <xsl:sort select="seealso"/>
+    </xsl:apply-templates>
+    <xsl:apply-templates select="$refs[tertiary and count(.|key('tertiary', concat($key, &sep;, &tertiary;))[1]) = 1]" 
+                         mode="index-tertiary-markup">
+      <xsl:sort select="&tertiary;"/>
+    </xsl:apply-templates>
+  </xsl:if>
+</xsl:template>
+
+<xsl:template match="indexterm" mode="index-tertiary-markup">
+  <xsl:variable name="key" select="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;)"/>
+  <xsl:variable name="refs" select="key('tertiary', $key)"/>
+  <xsl:variable name="pages" select="$refs[generate-id() = generate-id(key('tertiary-section', concat($key, &sep;, &section.id;))[1])]"/>
+
+  <xsl:text>&lt;tertiaryie&gt;</xsl:text>
+  <xsl:text>&lt;phrase&gt;</xsl:text>
+  <xsl:call-template name="escape-text">
+    <xsl:with-param name="text" select="string(tertiary)"/>
+  </xsl:call-template>
+  <xsl:text>&lt;/phrase&gt;</xsl:text>
+  <xsl:if test="$pages">,</xsl:if>
+  <xsl:text>&#10;</xsl:text>
+
+  <xsl:for-each select="$pages">
+    <xsl:apply-templates select="." mode="reference-markup"/>
+  </xsl:for-each>
+
+  <xsl:text>&lt;/tertiaryie&gt;&#10;</xsl:text>
+
+  <xsl:variable name="see" select="$refs/see | $refs/seealso"/>
+  <xsl:if test="$see">
+    <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, see))[1])]"
+                         mode="index-see-markup">
+      <xsl:sort select="see"/>
+    </xsl:apply-templates>
+    <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, seealso))[1])]"
+                         mode="index-seealso-markup">
+      <xsl:sort select="seealso"/>
+    </xsl:apply-templates>
+  </xsl:if>
+</xsl:template>
+
+<xsl:template match="indexterm" mode="reference-markup">
+  <xsl:choose>
+    <xsl:when test="@zone and string(@zone)">
+      <xsl:call-template name="reference-markup">
+        <xsl:with-param name="zones" select="normalize-space(@zone)"/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:variable name="id">
+        <xsl:call-template name="object.id"/>
+      </xsl:variable>
+
+      <xsl:text>&lt;phrase role="pageno"&gt;</xsl:text>
+      <xsl:if test="@id">
+        <xsl:text>&lt;link linkend="</xsl:text>
+        <xsl:value-of select="$id"/>
+        <xsl:text>"&gt;</xsl:text>
+      </xsl:if>
+      <fo:basic-link internal-destination="{$id}">
+        <fo:page-number-citation ref-id="{$id}"/>
+      </fo:basic-link>
+      <xsl:if test="@id">
+        <xsl:text>&lt;/link&gt;</xsl:text>
+      </xsl:if>
+      <xsl:text>&lt;/phrase&gt;&#10;</xsl:text>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template name="reference-markup">
+  <xsl:param name="zones"/>
+  <xsl:choose>
+    <xsl:when test="contains($zones, ' ')">
+      <xsl:variable name="zone" select="substring-before($zones, ' ')"/>
+      <xsl:variable name="target" select="key('sections', $zone)"/>
+
+      <xsl:variable name="id">
+        <xsl:call-template name="object.id">
+          <xsl:with-param name="object" select="$target[1]"/>
+        </xsl:call-template>
+      </xsl:variable>
+
+      <xsl:text>&lt;phrase fole="pageno"&gt;</xsl:text>
+      <xsl:if test="$target[1]/@id">
+        <xsl:text>&lt;link linkend="</xsl:text>
+        <xsl:value-of select="$id"/>
+        <xsl:text>"&gt;</xsl:text>
+      </xsl:if>
+      <fo:basic-link internal-destination="{$id}">
+        <fo:page-number-citation ref-id="{$id}"/>
+      </fo:basic-link>
+      <xsl:if test="$target[1]/@id">
+        <xsl:text>&lt;/link&gt;</xsl:text>
+      </xsl:if>
+      <xsl:text>&lt;/phrase&gt;&#10;</xsl:text>
+
+      <xsl:call-template name="reference">
+        <xsl:with-param name="zones" select="substring-after($zones, ' ')"/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:variable name="zone" select="$zones"/>
+      <xsl:variable name="target" select="key('sections', $zone)"/>
+
+      <xsl:variable name="id">
+        <xsl:call-template name="object.id">
+          <xsl:with-param name="object" select="$target[1]"/>
+        </xsl:call-template>
+      </xsl:variable>
+
+      <xsl:text>&lt;phrase role="pageno"&gt;</xsl:text>
+      <xsl:if test="$target[1]/@id">
+        <xsl:text>&lt;link linkend="</xsl:text>
+        <xsl:value-of select="$id"/>
+        <xsl:text>"&gt;</xsl:text>
+      </xsl:if>
+      <fo:basic-link internal-destination="{$id}">
+        <fo:page-number-citation ref-id="{$id}"/>
+      </fo:basic-link>
+      <xsl:if test="$target[1]/@id">
+        <xsl:text>&lt;/link&gt;</xsl:text>
+      </xsl:if>
+      <xsl:text>&lt;/phrase&gt;&#10;</xsl:text>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="indexterm" mode="index-see-markup">
+  <fo:block>
+    <xsl:text>&lt;seeie&gt;</xsl:text>
+    <xsl:text>&lt;phrase&gt;</xsl:text>
+    <xsl:call-template name="escape-text">
+      <xsl:with-param name="text" select="string(see)"/>
+    </xsl:call-template>
+    <xsl:text>&lt;/phrase&gt;</xsl:text>
+    <xsl:text>&lt;/seeie&gt;&#10;</xsl:text>
+  </fo:block>
+</xsl:template>
+
+<xsl:template match="indexterm" mode="index-seealso-markup">
+  <fo:block>
+    <xsl:text>&lt;seealsoie&gt;</xsl:text>
+    <xsl:text>&lt;phrase&gt;</xsl:text>
+    <xsl:call-template name="escape-text">
+      <xsl:with-param name="text" select="string(seealso)"/>
+    </xsl:call-template>
+    <xsl:text>&lt;/phrase&gt;</xsl:text>
+    <xsl:text>&lt;/seealsoie&gt;&#10;</xsl:text>
+  </fo:block>
+</xsl:template>
+
+<xsl:template name="escape-text">
+  <xsl:param name="text" select="''"/>
+
+  <xsl:variable name="ltpos" select="substring-before($text, '&lt;')"/>
+  <xsl:variable name="amppos" select="substring-before($text, '&amp;')"/>
+
+  <xsl:choose>
+    <xsl:when test="contains($text,'&lt;') and contains($text, '&amp;')
+                    and string-length($ltpos) &lt; string-length($amppos)">
+      <xsl:value-of select="$ltpos"/>
+      <xsl:text>&amp;lt;</xsl:text>
+      <xsl:call-template name="escape-text">
+        <xsl:with-param name="text" select="substring-after($text, '&lt;')"/>
+      </xsl:call-template>
+    </xsl:when>
+
+    <xsl:when test="contains($text,'&lt;') and contains($text, '&amp;')
+                    and string-length($amppos) &lt; string-length($ltpos)">
+      <xsl:value-of select="$amppos"/>
+      <xsl:text>&amp;amp;</xsl:text>
+      <xsl:call-template name="escape-text">
+        <xsl:with-param name="text" select="substring-after($text, '&amp;')"/>
+      </xsl:call-template>
+    </xsl:when>
+
+    <xsl:when test="contains($text, '&lt;')">
+      <xsl:value-of select="$ltpos"/>
+      <xsl:text>&amp;lt;</xsl:text>
+      <xsl:call-template name="escape-text">
+        <xsl:with-param name="text" select="substring-after($text, '&lt;')"/>
+      </xsl:call-template>
+    </xsl:when>
+
+    <xsl:when test="contains($text, '&amp;')">
+      <xsl:value-of select="$amppos"/>
+      <xsl:text>&amp;amp;</xsl:text>
+      <xsl:call-template name="escape-text">
+        <xsl:with-param name="text" select="substring-after($text, '&amp;')"/>
+      </xsl:call-template>
+    </xsl:when>
+
+    <xsl:otherwise>
+      <xsl:value-of select="$text"/>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 </xsl:stylesheet>