Indexes

A subject index with the references to the corresponding page numbers is generated automatically.

This section shall demonstrate how an index with the references to the corresponding page numbers is generated. In particular, this example shows how multiple entries of a key word in the index can be avoided and the repetitions of the same page numbers can be suppressed (only applies for the formatting with the XSL-Formatter of Antenna House).

The index which is produced in this example assumes that the authors create a complete index for their works in which the entries are already arranged in alphabetical order. The authors also set references for the index entries in the work content. In a XSLT process this index is transformed in such a way that it can be integrated into a second process in the formatting of the work with the following stylesheet excerpt.

Excerpt from the DTD:

<!ELEMENT Index (Entry)*>
<!ELEMENT Entry (Entry-1, (Entry-2)*)>
<!ELEMENT Entry-1 (#PCDATA)>
<!ELEMENT Entry-2 (#PCDATA)>
<!ATTLIST Entry-1 Name NMTOKEN #REQUIRED >
<!ATTLIST Entry-2 Name NMTOKEN #REQUIRED >
...
<!ELEMENT P (#PCDATA | ... | Kw | ...)*>
...
<!ELEMENT Kw (#PCDATA)>
<!ATTLIST Kw Refname NMTOKEN #REQUIRED>
...

Stylesheet:

<xsl:template name="SubjectIndex">                                     ❶ 
   <fo:block start-indent="1em" text-indent="-1em" text-align-last="left">
      <xsl:for-each select="//Kw[@Refname='Example' and not(preceding::Kw[@Refname='Example'])]"> ❷
         <fo:block>
            <fo:inline>
               <xsl:for-each select="//Kw[@Refname='Example']">
               <xsl:if test="position()=1">                           ❸ 
               <xsl:text></xsl:text>
                  <fo:page-number-citation ref-id="{generate-id()}"/> ❹
               </xsl:if>
               <xsl:if test="position()!=1">
                  <xsl:text></xsl:text>
                     <fo:page-number-citation ref-id="{generate-id()}" 
                      axf:suppress-duplicate-page-number="true"/>  ❹
               </xsl:if>
               </xsl:for-each>
            </fo:inline>
         </fo:block>
      </xsl:for-each>
   </fo:block>
</xsl:template>

❶ At first, a named template is generated by using the name attribute. This template can be called up again with the <xsl:call-template> element.

❷ Then the key word to be entered in the index will be selected. Each key word which has the Refname attribute with the value Example and which has no corresponding predecessor will be selected. The predecessors are excluded in order to avoid multiple entries. The work content has to contain a value for each of these constructs.

❸ Here, a check is made to ensure that the found key word is on the first position. If so, an entry will be made.

❹ With the <fo:page-number-citation> element the page can be displayed in which the referenced anchor (Kw) is situated. With the ref-id attribute the requested ID can be referenced. Each Kw in the work content gets this ID with the generate-id() function. The axf:suppress-duplicate-page-number attribute ensures that no page number is displayed twice within the index. In those cases in which a key word turns up on a page several times, the relevant page number will be displayed only once. This functionality is not part of the XSL-FO Recommendation but, as you can see by the axf namespace, a proprietary extension of the Antenna House Formatter.

<< back next >>

Copyright © dpunkt.verlag GmbH 2004
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "XSL-FO in der Praxis" ("XSL-FO in practice") is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.

dpunkt.verlag GmbH, Ringstraße 19B, 69115 Heidelberg, fon 06221-14830, fax 06221-148399, hallo@dpunkt.de