2 <xsl:stylesheet xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform"
5 <!-- ********************************************************************
6 $Id: autotoc.xsl,v 1.1 2007/03/10 05:15:13 scott Exp $
7 ********************************************************************
9 This file is part of the XSL DocBook Stylesheet distribution.
10 See ../README or http://nwalsh.com/docbook/xsl/ for copyright
11 and other information.
13 ******************************************************************** -->
15 <xsl:variable name=
"toc.listitem.type">
17 <xsl:when test=
"$toc.list.type = 'dl'">dt
</xsl:when>
18 <xsl:otherwise>li
</xsl:otherwise>
22 <!-- this is just hack because dl and ul aren't completely isomorphic -->
23 <xsl:variable name=
"toc.dd.type">
25 <xsl:when test=
"$toc.list.type = 'dl'">dd
</xsl:when>
26 <xsl:otherwise></xsl:otherwise>
30 <xsl:template name=
"make.toc">
31 <xsl:param name=
"toc-context" select=
"."/>
32 <xsl:param name=
"toc.title.p" select=
"true()"/>
33 <xsl:param name=
"nodes" select=
"/NOT-AN-ELEMENT"/>
35 <xsl:variable name=
"nodes.plus" select=
"$nodes | qandaset"/>
37 <xsl:variable name=
"toc.title">
38 <xsl:if test=
"$toc.title.p">
41 <xsl:call-template name=
"gentext">
42 <xsl:with-param name=
"key">TableofContents
</xsl:with-param>
50 <xsl:when test=
"$manual.toc != ''">
51 <xsl:variable name=
"id">
52 <xsl:call-template name=
"object.id"/>
54 <xsl:variable name=
"toc" select=
"document($manual.toc, .)"/>
55 <xsl:variable name=
"tocentry" select=
"$toc//tocentry[@linkend=$id]"/>
56 <xsl:if test=
"$tocentry and $tocentry/*">
58 <xsl:copy-of select=
"$toc.title"/>
59 <xsl:element name=
"{$toc.list.type}">
60 <xsl:call-template name=
"manual-toc">
61 <xsl:with-param name=
"tocentry" select=
"$tocentry/*[1]"/>
69 <xsl:when test=
"$qanda.in.toc != 0">
70 <xsl:if test=
"$nodes.plus">
72 <xsl:copy-of select=
"$toc.title"/>
73 <xsl:element name=
"{$toc.list.type}">
74 <xsl:apply-templates select=
"$nodes.plus" mode=
"toc">
75 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
76 </xsl:apply-templates>
82 <xsl:if test=
"$nodes">
84 <xsl:copy-of select=
"$toc.title"/>
85 <xsl:element name=
"{$toc.list.type}">
86 <xsl:apply-templates select=
"$nodes" mode=
"toc">
87 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
88 </xsl:apply-templates>
99 <xsl:template name=
"make.lots">
100 <xsl:param name=
"toc.params" select=
"''"/>
101 <xsl:param name=
"toc"/>
103 <xsl:if test=
"contains($toc.params, 'toc')">
104 <xsl:copy-of select=
"$toc"/>
107 <xsl:if test=
"contains($toc.params, 'figure')">
108 <xsl:call-template name=
"list.of.titles">
109 <xsl:with-param name=
"titles" select=
"'figure'"/>
110 <xsl:with-param name=
"nodes" select=
".//figure"/>
114 <xsl:if test=
"contains($toc.params, 'table')">
115 <xsl:call-template name=
"list.of.titles">
116 <xsl:with-param name=
"titles" select=
"'table'"/>
117 <xsl:with-param name=
"nodes" select=
".//table"/>
121 <xsl:if test=
"contains($toc.params, 'example')">
122 <xsl:call-template name=
"list.of.titles">
123 <xsl:with-param name=
"titles" select=
"'example'"/>
124 <xsl:with-param name=
"nodes" select=
".//example"/>
128 <xsl:if test=
"contains($toc.params, 'equation')">
129 <xsl:call-template name=
"list.of.titles">
130 <xsl:with-param name=
"titles" select=
"'equation'"/>
131 <xsl:with-param name=
"nodes" select=
".//equation[title or info/title]"/>
135 <xsl:if test=
"contains($toc.params, 'procedure')">
136 <xsl:call-template name=
"list.of.titles">
137 <xsl:with-param name=
"titles" select=
"'procedure'"/>
138 <xsl:with-param name=
"nodes" select=
".//procedure[title]"/>
143 <!-- ====================================================================== -->
145 <xsl:template name=
"set.toc">
146 <xsl:param name=
"toc-context" select=
"."/>
147 <xsl:param name=
"toc.title.p" select=
"true()"/>
149 <xsl:call-template name=
"make.toc">
150 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
151 <xsl:with-param name=
"toc.title.p" select=
"$toc.title.p"/>
152 <xsl:with-param name=
"nodes" select=
"book|setindex"/>
156 <xsl:template name=
"division.toc">
157 <xsl:param name=
"toc-context" select=
"."/>
158 <xsl:param name=
"toc.title.p" select=
"true()"/>
160 <xsl:call-template name=
"make.toc">
161 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
162 <xsl:with-param name=
"toc.title.p" select=
"$toc.title.p"/>
163 <xsl:with-param name=
"nodes" select=
"part|reference
164 |preface|chapter|appendix
166 |bibliography|glossary|index
168 |bridgehead[$bridgehead.in.toc != 0]"/>
173 <xsl:template name=
"component.toc">
174 <xsl:param name=
"toc-context" select=
"."/>
175 <xsl:param name=
"toc.title.p" select=
"true()"/>
177 <xsl:call-template name=
"make.toc">
178 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
179 <xsl:with-param name=
"toc.title.p" select=
"$toc.title.p"/>
180 <xsl:with-param name=
"nodes" select=
"section|sect1
181 |simplesect[$simplesect.in.toc != 0]
183 |article|bibliography|glossary
185 |bridgehead[not(@renderas)
186 and $bridgehead.in.toc != 0]
187 |.//bridgehead[@renderas='sect1'
188 and $bridgehead.in.toc != 0]"/>
192 <xsl:template name=
"component.toc.separator">
193 <!-- Customize to output something between
194 component.toc and first output -->
197 <xsl:template name=
"section.toc">
198 <xsl:param name=
"toc-context" select=
"."/>
199 <xsl:param name=
"toc.title.p" select=
"true()"/>
201 <xsl:call-template name=
"make.toc">
202 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
203 <xsl:with-param name=
"toc.title.p" select=
"$toc.title.p"/>
204 <xsl:with-param name=
"nodes"
205 select=
"section|sect1|sect2|sect3|sect4|sect5|refentry
206 |bridgehead[$bridgehead.in.toc != 0]"/>
211 <xsl:template name=
"section.toc.separator">
212 <!-- Customize to output something between
213 section.toc and first output -->
215 <!-- ==================================================================== -->
217 <xsl:template name=
"subtoc">
218 <xsl:param name=
"toc-context" select=
"."/>
219 <xsl:param name=
"nodes" select=
"NOT-AN-ELEMENT"/>
221 <xsl:variable name=
"nodes.plus" select=
"$nodes | qandaset"/>
223 <xsl:variable name=
"subtoc">
224 <xsl:element name=
"{$toc.list.type}">
226 <xsl:when test=
"$qanda.in.toc != 0">
227 <xsl:apply-templates mode=
"toc" select=
"$nodes.plus">
228 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
229 </xsl:apply-templates>
232 <xsl:apply-templates mode=
"toc" select=
"$nodes">
233 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
234 </xsl:apply-templates>
240 <xsl:variable name=
"depth">
242 <xsl:when test=
"local-name(.) = 'section'">
243 <xsl:value-of select=
"count(ancestor::section) + 1"/>
245 <xsl:when test=
"local-name(.) = 'sect1'">1</xsl:when>
246 <xsl:when test=
"local-name(.) = 'sect2'">2</xsl:when>
247 <xsl:when test=
"local-name(.) = 'sect3'">3</xsl:when>
248 <xsl:when test=
"local-name(.) = 'sect4'">4</xsl:when>
249 <xsl:when test=
"local-name(.) = 'sect5'">5</xsl:when>
250 <xsl:when test=
"local-name(.) = 'refsect1'">1</xsl:when>
251 <xsl:when test=
"local-name(.) = 'refsect2'">2</xsl:when>
252 <xsl:when test=
"local-name(.) = 'refsect3'">3</xsl:when>
253 <xsl:when test=
"local-name(.) = 'simplesect'">
256 <xsl:when test=
"local-name(..) = 'section'">
257 <xsl:value-of select=
"count(ancestor::section)"/>
259 <xsl:when test=
"local-name(..) = 'sect1'">2</xsl:when>
260 <xsl:when test=
"local-name(..) = 'sect2'">3</xsl:when>
261 <xsl:when test=
"local-name(..) = 'sect3'">4</xsl:when>
262 <xsl:when test=
"local-name(..) = 'sect4'">5</xsl:when>
263 <xsl:when test=
"local-name(..) = 'sect5'">6</xsl:when>
264 <xsl:when test=
"local-name(..) = 'refsect1'">2</xsl:when>
265 <xsl:when test=
"local-name(..) = 'refsect2'">3</xsl:when>
266 <xsl:when test=
"local-name(..) = 'refsect3'">4</xsl:when>
267 <xsl:otherwise>1</xsl:otherwise>
270 <xsl:otherwise>0</xsl:otherwise>
274 <xsl:variable name=
"depth.from.context" select=
"count(ancestor::*)-count($toc-context/ancestor::*)"/>
276 <xsl:variable name=
"subtoc.list">
278 <xsl:when test=
"$toc.dd.type = ''">
279 <xsl:copy-of select=
"$subtoc"/>
282 <xsl:element name=
"{$toc.dd.type}">
283 <xsl:copy-of select=
"$subtoc"/>
289 <xsl:element name=
"{$toc.listitem.type}">
290 <xsl:call-template name=
"toc.line">
291 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
293 <xsl:if test=
"$toc.listitem.type = 'li'
294 and $toc.section.depth > $depth and
295 ( ($qanda.in.toc = 0 and count($nodes)>0) or
296 ($qanda.in.toc != 0 and count($nodes.plus)>0) )
297 and $toc.max.depth > $depth.from.context">
298 <xsl:copy-of select=
"$subtoc.list"/>
301 <xsl:if test=
"$toc.listitem.type != 'li'
302 and $toc.section.depth > $depth and
303 ( ($qanda.in.toc = 0 and count($nodes)>0) or
304 ($qanda.in.toc != 0 and count($nodes.plus)>0) )
305 and $toc.max.depth > $depth.from.context">
306 <xsl:copy-of select=
"$subtoc.list"/>
310 <xsl:template name=
"toc.line">
311 <xsl:param name=
"toc-context" select=
"."/>
312 <xsl:param name=
"depth" select=
"1"/>
313 <xsl:param name=
"depth.from.context" select=
"8"/>
316 <xsl:attribute name=
"class"><xsl:value-of select=
"local-name(.)"/></xsl:attribute>
318 <!-- * if $autotoc.label.in.hyperlink is zero, then output the label -->
319 <!-- * before the hyperlinked title (as the DSSSL stylesheet does) -->
320 <xsl:if test=
"$autotoc.label.in.hyperlink = 0">
321 <xsl:variable name=
"label">
322 <xsl:apply-templates select=
"." mode=
"label.markup"/>
324 <xsl:copy-of select=
"$label"/>
325 <xsl:if test=
"$label != ''">
326 <xsl:value-of select=
"$autotoc.label.separator"/>
331 <xsl:attribute name=
"href">
332 <xsl:call-template name=
"href.target">
333 <xsl:with-param name=
"context" select=
"$toc-context"/>
337 <!-- * if $autotoc.label.in.hyperlink is non-zero, then output the label -->
338 <!-- * as part of the hyperlinked title -->
339 <xsl:if test=
"not($autotoc.label.in.hyperlink = 0)">
340 <xsl:variable name=
"label">
341 <xsl:apply-templates select=
"." mode=
"label.markup"/>
343 <xsl:copy-of select=
"$label"/>
344 <xsl:if test=
"$label != ''">
345 <xsl:value-of select=
"$autotoc.label.separator"/>
349 <xsl:apply-templates select=
"." mode=
"titleabbrev.markup"/>
354 <xsl:template match=
"book" mode=
"toc">
355 <xsl:param name=
"toc-context" select=
"."/>
357 <xsl:call-template name=
"subtoc">
358 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
359 <xsl:with-param name=
"nodes" select=
"part|reference
360 |preface|chapter|appendix
362 |bibliography|glossary|index
364 |bridgehead[$bridgehead.in.toc != 0]"/>
368 <xsl:template match=
"setindex" mode=
"toc">
369 <xsl:param name=
"toc-context" select=
"."/>
371 <!-- If the setindex tag is not empty, it should be it in the TOC -->
372 <xsl:if test=
"* or $generate.index != 0">
373 <xsl:call-template name=
"subtoc">
374 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
379 <xsl:template match=
"part|reference" mode=
"toc">
380 <xsl:param name=
"toc-context" select=
"."/>
382 <xsl:call-template name=
"subtoc">
383 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
384 <xsl:with-param name=
"nodes" select=
"appendix|chapter|article
385 |index|glossary|bibliography
386 |preface|reference|refentry
387 |bridgehead[$bridgehead.in.toc != 0]"/>
391 <xsl:template match=
"preface|chapter|appendix|article" mode=
"toc">
392 <xsl:param name=
"toc-context" select=
"."/>
394 <xsl:call-template name=
"subtoc">
395 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
396 <xsl:with-param name=
"nodes" select=
"section|sect1
397 |simplesect[$simplesect.in.toc != 0]
399 |glossary|bibliography|index
400 |bridgehead[$bridgehead.in.toc != 0]"/>
404 <xsl:template match=
"sect1" mode=
"toc">
405 <xsl:param name=
"toc-context" select=
"."/>
406 <xsl:call-template name=
"subtoc">
407 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
408 <xsl:with-param name=
"nodes" select=
"sect2
409 |bridgehead[$bridgehead.in.toc != 0]"/>
413 <xsl:template match=
"sect2" mode=
"toc">
414 <xsl:param name=
"toc-context" select=
"."/>
416 <xsl:call-template name=
"subtoc">
417 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
418 <xsl:with-param name=
"nodes" select=
"sect3
419 |bridgehead[$bridgehead.in.toc != 0]"/>
423 <xsl:template match=
"sect3" mode=
"toc">
424 <xsl:param name=
"toc-context" select=
"."/>
426 <xsl:call-template name=
"subtoc">
427 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
428 <xsl:with-param name=
"nodes" select=
"sect4
429 |bridgehead[$bridgehead.in.toc != 0]"/>
433 <xsl:template match=
"sect4" mode=
"toc">
434 <xsl:param name=
"toc-context" select=
"."/>
436 <xsl:call-template name=
"subtoc">
437 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
438 <xsl:with-param name=
"nodes" select=
"sect5
439 |bridgehead[$bridgehead.in.toc != 0]"/>
443 <xsl:template match=
"sect5" mode=
"toc">
444 <xsl:param name=
"toc-context" select=
"."/>
446 <xsl:call-template name=
"subtoc">
447 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
451 <xsl:template match=
"simplesect" mode=
"toc">
452 <xsl:param name=
"toc-context" select=
"."/>
454 <xsl:call-template name=
"subtoc">
455 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
459 <xsl:template match=
"section" mode=
"toc">
460 <xsl:param name=
"toc-context" select=
"."/>
462 <xsl:call-template name=
"subtoc">
463 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
464 <xsl:with-param name=
"nodes" select=
"section
465 |bridgehead[$bridgehead.in.toc != 0]"/>
469 <xsl:template match=
"bridgehead" mode=
"toc">
470 <xsl:param name=
"toc-context" select=
"."/>
472 <xsl:if test=
"$bridgehead.in.toc != 0">
473 <xsl:call-template name=
"subtoc">
474 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
479 <xsl:template match=
"bibliography|glossary" mode=
"toc">
480 <xsl:param name=
"toc-context" select=
"."/>
482 <xsl:call-template name=
"subtoc">
483 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
487 <xsl:template match=
"index" mode=
"toc">
488 <xsl:param name=
"toc-context" select=
"."/>
490 <!-- If the index tag is not empty, it should be it in the TOC -->
491 <xsl:if test=
"* or $generate.index != 0">
492 <xsl:call-template name=
"subtoc">
493 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
498 <xsl:template match=
"refentry" mode=
"toc">
499 <xsl:param name=
"toc-context" select=
"."/>
501 <xsl:variable name=
"refmeta" select=
".//refmeta"/>
502 <xsl:variable name=
"refentrytitle" select=
"$refmeta//refentrytitle"/>
503 <xsl:variable name=
"refnamediv" select=
".//refnamediv"/>
504 <xsl:variable name=
"refname" select=
"$refnamediv//refname"/>
505 <xsl:variable name=
"refdesc" select=
"$refnamediv//refdescriptor"/>
506 <xsl:variable name=
"title">
508 <xsl:when test=
"$refentrytitle">
509 <xsl:apply-templates select=
"$refentrytitle[1]"
510 mode=
"titleabbrev.markup"/>
512 <xsl:when test=
"$refdesc">
513 <xsl:apply-templates select=
"$refdesc"
514 mode=
"titleabbrev.markup"/>
516 <xsl:when test=
"$refname">
517 <xsl:apply-templates select=
"$refname[1]"
518 mode=
"titleabbrev.markup"/>
523 <xsl:element name=
"{$toc.listitem.type}">
524 <span class='refentrytitle'
>
526 <xsl:attribute name=
"href">
527 <xsl:call-template name=
"href.target"/>
529 <xsl:copy-of select=
"$title"/>
532 <span class='refpurpose'
>
533 <xsl:if test=
"$annotate.toc != 0">
534 <!-- * DocBook 5 says inlinemediaobject (among other things) -->
535 <!-- * is allowed in refpurpose; so we need to run -->
536 <!-- * apply-templates on refpurpose here, instead of value-of -->
537 <xsl:apply-templates select=
"refnamediv/refpurpose"/>
543 <xsl:template match=
"title" mode=
"toc">
544 <xsl:param name=
"toc-context" select=
"."/>
547 <xsl:attribute name=
"href">
548 <xsl:call-template name=
"href.target">
549 <xsl:with-param name=
"object" select=
".."/>
552 <xsl:apply-templates/>
556 <xsl:template name=
"manual-toc">
557 <xsl:param name=
"toc-context" select=
"."/>
558 <xsl:param name=
"tocentry"/>
560 <!-- be careful, we don't want to change the current document to the other tree! -->
562 <xsl:if test=
"$tocentry">
563 <xsl:variable name=
"node" select=
"key('id', $tocentry/@linkend)"/>
565 <xsl:element name=
"{$toc.listitem.type}">
566 <xsl:variable name=
"label">
567 <xsl:apply-templates select=
"$node" mode=
"label.markup"/>
569 <xsl:copy-of select=
"$label"/>
570 <xsl:if test=
"$label != ''">
571 <xsl:value-of select=
"$autotoc.label.separator"/>
574 <xsl:attribute name=
"href">
575 <xsl:call-template name=
"href.target">
576 <xsl:with-param name=
"object" select=
"$node"/>
579 <xsl:apply-templates select=
"$node" mode=
"titleabbrev.markup"/>
583 <xsl:if test=
"$tocentry/*">
584 <xsl:element name=
"{$toc.list.type}">
585 <xsl:call-template name=
"manual-toc">
586 <xsl:with-param name=
"tocentry" select=
"$tocentry/*[1]"/>
591 <xsl:if test=
"$tocentry/following-sibling::*">
592 <xsl:call-template name=
"manual-toc">
593 <xsl:with-param name=
"tocentry" select=
"$tocentry/following-sibling::*[1]"/>
599 <!-- ==================================================================== -->
601 <xsl:template name=
"list.of.titles">
602 <xsl:param name=
"toc-context" select=
"."/>
603 <xsl:param name=
"titles" select=
"'table'"/>
604 <xsl:param name=
"nodes" select=
".//table"/>
606 <xsl:if test=
"$nodes">
607 <div class=
"list-of-{$titles}s">
610 <xsl:call-template name=
"gentext">
611 <xsl:with-param name=
"key">
613 <xsl:when test=
"$titles='table'">ListofTables
</xsl:when>
614 <xsl:when test=
"$titles='figure'">ListofFigures
</xsl:when>
615 <xsl:when test=
"$titles='equation'">ListofEquations
</xsl:when>
616 <xsl:when test=
"$titles='example'">ListofExamples
</xsl:when>
617 <xsl:when test=
"$titles='procedure'">ListofProcedures
</xsl:when>
618 <xsl:otherwise>ListofUnknown
</xsl:otherwise>
625 <xsl:element name=
"{$toc.list.type}">
626 <xsl:apply-templates select=
"$nodes" mode=
"toc">
627 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
628 </xsl:apply-templates>
634 <xsl:template match=
"figure|table|example|equation|procedure" mode=
"toc">
635 <xsl:param name=
"toc-context" select=
"."/>
637 <xsl:element name=
"{$toc.listitem.type}">
638 <xsl:variable name=
"label">
639 <xsl:apply-templates select=
"." mode=
"label.markup"/>
641 <xsl:copy-of select=
"$label"/>
642 <xsl:if test=
"$label != ''">
643 <xsl:value-of select=
"$autotoc.label.separator"/>
646 <xsl:attribute name=
"href">
647 <xsl:call-template name=
"href.target"/>
649 <xsl:apply-templates select=
"." mode=
"titleabbrev.markup"/>
654 <!-- Used only if qanda.in.toc parameter is non-zero -->
655 <xsl:template match=
"qandaset" mode=
"toc">
656 <xsl:param name=
"toc-context" select=
"."/>
657 <xsl:call-template name=
"subtoc">
658 <xsl:with-param name=
"toc-context" select=
"$toc-context"/>
659 <xsl:with-param name=
"nodes" select=
"qandadiv | qandaentry"/>
663 <xsl:template match=
"qandadiv|qandaentry" mode=
"toc">
664 <xsl:apply-templates select=
"." mode=
"qandatoc.mode"/>