2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:fo="http://www.w3.org/1999/XSL/Format"
6 <!-- ********************************************************************
7 $Id: toc.xsl 8323 2009-03-12 22:52:17Z bobstayton $
8 ********************************************************************
10 This file is part of the XSL DocBook Stylesheet distribution.
11 See ../README or http://docbook.sf.net/release/xsl/current/ for
12 copyright and other information.
14 ******************************************************************** -->
16 <!-- ==================================================================== -->
18 <!-- only set, book and part puts toc in its own page sequence -->
20 <xsl:template match="set/toc | book/toc | part/toc">
21 <xsl:variable name="toc.params">
22 <xsl:call-template name="find.path.params">
23 <xsl:with-param name="node" select="parent::*"/>
24 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
28 <!-- Do not output the toc element if one is already generated
29 by the use of $generate.toc parameter, or if
30 generating a source toc is turned off -->
31 <xsl:if test="not(contains($toc.params, 'toc')) and
32 ($process.source.toc != 0 or $process.empty.source.toc != 0)">
33 <!-- Don't generate a page sequence unless there is content -->
34 <xsl:variable name="content">
36 <xsl:when test="* and $process.source.toc != 0">
37 <xsl:apply-templates />
39 <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">
40 <!-- trick to switch context node to parent element -->
41 <xsl:for-each select="parent::*">
43 <xsl:when test="self::set">
44 <xsl:call-template name="set.toc">
45 <xsl:with-param name="toc.title.p"
46 select="contains($toc.params, 'title')"/>
49 <xsl:when test="self::book">
50 <xsl:call-template name="division.toc">
51 <xsl:with-param name="toc.title.p"
52 select="contains($toc.params, 'title')"/>
55 <xsl:when test="self::part">
56 <xsl:call-template name="division.toc">
57 <xsl:with-param name="toc.title.p"
58 select="contains($toc.params, 'title')"/>
67 <xsl:if test="string-length(normalize-space($content)) != 0">
68 <xsl:variable name="lot-master-reference">
69 <xsl:call-template name="select.pagemaster">
70 <xsl:with-param name="pageclass" select="'lot'"/>
74 <xsl:call-template name="page.sequence">
75 <xsl:with-param name="master-reference"
76 select="$lot-master-reference"/>
77 <xsl:with-param name="element" select="'toc'"/>
78 <xsl:with-param name="gentext-key" select="'TableofContents'"/>
79 <xsl:with-param name="content" select="$content"/>
85 <xsl:template match="chapter/toc | appendix/toc | preface/toc | article/toc">
86 <xsl:variable name="toc.params">
87 <xsl:call-template name="find.path.params">
88 <xsl:with-param name="node" select="parent::*"/>
89 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
93 <!-- Do not output the toc element if one is already generated
94 by the use of $generate.toc parameter, or if
95 generating a source toc is turned off -->
96 <xsl:if test="not(contains($toc.params, 'toc')) and
97 ($process.source.toc != 0 or $process.empty.source.toc != 0)">
99 <xsl:when test="* and $process.source.toc != 0">
101 <xsl:apply-templates/>
104 <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">
105 <!-- trick to switch context node to section element -->
106 <xsl:for-each select="parent::*">
107 <xsl:call-template name="component.toc">
108 <xsl:with-param name="toc.title.p"
109 select="contains($toc.params, 'title')"/>
114 <xsl:call-template name="component.toc.separator"/>
118 <xsl:template match="section/toc
125 <xsl:variable name="toc.params">
126 <xsl:call-template name="find.path.params">
127 <xsl:with-param name="node" select="parent::*"/>
128 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
132 <!-- Do not output the toc element if one is already generated
133 by the use of $generate.toc parameter, or if
134 generating a source toc is turned off -->
135 <xsl:if test="not(contains($toc.params, 'toc')) and
136 ($process.source.toc != 0 or $process.empty.source.toc != 0)">
138 <xsl:when test="* and $process.source.toc != 0">
140 <xsl:apply-templates/>
143 <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">
144 <!-- trick to switch context node to section element -->
145 <xsl:for-each select="parent::*">
146 <xsl:call-template name="section.toc">
147 <xsl:with-param name="toc.title.p"
148 select="contains($toc.params, 'title')"/>
153 <xsl:call-template name="section.toc.separator"/>
157 <!-- ==================================================================== -->
159 <xsl:template match="tocpart|tocchap
160 |toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
161 <xsl:apply-templates select="tocentry"/>
162 <xsl:if test="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
163 <fo:block start-indent="{count(ancestor::*)*2}pc">
164 <xsl:apply-templates select="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5"/>
169 <xsl:template match="tocentry|lotentry|tocdiv|tocfront|tocback">
170 <fo:block text-align-last="justify"
172 last-line-end-indent="-2pc">
173 <fo:inline keep-with-next.within-line="always">
175 <xsl:when test="@linkend">
176 <fo:basic-link internal-destination="{@linkend}">
177 <xsl:apply-templates/>
181 <xsl:apply-templates/>
187 <xsl:when test="@linkend">
188 <fo:inline keep-together.within-line="always">
189 <xsl:text> </xsl:text>
190 <fo:leader leader-pattern="dots"
191 keep-with-next.within-line="always"/>
192 <xsl:text> </xsl:text>
193 <fo:basic-link internal-destination="{@linkend}">
195 <xsl:when test="@pagenum">
196 <xsl:value-of select="@pagenum"/>
199 <fo:page-number-citation ref-id="{@linkend}"/>
205 <xsl:when test="@pagenum">
206 <fo:inline keep-together.within-line="always">
207 <xsl:text> </xsl:text>
208 <fo:leader leader-pattern="dots"
209 keep-with-next.within-line="always"/>
210 <xsl:text> </xsl:text>
211 <xsl:value-of select="@pagenum"/>
215 <!-- just the leaders, what else can I do? -->
216 <fo:inline keep-together.within-line="always">
217 <xsl:text> </xsl:text>
218 <fo:leader leader-pattern="space"
219 keep-with-next.within-line="always"/>
226 <xsl:template match="toc/title">
227 <fo:block font-weight="bold">
228 <xsl:apply-templates/>
232 <xsl:template match="toc/subtitle">
233 <fo:block font-weight="bold">
234 <xsl:apply-templates/>
238 <xsl:template match="toc/titleabbrev">
241 <!-- ==================================================================== -->
243 <!-- A lot element must have content, because there is no attribute
244 to select what kind of list should be generated -->
245 <xsl:template match="book/lot | part/lot">
246 <!-- Don't generate a page sequence unless there is content -->
247 <xsl:variable name="content">
249 <xsl:when test="* and $process.source.toc != 0">
250 <xsl:apply-templates />
252 <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
253 <xsl:call-template name="process.empty.lot"/>
258 <xsl:if test="string-length(normalize-space($content)) != 0">
259 <xsl:variable name="lot-master-reference">
260 <xsl:call-template name="select.pagemaster">
261 <xsl:with-param name="pageclass" select="'lot'"/>
265 <xsl:call-template name="page.sequence">
266 <xsl:with-param name="master-reference"
267 select="$lot-master-reference"/>
268 <xsl:with-param name="element" select="'toc'"/>
269 <xsl:with-param name="content" select="$content"/>
274 <xsl:template match="chapter/lot | appendix/lot | preface/lot | article/lot">
276 <xsl:when test="* and $process.source.toc != 0">
278 <xsl:apply-templates/>
280 <xsl:call-template name="component.toc.separator"/>
282 <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
283 <xsl:call-template name="process.empty.lot"/>
288 <xsl:template match="section/lot
295 <xsl:when test="* and $process.source.toc != 0">
297 <xsl:apply-templates/>
299 <xsl:call-template name="section.toc.separator"/>
301 <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
302 <xsl:call-template name="process.empty.lot"/>
307 <xsl:template name="process.empty.lot">
308 <!-- An empty lot element does not provide any information to indicate
309 what should be included in it. You can customize this
310 template to generate a lot based on @role or something -->
312 <xsl:text>Warning: don't know what to generate for </xsl:text>
313 <xsl:text>lot that has no children.</xsl:text>
317 <xsl:template match="lot/title">
318 <fo:block font-weight="bold">
319 <xsl:apply-templates/>
323 <xsl:template match="lot/subtitle">
324 <fo:block font-weight="bold">
325 <xsl:apply-templates/>
329 <xsl:template match="lot/titleabbrev">