2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5 <!-- ********************************************************************
6 $Id: index.xsl 8421 2009-05-04 07:49:49Z bobstayton $
7 ********************************************************************
9 This file is part of the XSL DocBook Stylesheet distribution.
10 See ../README or http://docbook.sf.net/release/xsl/current/ for
11 copyright and other information.
13 ******************************************************************** -->
15 <!-- ==================================================================== -->
17 <xsl:template match="index">
18 <!-- some implementations use completely empty index tags to indicate -->
19 <!-- where an automatically generated index should be inserted. so -->
20 <!-- if the index is completely empty, skip it. Unless generate.index -->
21 <!-- is non-zero, in which case, this is where the automatically -->
22 <!-- generated index should go. -->
24 <xsl:call-template name="id.warning"/>
26 <xsl:if test="count(*)>0 or $generate.index != '0'">
28 <xsl:apply-templates select="." mode="common.html.attributes"/>
29 <xsl:if test="$generate.id.attributes != 0">
30 <xsl:attribute name="id">
31 <xsl:call-template name="object.id"/>
35 <xsl:call-template name="index.titlepage"/>
37 <xsl:when test="indexdiv">
38 <xsl:apply-templates/>
41 <xsl:apply-templates select="*[not(self::indexentry)]"/>
42 <!-- Because it's actually valid for Index to have neither any -->
43 <!-- Indexdivs nor any Indexentries, we need to check and make -->
44 <!-- sure that at least one Indexentry exists, and generate a -->
45 <!-- wrapper dl if there is at least one; otherwise, do nothing. -->
46 <xsl:if test="indexentry">
47 <!-- The indexentry template assumes a parent dl wrapper has -->
48 <!-- been generated; for Indexes that have Indexdivs, the dl -->
49 <!-- wrapper is generated by the indexdiv template; however, -->
50 <!-- for Indexes that lack Indexdivs, if we don't generate a -->
51 <!-- dl here, HTML output will not be valid. -->
53 <xsl:apply-templates select="indexentry"/>
59 <xsl:if test="count(indexentry) = 0 and count(indexdiv) = 0">
60 <xsl:call-template name="generate-index">
61 <xsl:with-param name="scope" select="(ancestor::book|/)[last()]"/>
65 <xsl:if test="not(parent::article)">
66 <xsl:call-template name="process.footnotes"/>
72 <xsl:template match="setindex">
73 <!-- some implementations use completely empty index tags to indicate -->
74 <!-- where an automatically generated index should be inserted. so -->
75 <!-- if the index is completely empty, skip it. Unless generate.index -->
76 <!-- is non-zero, in which case, this is where the automatically -->
77 <!-- generated index should go. -->
79 <xsl:call-template name="id.warning"/>
81 <xsl:if test="count(*)>0 or $generate.index != '0'">
83 <xsl:apply-templates select="." mode="common.html.attributes"/>
84 <xsl:if test="$generate.id.attributes != 0">
85 <xsl:attribute name="id">
86 <xsl:call-template name="object.id"/>
90 <xsl:call-template name="setindex.titlepage"/>
91 <xsl:apply-templates/>
93 <xsl:if test="count(indexentry) = 0 and count(indexdiv) = 0">
94 <xsl:call-template name="generate-index">
95 <xsl:with-param name="scope" select="/"/>
99 <xsl:if test="not(parent::article)">
100 <xsl:call-template name="process.footnotes"/>
106 <xsl:template match="index/indexinfo"></xsl:template>
107 <xsl:template match="index/info"></xsl:template>
108 <xsl:template match="index/title"></xsl:template>
109 <xsl:template match="index/subtitle"></xsl:template>
110 <xsl:template match="index/titleabbrev"></xsl:template>
112 <!-- ==================================================================== -->
114 <xsl:template match="indexdiv">
115 <xsl:call-template name="id.warning"/>
118 <xsl:apply-templates select="." mode="common.html.attributes"/>
119 <xsl:if test="$generate.id.attributes != 0">
120 <xsl:attribute name="id">
121 <xsl:call-template name="object.id"/>
125 <xsl:call-template name="anchor"/>
126 <xsl:apply-templates select="*[not(self::indexentry)]"/>
128 <xsl:apply-templates select="indexentry"/>
133 <xsl:template match="indexdiv/title">
135 <xsl:apply-templates select="." mode="common.html.attributes"/>
136 <xsl:apply-templates/>
140 <!-- ==================================================================== -->
142 <xsl:template match="indexterm">
143 <!-- this one must have a name, even if it doesn't have an ID -->
144 <xsl:variable name="id">
145 <xsl:call-template name="object.id"/>
148 <a class="indexterm" name="{$id}"/>
151 <xsl:template match="primary|secondary|tertiary|see|seealso">
154 <!-- ==================================================================== -->
156 <xsl:template match="indexentry">
157 <xsl:apply-templates select="primaryie"/>
160 <xsl:template match="primaryie">
162 <xsl:apply-templates/>
165 <xsl:apply-templates select="following-sibling::seeie
166 [not(preceding-sibling::secondaryie)]"
168 <xsl:apply-templates select="following-sibling::seealsoie
169 [not(preceding-sibling::secondaryie)]"
171 <xsl:apply-templates select="following-sibling::secondaryie"
176 <!-- Handled in mode to convert flat list to structured output -->
177 <xsl:template match="secondaryie">
179 <xsl:template match="tertiaryie">
181 <xsl:template match="seeie|seealsoie">
184 <xsl:template match="secondaryie" mode="indexentry">
187 <xsl:apply-templates/>
190 <!-- select following see* elements up to next secondaryie or tertiary or end -->
191 <xsl:variable name="after.this"
192 select="following-sibling::*"/>
193 <xsl:variable name="next.entry"
194 select="(following-sibling::secondaryie|following-sibling::tertiaryie)[1]"/>
195 <xsl:variable name="before.entry"
196 select="$next.entry/preceding-sibling::*"/>
197 <xsl:variable name="see.intersection"
198 select="$after.this[count(.|$before.entry) = count($before.entry)]
199 [self::seeie or self::seealsoie]"/>
201 <xsl:when test="count($see.intersection) != 0">
202 <xsl:apply-templates select="$see.intersection" mode="indexentry"/>
204 <xsl:when test="count($next.entry) = 0">
205 <xsl:apply-templates select="following-sibling::seeie"
207 <xsl:apply-templates select="following-sibling::seealsoie"
212 <!-- now process any tertiaryie before the next secondaryie -->
213 <xsl:variable name="before.next.secondary"
214 select="following-sibling::secondaryie[1]/preceding-sibling::*"/>
215 <xsl:variable name="tertiary.intersection"
216 select="$after.this[count(.|$before.next.secondary) =
217 count($before.next.secondary)]
218 [not(self::seeie) and not(self::seealsoie)]"/>
220 <xsl:when test="count($tertiary.intersection) != 0">
221 <xsl:apply-templates select="$tertiary.intersection"
224 <xsl:when test="not(following-sibling::secondaryie)">
225 <xsl:apply-templates select="following-sibling::tertiaryie"
233 <xsl:template match="tertiaryie" mode="indexentry">
236 <xsl:apply-templates/>
239 <!-- select following see* elements up to next secondaryie or tertiary or end -->
240 <xsl:variable name="after.this"
241 select="following-sibling::*"/>
242 <xsl:variable name="next.entry"
243 select="(following-sibling::secondaryie|following-sibling::tertiaryie)[1]"/>
244 <xsl:variable name="before.entry"
245 select="$next.entry/preceding-sibling::*"/>
246 <xsl:variable name="see.intersection"
247 select="$after.this[count(.|$before.entry) = count($before.entry)]
248 [self::seeie or self::seealsoie]"/>
250 <xsl:when test="count($see.intersection) != 0">
251 <xsl:apply-templates select="$see.intersection" mode="indexentry"/>
253 <xsl:when test="count($next.entry) = 0">
254 <xsl:apply-templates select="following-sibling::seeie"
256 <xsl:apply-templates select="following-sibling::seealsoie"
264 <xsl:template match="seeie" mode="indexentry">
266 <xsl:text>(</xsl:text>
267 <xsl:call-template name="gentext">
268 <xsl:with-param name="key" select="'see'"/>
270 <xsl:text> </xsl:text>
271 <xsl:apply-templates/>
272 <xsl:text>)</xsl:text>
276 <xsl:template match="seealsoie" mode="indexentry">
278 <xsl:text>(</xsl:text>
279 <xsl:call-template name="gentext">
280 <xsl:with-param name="key" select="'seealso'"/>
282 <xsl:text> </xsl:text>
283 <xsl:apply-templates/>
284 <xsl:text>)</xsl:text>