2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5 <!-- ********************************************************************
6 $Id: toc.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="set/toc | book/toc | part/toc">
18 <xsl:variable name="toc.params">
19 <xsl:call-template name="find.path.params">
20 <xsl:with-param name="node" select="parent::*"/>
21 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
25 <!-- Do not output the toc element if one is already generated
26 by the use of $generate.toc parameter, or if
27 generating a source toc is turned off -->
28 <xsl:if test="not(contains($toc.params, 'toc')) and
29 ($process.source.toc != 0 or $process.empty.source.toc != 0)">
30 <xsl:variable name="content">
32 <xsl:when test="* and $process.source.toc != 0">
33 <xsl:apply-templates />
35 <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">
36 <!-- trick to switch context node to parent element -->
37 <xsl:for-each select="parent::*">
39 <xsl:when test="self::set">
40 <xsl:call-template name="set.toc">
41 <xsl:with-param name="toc.title.p"
42 select="contains($toc.params, 'title')"/>
45 <xsl:when test="self::book">
46 <xsl:call-template name="division.toc">
47 <xsl:with-param name="toc.title.p"
48 select="contains($toc.params, 'title')"/>
51 <xsl:when test="self::part">
52 <xsl:call-template name="division.toc">
53 <xsl:with-param name="toc.title.p"
54 select="contains($toc.params, 'title')"/>
63 <xsl:if test="string-length(normalize-space($content)) != 0">
64 <xsl:copy-of select="$content"/>
69 <xsl:template match="chapter/toc | appendix/toc | preface/toc | article/toc">
70 <xsl:variable name="toc.params">
71 <xsl:call-template name="find.path.params">
72 <xsl:with-param name="node" select="parent::*"/>
73 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
77 <!-- Do not output the toc element if one is already generated
78 by the use of $generate.toc parameter, or if
79 generating a source toc is turned off -->
80 <xsl:if test="not(contains($toc.params, 'toc')) and
81 ($process.source.toc != 0 or $process.empty.source.toc != 0)">
83 <xsl:when test="* and $process.source.toc != 0">
85 <xsl:apply-templates select="." mode="common.html.attributes"/>
86 <xsl:apply-templates select="title"/>
88 <xsl:apply-templates select="." mode="common.html.attributes"/>
89 <xsl:apply-templates select="*[not(self::title)]"/>
92 <xsl:call-template name="component.toc.separator"/>
94 <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">
95 <!-- trick to switch context node to section element -->
96 <xsl:for-each select="parent::*">
97 <xsl:call-template name="component.toc">
98 <xsl:with-param name="toc.title.p"
99 select="contains($toc.params, 'title')"/>
102 <xsl:call-template name="component.toc.separator"/>
108 <xsl:template match="section/toc
115 <xsl:variable name="toc.params">
116 <xsl:call-template name="find.path.params">
117 <xsl:with-param name="node" select="parent::*"/>
118 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
122 <!-- Do not output the toc element if one is already generated
123 by the use of $generate.toc parameter, or if
124 generating a source toc is turned off -->
125 <xsl:if test="not(contains($toc.params, 'toc')) and
126 ($process.source.toc != 0 or $process.empty.source.toc != 0)">
128 <xsl:when test="* and $process.source.toc != 0">
130 <xsl:apply-templates select="." mode="common.html.attributes"/>
131 <xsl:apply-templates select="title"/>
133 <xsl:apply-templates select="." mode="common.html.attributes"/>
134 <xsl:apply-templates select="*[not(self::title)]"/>
137 <xsl:call-template name="section.toc.separator"/>
139 <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">
140 <!-- trick to switch context node to section element -->
141 <xsl:for-each select="parent::*">
142 <xsl:call-template name="section.toc">
143 <xsl:with-param name="toc.title.p"
144 select="contains($toc.params, 'title')"/>
147 <xsl:call-template name="section.toc.separator"/>
153 <!-- ==================================================================== -->
155 <xsl:template match="tocpart|tocchap
156 |toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
157 <xsl:variable name="sub-toc">
158 <xsl:if test="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
160 <xsl:when test="$toc.list.type = 'dl'">
162 <xsl:apply-templates select="." mode="common.html.attributes"/>
163 <xsl:element name="{$toc.list.type}">
164 <xsl:apply-templates select="." mode="common.html.attributes"/>
165 <xsl:apply-templates select="tocchap|toclevel1|toclevel2|
166 toclevel3|toclevel4|toclevel5"/>
171 <xsl:element name="{$toc.list.type}">
172 <xsl:apply-templates select="." mode="common.html.attributes"/>
173 <xsl:apply-templates select="tocchap|toclevel1|toclevel2|
174 toclevel3|toclevel4|toclevel5"/>
181 <xsl:apply-templates select="tocentry[position() != last()]"/>
184 <xsl:when test="$toc.list.type = 'dl'">
186 <xsl:apply-templates select="." mode="common.html.attributes"/>
187 <xsl:apply-templates select="tocentry[position() = last()]"/>
189 <xsl:copy-of select="$sub-toc"/>
193 <xsl:apply-templates select="." mode="common.html.attributes"/>
194 <xsl:apply-templates select="tocentry[position() = last()]"/>
195 <xsl:copy-of select="$sub-toc"/>
201 <xsl:template match="tocentry|tocdiv|lotentry|tocfront|tocback">
203 <xsl:when test="$toc.list.type = 'dl'">
205 <xsl:apply-templates select="." mode="common.html.attributes"/>
206 <xsl:call-template name="tocentry-content"/>
211 <xsl:apply-templates select="." mode="common.html.attributes"/>
212 <xsl:call-template name="tocentry-content"/>
218 <xsl:template match="tocentry[position() = last()]" priority="2">
219 <xsl:call-template name="tocentry-content"/>
222 <xsl:template name="tocentry-content">
223 <xsl:variable name="targets" select="key('id',@linkend)"/>
224 <xsl:variable name="target" select="$targets[1]"/>
227 <xsl:when test="@linkend">
228 <xsl:call-template name="check.id.unique">
229 <xsl:with-param name="linkend" select="@linkend"/>
232 <xsl:attribute name="href">
233 <xsl:call-template name="href.target">
234 <xsl:with-param name="object" select="$target"/>
237 <xsl:apply-templates/>
241 <xsl:apply-templates/>
246 <xsl:template match="toc/title">
248 <xsl:apply-templates select="." mode="common.html.attributes"/>
249 <xsl:apply-templates/>
253 <xsl:template match="toc/subtitle">
255 <xsl:apply-templates select="." mode="common.html.attributes"/>
256 <xsl:apply-templates/>
260 <xsl:template match="toc/titleabbrev">
263 <!-- ==================================================================== -->
265 <!-- A lot element must have content, because there is no attribute
266 to select what kind of list should be generated -->
267 <xsl:template match="book/lot | part/lot">
268 <!-- Don't generate a page sequence unless there is content -->
269 <xsl:variable name="content">
271 <xsl:when test="* and $process.source.toc != 0">
273 <xsl:apply-templates select="." mode="common.html.attributes"/>
274 <xsl:apply-templates />
277 <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
278 <xsl:call-template name="process.empty.lot"/>
283 <xsl:if test="string-length(normalize-space($content)) != 0">
284 <xsl:copy-of select="$content"/>
288 <xsl:template match="chapter/lot | appendix/lot | preface/lot | article/lot">
290 <xsl:when test="* and $process.source.toc != 0">
292 <xsl:apply-templates select="." mode="common.html.attributes"/>
293 <xsl:apply-templates />
295 <xsl:call-template name="component.toc.separator"/>
297 <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
298 <xsl:call-template name="process.empty.lot"/>
303 <xsl:template match="section/lot
310 <xsl:when test="* and $process.source.toc != 0">
312 <xsl:apply-templates select="." mode="common.html.attributes"/>
313 <xsl:apply-templates/>
315 <xsl:call-template name="section.toc.separator"/>
317 <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
318 <xsl:call-template name="process.empty.lot"/>
323 <xsl:template name="process.empty.lot">
324 <!-- An empty lot element does not provide any information to indicate
325 what should be included in it. You can customize this
326 template to generate a lot based on @role or something -->
328 <xsl:text>Warning: don't know what to generate for </xsl:text>
329 <xsl:text>lot that has no children.</xsl:text>
333 <xsl:template match="lot/title">
335 <xsl:apply-templates select="." mode="common.html.attributes"/>
336 <xsl:apply-templates/>
340 <xsl:template match="lot/subtitle">
342 <xsl:apply-templates select="." mode="common.html.attributes"/>
343 <xsl:apply-templates/>
347 <xsl:template match="lot/titleabbrev">