2 <xsl:stylesheet exclude-result-prefixes="d"
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:d="http://docbook.org/ns/docbook"
5 xmlns:fo="http://www.w3.org/1999/XSL/Format"
8 <!-- ********************************************************************
10 This file is part of the XSL DocBook Stylesheet distribution.
11 See ../README or http://cdn.docbook.org/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="d:set/d:toc | d:book/d:toc | d:part/d: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::d: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::d: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::d: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="d:chapter/d:toc | d:appendix/d:toc | d:preface/d:toc | d:article/d: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="d:section/d: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="d:tocpart|d:tocchap
160 |d:toclevel1|d:toclevel2|d:toclevel3|d:toclevel4|d:toclevel5">
161 <xsl:apply-templates select="d:tocentry"/>
162 <xsl:if test="d:tocchap|d:toclevel1|d:toclevel2|d:toclevel3|d:toclevel4|d:toclevel5">
163 <fo:block start-indent="{count(ancestor::*)*2}pc">
164 <xsl:apply-templates select="d:tocchap|d:toclevel1|d:toclevel2|d:toclevel3|d:toclevel4|d:toclevel5"/>
169 <xsl:template match="d:tocentry|d:lotentry|d:tocdiv|d:tocfront|d:tocback">
170 <fo:block end-indent="2pc"
171 last-line-end-indent="-2pc">
172 <xsl:if test="@linkend or @pagenum">
173 <xsl:attribute name="text-align-last">justify</xsl:attribute>
175 <fo:inline keep-with-next.within-line="always">
177 <xsl:when test="@linkend">
178 <fo:basic-link internal-destination="{@linkend}">
179 <xsl:apply-templates/>
183 <xsl:apply-templates/>
189 <xsl:when test="@linkend">
190 <fo:inline keep-together.within-line="always">
191 <fo:leader xsl:use-attribute-sets="toc.leader.properties"/>
192 <fo:basic-link internal-destination="{@linkend}">
194 <xsl:when test="@pagenum">
195 <xsl:value-of select="@pagenum"/>
198 <fo:page-number-citation ref-id="{@linkend}"/>
204 <xsl:when test="@pagenum">
205 <fo:inline keep-together.within-line="always">
206 <fo:leader xsl:use-attribute-sets="toc.leader.properties"/>
207 <xsl:value-of select="@pagenum"/>
214 <xsl:template match="d:toc/d:title | d:tocdiv/d:title">
215 <fo:block font-weight="bold">
216 <xsl:apply-templates/>
220 <xsl:template match="d:toc/d:subtitle | d:tocdiv/d:subtitle">
221 <fo:block font-weight="bold">
222 <xsl:apply-templates/>
226 <xsl:template match="d:toc/d:titleabbrev |d:tocdiv/d:titleabbrev">
229 <!-- ==================================================================== -->
231 <!-- A lot element must have content, because there is no attribute
232 to select what kind of list should be generated -->
233 <xsl:template match="d:book/d:lot | d:part/d:lot">
234 <!-- Don't generate a page sequence unless there is content -->
235 <xsl:variable name="content">
237 <xsl:when test="* and $process.source.toc != 0">
238 <xsl:apply-templates />
240 <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
241 <xsl:call-template name="process.empty.lot"/>
246 <xsl:if test="string-length(normalize-space($content)) != 0">
247 <xsl:variable name="lot-master-reference">
248 <xsl:call-template name="select.pagemaster">
249 <xsl:with-param name="pageclass" select="'lot'"/>
253 <xsl:call-template name="page.sequence">
254 <xsl:with-param name="master-reference"
255 select="$lot-master-reference"/>
256 <xsl:with-param name="element" select="'toc'"/>
257 <xsl:with-param name="content" select="$content"/>
262 <xsl:template match="d:chapter/d:lot | d:appendix/d:lot | d:preface/d:lot | d:article/d:lot">
264 <xsl:when test="* and $process.source.toc != 0">
266 <xsl:apply-templates/>
268 <xsl:call-template name="component.toc.separator"/>
270 <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
271 <xsl:call-template name="process.empty.lot"/>
276 <xsl:template match="d:section/d:lot
283 <xsl:when test="* and $process.source.toc != 0">
285 <xsl:apply-templates/>
287 <xsl:call-template name="section.toc.separator"/>
289 <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
290 <xsl:call-template name="process.empty.lot"/>
295 <xsl:template name="process.empty.lot">
296 <!-- An empty lot element does not provide any information to indicate
297 what should be included in it. You can customize this
298 template to generate a lot based on @role or something -->
300 <xsl:text>Warning: don't know what to generate for </xsl:text>
301 <xsl:text>lot that has no children.</xsl:text>
305 <xsl:template match="d:lot/d:title">
306 <fo:block font-weight="bold">
307 <xsl:apply-templates/>
311 <xsl:template match="d:lot/d:subtitle">
312 <fo:block font-weight="bold">
313 <xsl:apply-templates/>
317 <xsl:template match="d:lot/d:titleabbrev">