2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5 <!-- ********************************************************************
6 $Id: toc.xsl 9297 2012-04-22 03:56:16Z 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:call-template name="id.attribute"/>
87 <xsl:apply-templates select="title"/>
89 <xsl:apply-templates select="." mode="common.html.attributes"/>
90 <xsl:apply-templates select="*[not(self::title)]"/>
93 <xsl:call-template name="component.toc.separator"/>
95 <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">
96 <!-- trick to switch context node to section element -->
97 <xsl:for-each select="parent::*">
98 <xsl:call-template name="component.toc">
99 <xsl:with-param name="toc.title.p"
100 select="contains($toc.params, 'title')"/>
103 <xsl:call-template name="component.toc.separator"/>
109 <xsl:template match="section/toc
116 <xsl:variable name="toc.params">
117 <xsl:call-template name="find.path.params">
118 <xsl:with-param name="node" select="parent::*"/>
119 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
123 <!-- Do not output the toc element if one is already generated
124 by the use of $generate.toc parameter, or if
125 generating a source toc is turned off -->
126 <xsl:if test="not(contains($toc.params, 'toc')) and
127 ($process.source.toc != 0 or $process.empty.source.toc != 0)">
129 <xsl:when test="* and $process.source.toc != 0">
131 <xsl:apply-templates select="." mode="common.html.attributes"/>
132 <xsl:call-template name="id.attribute"/>
133 <xsl:apply-templates select="title"/>
135 <xsl:apply-templates select="." mode="common.html.attributes"/>
136 <xsl:apply-templates select="*[not(self::title)]"/>
139 <xsl:call-template name="section.toc.separator"/>
141 <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">
142 <!-- trick to switch context node to section element -->
143 <xsl:for-each select="parent::*">
144 <xsl:call-template name="section.toc">
145 <xsl:with-param name="toc.title.p"
146 select="contains($toc.params, 'title')"/>
149 <xsl:call-template name="section.toc.separator"/>
155 <!-- ==================================================================== -->
157 <xsl:template match="tocpart|tocchap
158 |toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
159 <xsl:variable name="sub-toc">
160 <xsl:if test="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
162 <xsl:when test="$toc.list.type = 'dl'">
164 <xsl:apply-templates select="." mode="common.html.attributes"/>
165 <xsl:element name="{$toc.list.type}">
166 <xsl:apply-templates select="." mode="common.html.attributes"/>
167 <xsl:apply-templates select="tocchap|toclevel1|toclevel2|
168 toclevel3|toclevel4|toclevel5"/>
173 <xsl:element name="{$toc.list.type}">
174 <xsl:apply-templates select="." mode="common.html.attributes"/>
175 <xsl:apply-templates select="tocchap|toclevel1|toclevel2|
176 toclevel3|toclevel4|toclevel5"/>
183 <xsl:apply-templates select="tocentry[position() != last()]"/>
186 <xsl:when test="$toc.list.type = 'dl'">
188 <xsl:apply-templates select="." mode="common.html.attributes"/>
189 <xsl:apply-templates select="tocentry[position() = last()]"/>
191 <xsl:copy-of select="$sub-toc"/>
195 <xsl:apply-templates select="." mode="common.html.attributes"/>
196 <xsl:apply-templates select="tocentry[position() = last()]"/>
197 <xsl:copy-of select="$sub-toc"/>
203 <xsl:template match="tocentry|tocdiv|lotentry|tocfront|tocback">
205 <xsl:when test="$toc.list.type = 'dl'">
207 <xsl:apply-templates select="." mode="common.html.attributes"/>
208 <xsl:call-template name="tocentry-content"/>
213 <xsl:apply-templates select="." mode="common.html.attributes"/>
214 <xsl:call-template name="tocentry-content"/>
220 <xsl:template match="tocentry[position() = last()]" priority="2">
221 <xsl:call-template name="tocentry-content"/>
224 <xsl:template name="tocentry-content">
225 <xsl:variable name="targets" select="key('id',@linkend)"/>
226 <xsl:variable name="target" select="$targets[1]"/>
229 <xsl:when test="@linkend">
230 <xsl:call-template name="check.id.unique">
231 <xsl:with-param name="linkend" select="@linkend"/>
234 <xsl:attribute name="href">
235 <xsl:call-template name="href.target">
236 <xsl:with-param name="object" select="$target"/>
239 <xsl:apply-templates/>
243 <xsl:apply-templates/>
248 <xsl:template match="toc/title">
250 <xsl:apply-templates select="." mode="common.html.attributes"/>
251 <xsl:apply-templates/>
255 <xsl:template match="toc/subtitle">
257 <xsl:apply-templates select="." mode="common.html.attributes"/>
258 <xsl:apply-templates/>
262 <xsl:template match="toc/titleabbrev">
265 <!-- ==================================================================== -->
267 <!-- A lot element must have content, because there is no attribute
268 to select what kind of list should be generated -->
269 <xsl:template match="book/lot | part/lot">
270 <!-- Don't generate a page sequence unless there is content -->
271 <xsl:variable name="content">
273 <xsl:when test="* and $process.source.toc != 0">
275 <xsl:apply-templates select="." mode="common.html.attributes"/>
276 <xsl:apply-templates />
279 <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
280 <xsl:call-template name="process.empty.lot"/>
285 <xsl:if test="string-length(normalize-space($content)) != 0">
286 <xsl:copy-of select="$content"/>
290 <xsl:template match="chapter/lot | appendix/lot | preface/lot | article/lot">
292 <xsl:when test="* and $process.source.toc != 0">
294 <xsl:apply-templates select="." mode="common.html.attributes"/>
295 <xsl:apply-templates />
297 <xsl:call-template name="component.toc.separator"/>
299 <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
300 <xsl:call-template name="process.empty.lot"/>
305 <xsl:template match="section/lot
312 <xsl:when test="* and $process.source.toc != 0">
314 <xsl:apply-templates select="." mode="common.html.attributes"/>
315 <xsl:apply-templates/>
317 <xsl:call-template name="section.toc.separator"/>
319 <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
320 <xsl:call-template name="process.empty.lot"/>
325 <xsl:template name="process.empty.lot">
326 <!-- An empty lot element does not provide any information to indicate
327 what should be included in it. You can customize this
328 template to generate a lot based on @role or something -->
330 <xsl:text>Warning: don't know what to generate for </xsl:text>
331 <xsl:text>lot that has no children.</xsl:text>
335 <xsl:template match="lot/title">
337 <xsl:apply-templates select="." mode="common.html.attributes"/>
338 <xsl:apply-templates/>
342 <xsl:template match="lot/subtitle">
344 <xsl:apply-templates select="." mode="common.html.attributes"/>
345 <xsl:apply-templates/>
349 <xsl:template match="lot/titleabbrev">