2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5 <!-- ********************************************************************
6 $Id: autotoc.xsl 8558 2009-12-11 00:33:17Z 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 <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">
40 <xsl:when test="$make.clean.html != 0">
41 <div class="toc-title">
42 <xsl:call-template name="gentext">
43 <xsl:with-param name="key">TableofContents</xsl:with-param>
50 <xsl:call-template name="gentext">
51 <xsl:with-param name="key">TableofContents</xsl:with-param>
61 <xsl:when test="$manual.toc != ''">
62 <xsl:variable name="id">
63 <xsl:call-template name="object.id"/>
65 <xsl:variable name="toc" select="document($manual.toc, .)"/>
66 <xsl:variable name="tocentry" select="$toc//tocentry[@linkend=$id]"/>
67 <xsl:if test="$tocentry and $tocentry/*">
69 <xsl:copy-of select="$toc.title"/>
70 <xsl:element name="{$toc.list.type}">
71 <xsl:call-template name="manual-toc">
72 <xsl:with-param name="tocentry" select="$tocentry/*[1]"/>
80 <xsl:when test="$qanda.in.toc != 0">
81 <xsl:if test="$nodes.plus">
83 <xsl:copy-of select="$toc.title"/>
84 <xsl:element name="{$toc.list.type}">
85 <xsl:apply-templates select="$nodes.plus" mode="toc">
86 <xsl:with-param name="toc-context" select="$toc-context"/>
87 </xsl:apply-templates>
93 <xsl:if test="$nodes">
95 <xsl:copy-of select="$toc.title"/>
96 <xsl:element name="{$toc.list.type}">
97 <xsl:apply-templates select="$nodes" mode="toc">
98 <xsl:with-param name="toc-context" select="$toc-context"/>
99 </xsl:apply-templates>
110 <xsl:template name="make.lots">
111 <xsl:param name="toc.params" select="''"/>
112 <xsl:param name="toc"/>
114 <xsl:if test="contains($toc.params, 'toc')">
115 <xsl:copy-of select="$toc"/>
118 <xsl:if test="contains($toc.params, 'figure')">
119 <xsl:call-template name="list.of.titles">
120 <xsl:with-param name="titles" select="'figure'"/>
121 <xsl:with-param name="nodes" select=".//figure"/>
125 <xsl:if test="contains($toc.params, 'table')">
126 <xsl:call-template name="list.of.titles">
127 <xsl:with-param name="titles" select="'table'"/>
128 <xsl:with-param name="nodes" select=".//table"/>
132 <xsl:if test="contains($toc.params, 'example')">
133 <xsl:call-template name="list.of.titles">
134 <xsl:with-param name="titles" select="'example'"/>
135 <xsl:with-param name="nodes" select=".//example"/>
139 <xsl:if test="contains($toc.params, 'equation')">
140 <xsl:call-template name="list.of.titles">
141 <xsl:with-param name="titles" select="'equation'"/>
142 <xsl:with-param name="nodes" select=".//equation[title or info/title]"/>
146 <xsl:if test="contains($toc.params, 'procedure')">
147 <xsl:call-template name="list.of.titles">
148 <xsl:with-param name="titles" select="'procedure'"/>
149 <xsl:with-param name="nodes" select=".//procedure[title]"/>
154 <!-- ====================================================================== -->
156 <xsl:template name="set.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="book|setindex"/>
167 <xsl:template name="division.toc">
168 <xsl:param name="toc-context" select="."/>
169 <xsl:param name="toc.title.p" select="true()"/>
171 <xsl:call-template name="make.toc">
172 <xsl:with-param name="toc-context" select="$toc-context"/>
173 <xsl:with-param name="toc.title.p" select="$toc.title.p"/>
174 <xsl:with-param name="nodes" select="part|reference
175 |preface|chapter|appendix
177 |bibliography|glossary|index
179 |bridgehead[$bridgehead.in.toc != 0]"/>
184 <xsl:template name="component.toc">
185 <xsl:param name="toc-context" select="."/>
186 <xsl:param name="toc.title.p" select="true()"/>
188 <xsl:call-template name="make.toc">
189 <xsl:with-param name="toc-context" select="$toc-context"/>
190 <xsl:with-param name="toc.title.p" select="$toc.title.p"/>
191 <xsl:with-param name="nodes" select="section|sect1
192 |simplesect[$simplesect.in.toc != 0]
194 |article|bibliography|glossary
196 |bridgehead[not(@renderas)
197 and $bridgehead.in.toc != 0]
198 |.//bridgehead[@renderas='sect1'
199 and $bridgehead.in.toc != 0]"/>
203 <xsl:template name="component.toc.separator">
204 <!-- Customize to output something between
205 component.toc and first output -->
208 <xsl:template name="section.toc">
209 <xsl:param name="toc-context" select="."/>
210 <xsl:param name="toc.title.p" select="true()"/>
212 <xsl:call-template name="make.toc">
213 <xsl:with-param name="toc-context" select="$toc-context"/>
214 <xsl:with-param name="toc.title.p" select="$toc.title.p"/>
215 <xsl:with-param name="nodes"
216 select="section|sect1|sect2|sect3|sect4|sect5|refentry
217 |bridgehead[$bridgehead.in.toc != 0]"/>
222 <xsl:template name="section.toc.separator">
223 <!-- Customize to output something between
224 section.toc and first output -->
226 <!-- ==================================================================== -->
228 <xsl:template name="subtoc">
229 <xsl:param name="toc-context" select="."/>
230 <xsl:param name="nodes" select="NOT-AN-ELEMENT"/>
232 <xsl:variable name="nodes.plus" select="$nodes | qandaset"/>
234 <xsl:variable name="subtoc">
235 <xsl:element name="{$toc.list.type}">
237 <xsl:when test="$qanda.in.toc != 0">
238 <xsl:apply-templates mode="toc" select="$nodes.plus">
239 <xsl:with-param name="toc-context" select="$toc-context"/>
240 </xsl:apply-templates>
243 <xsl:apply-templates mode="toc" select="$nodes">
244 <xsl:with-param name="toc-context" select="$toc-context"/>
245 </xsl:apply-templates>
251 <xsl:variable name="depth">
253 <xsl:when test="local-name(.) = 'section'">
254 <xsl:value-of select="count(ancestor::section) + 1"/>
256 <xsl:when test="local-name(.) = 'sect1'">1</xsl:when>
257 <xsl:when test="local-name(.) = 'sect2'">2</xsl:when>
258 <xsl:when test="local-name(.) = 'sect3'">3</xsl:when>
259 <xsl:when test="local-name(.) = 'sect4'">4</xsl:when>
260 <xsl:when test="local-name(.) = 'sect5'">5</xsl:when>
261 <xsl:when test="local-name(.) = 'refsect1'">1</xsl:when>
262 <xsl:when test="local-name(.) = 'refsect2'">2</xsl:when>
263 <xsl:when test="local-name(.) = 'refsect3'">3</xsl:when>
264 <xsl:when test="local-name(.) = 'simplesect'">
267 <xsl:when test="local-name(..) = 'section'">
268 <xsl:value-of select="count(ancestor::section)"/>
270 <xsl:when test="local-name(..) = 'sect1'">2</xsl:when>
271 <xsl:when test="local-name(..) = 'sect2'">3</xsl:when>
272 <xsl:when test="local-name(..) = 'sect3'">4</xsl:when>
273 <xsl:when test="local-name(..) = 'sect4'">5</xsl:when>
274 <xsl:when test="local-name(..) = 'sect5'">6</xsl:when>
275 <xsl:when test="local-name(..) = 'refsect1'">2</xsl:when>
276 <xsl:when test="local-name(..) = 'refsect2'">3</xsl:when>
277 <xsl:when test="local-name(..) = 'refsect3'">4</xsl:when>
278 <xsl:otherwise>1</xsl:otherwise>
281 <xsl:otherwise>0</xsl:otherwise>
285 <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
287 <xsl:variable name="subtoc.list">
289 <xsl:when test="$toc.dd.type = ''">
290 <xsl:copy-of select="$subtoc"/>
293 <xsl:element name="{$toc.dd.type}">
294 <xsl:copy-of select="$subtoc"/>
300 <xsl:element name="{$toc.listitem.type}">
301 <xsl:call-template name="toc.line">
302 <xsl:with-param name="toc-context" select="$toc-context"/>
304 <xsl:if test="$toc.listitem.type = 'li'
305 and $toc.section.depth > $depth and
306 ( ($qanda.in.toc = 0 and count($nodes)>0) or
307 ($qanda.in.toc != 0 and count($nodes.plus)>0) )
308 and $toc.max.depth > $depth.from.context">
309 <xsl:copy-of select="$subtoc.list"/>
312 <xsl:if test="$toc.listitem.type != 'li'
313 and $toc.section.depth > $depth and
314 ( ($qanda.in.toc = 0 and count($nodes)>0) or
315 ($qanda.in.toc != 0 and count($nodes.plus)>0) )
316 and $toc.max.depth > $depth.from.context">
317 <xsl:copy-of select="$subtoc.list"/>
321 <xsl:template name="toc.line">
322 <xsl:param name="toc-context" select="."/>
323 <xsl:param name="depth" select="1"/>
324 <xsl:param name="depth.from.context" select="8"/>
327 <xsl:attribute name="class"><xsl:value-of select="local-name(.)"/></xsl:attribute>
329 <!-- * if $autotoc.label.in.hyperlink is zero, then output the label -->
330 <!-- * before the hyperlinked title (as the DSSSL stylesheet does) -->
331 <xsl:if test="$autotoc.label.in.hyperlink = 0">
332 <xsl:variable name="label">
333 <xsl:apply-templates select="." mode="label.markup"/>
335 <xsl:copy-of select="$label"/>
336 <xsl:if test="$label != ''">
337 <xsl:value-of select="$autotoc.label.separator"/>
342 <xsl:attribute name="href">
343 <xsl:call-template name="href.target">
344 <xsl:with-param name="context" select="$toc-context"/>
345 <xsl:with-param name="toc-context" select="$toc-context"/>
349 <!-- * if $autotoc.label.in.hyperlink is non-zero, then output the label -->
350 <!-- * as part of the hyperlinked title -->
351 <xsl:if test="not($autotoc.label.in.hyperlink = 0)">
352 <xsl:variable name="label">
353 <xsl:apply-templates select="." mode="label.markup"/>
355 <xsl:copy-of select="$label"/>
356 <xsl:if test="$label != ''">
357 <xsl:value-of select="$autotoc.label.separator"/>
361 <xsl:apply-templates select="." mode="titleabbrev.markup"/>
366 <xsl:template match="book" mode="toc">
367 <xsl:param name="toc-context" select="."/>
369 <xsl:call-template name="subtoc">
370 <xsl:with-param name="toc-context" select="$toc-context"/>
371 <xsl:with-param name="nodes" select="part|reference
372 |preface|chapter|appendix
374 |bibliography|glossary|index
376 |bridgehead[$bridgehead.in.toc != 0]"/>
380 <xsl:template match="setindex" mode="toc">
381 <xsl:param name="toc-context" select="."/>
383 <!-- If the setindex tag is not empty, it should be it in the TOC -->
384 <xsl:if test="* or $generate.index != 0">
385 <xsl:call-template name="subtoc">
386 <xsl:with-param name="toc-context" select="$toc-context"/>
391 <xsl:template match="part|reference" 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="appendix|chapter|article
397 |index|glossary|bibliography
398 |preface|reference|refentry
399 |bridgehead[$bridgehead.in.toc != 0]"/>
403 <xsl:template match="preface|chapter|appendix|article" mode="toc">
404 <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="section|sect1
409 |simplesect[$simplesect.in.toc != 0]
411 |glossary|bibliography|index
412 |bridgehead[$bridgehead.in.toc != 0]"/>
416 <xsl:template match="sect1" mode="toc">
417 <xsl:param name="toc-context" select="."/>
418 <xsl:call-template name="subtoc">
419 <xsl:with-param name="toc-context" select="$toc-context"/>
420 <xsl:with-param name="nodes" select="sect2
421 |bridgehead[$bridgehead.in.toc != 0]"/>
425 <xsl:template match="sect2" mode="toc">
426 <xsl:param name="toc-context" select="."/>
428 <xsl:call-template name="subtoc">
429 <xsl:with-param name="toc-context" select="$toc-context"/>
430 <xsl:with-param name="nodes" select="sect3
431 |bridgehead[$bridgehead.in.toc != 0]"/>
435 <xsl:template match="sect3" mode="toc">
436 <xsl:param name="toc-context" select="."/>
438 <xsl:call-template name="subtoc">
439 <xsl:with-param name="toc-context" select="$toc-context"/>
440 <xsl:with-param name="nodes" select="sect4
441 |bridgehead[$bridgehead.in.toc != 0]"/>
445 <xsl:template match="sect4" mode="toc">
446 <xsl:param name="toc-context" select="."/>
448 <xsl:call-template name="subtoc">
449 <xsl:with-param name="toc-context" select="$toc-context"/>
450 <xsl:with-param name="nodes" select="sect5
451 |bridgehead[$bridgehead.in.toc != 0]"/>
455 <xsl:template match="sect5" mode="toc">
456 <xsl:param name="toc-context" select="."/>
458 <xsl:call-template name="subtoc">
459 <xsl:with-param name="toc-context" select="$toc-context"/>
463 <xsl:template match="simplesect" mode="toc">
464 <xsl:param name="toc-context" select="."/>
466 <xsl:call-template name="subtoc">
467 <xsl:with-param name="toc-context" select="$toc-context"/>
471 <xsl:template match="section" mode="toc">
472 <xsl:param name="toc-context" select="."/>
474 <xsl:call-template name="subtoc">
475 <xsl:with-param name="toc-context" select="$toc-context"/>
476 <xsl:with-param name="nodes" select="section|refentry
477 |simplesect[$simplesect.in.toc != 0]
478 |bridgehead[$bridgehead.in.toc != 0]"/>
482 <xsl:template match="bridgehead" mode="toc">
483 <xsl:param name="toc-context" select="."/>
485 <xsl:if test="$bridgehead.in.toc != 0">
486 <xsl:call-template name="subtoc">
487 <xsl:with-param name="toc-context" select="$toc-context"/>
492 <xsl:template match="bibliography|glossary" mode="toc">
493 <xsl:param name="toc-context" select="."/>
495 <xsl:call-template name="subtoc">
496 <xsl:with-param name="toc-context" select="$toc-context"/>
500 <xsl:template match="index" mode="toc">
501 <xsl:param name="toc-context" select="."/>
503 <!-- If the index tag is not empty, it should be it in the TOC -->
504 <xsl:if test="* or $generate.index != 0">
505 <xsl:call-template name="subtoc">
506 <xsl:with-param name="toc-context" select="$toc-context"/>
511 <xsl:template match="refentry" mode="toc">
512 <xsl:param name="toc-context" select="."/>
514 <xsl:variable name="refmeta" select=".//refmeta"/>
515 <xsl:variable name="refentrytitle" select="$refmeta//refentrytitle"/>
516 <xsl:variable name="refnamediv" select=".//refnamediv"/>
517 <xsl:variable name="refname" select="$refnamediv//refname"/>
518 <xsl:variable name="refdesc" select="$refnamediv//refdescriptor"/>
519 <xsl:variable name="title">
521 <xsl:when test="$refentrytitle">
522 <xsl:apply-templates select="$refentrytitle[1]"
523 mode="titleabbrev.markup"/>
525 <xsl:when test="$refdesc">
526 <xsl:apply-templates select="$refdesc"
527 mode="titleabbrev.markup"/>
529 <xsl:when test="$refname">
530 <xsl:apply-templates select="$refname[1]"
531 mode="titleabbrev.markup"/>
536 <xsl:element name="{$toc.listitem.type}">
537 <span class='refentrytitle'>
539 <xsl:attribute name="href">
540 <xsl:call-template name="href.target">
541 <xsl:with-param name="toc-context" select="$toc-context"/>
544 <xsl:copy-of select="$title"/>
547 <span class='refpurpose'>
548 <xsl:if test="$annotate.toc != 0">
549 <!-- * DocBook 5 says inlinemediaobject (among other things) -->
550 <!-- * is allowed in refpurpose; so we need to run -->
551 <!-- * apply-templates on refpurpose here, instead of value-of -->
552 <xsl:apply-templates select="refnamediv/refpurpose"/>
558 <xsl:template match="title" mode="toc">
559 <xsl:param name="toc-context" select="."/>
562 <xsl:attribute name="href">
563 <xsl:call-template name="href.target">
564 <xsl:with-param name="object" select=".."/>
565 <xsl:with-param name="toc-context" select="$toc-context"/>
568 <xsl:apply-templates/>
572 <xsl:template name="manual-toc">
573 <xsl:param name="toc-context" select="."/>
574 <xsl:param name="tocentry"/>
576 <!-- be careful, we don't want to change the current document to the other tree! -->
578 <xsl:if test="$tocentry">
579 <xsl:variable name="node" select="key('id', $tocentry/@linkend)"/>
581 <xsl:element name="{$toc.listitem.type}">
582 <xsl:variable name="label">
583 <xsl:apply-templates select="$node" mode="label.markup"/>
585 <xsl:copy-of select="$label"/>
586 <xsl:if test="$label != ''">
587 <xsl:value-of select="$autotoc.label.separator"/>
590 <xsl:attribute name="href">
591 <xsl:call-template name="href.target">
592 <xsl:with-param name="object" select="$node"/>
593 <xsl:with-param name="toc-context" select="$toc-context"/>
596 <xsl:apply-templates select="$node" mode="titleabbrev.markup"/>
600 <xsl:if test="$tocentry/*">
601 <xsl:element name="{$toc.list.type}">
602 <xsl:call-template name="manual-toc">
603 <xsl:with-param name="tocentry" select="$tocentry/*[1]"/>
608 <xsl:if test="$tocentry/following-sibling::*">
609 <xsl:call-template name="manual-toc">
610 <xsl:with-param name="tocentry" select="$tocentry/following-sibling::*[1]"/>
616 <!-- ==================================================================== -->
618 <xsl:template name="list.of.titles">
619 <xsl:param name="toc-context" select="."/>
620 <xsl:param name="titles" select="'table'"/>
621 <xsl:param name="nodes" select=".//table"/>
623 <xsl:if test="$nodes">
624 <div class="list-of-{$titles}s">
626 <xsl:when test="$make.clean.html != 0">
627 <div class="toc-title">
628 <xsl:call-template name="gentext">
629 <xsl:with-param name="key">
631 <xsl:when test="$titles='table'">ListofTables</xsl:when>
632 <xsl:when test="$titles='figure'">ListofFigures</xsl:when>
633 <xsl:when test="$titles='equation'">ListofEquations</xsl:when>
634 <xsl:when test="$titles='example'">ListofExamples</xsl:when>
635 <xsl:when test="$titles='procedure'">ListofProcedures</xsl:when>
636 <xsl:otherwise>ListofUnknown</xsl:otherwise>
645 <xsl:call-template name="gentext">
646 <xsl:with-param name="key">
648 <xsl:when test="$titles='table'">ListofTables</xsl:when>
649 <xsl:when test="$titles='figure'">ListofFigures</xsl:when>
650 <xsl:when test="$titles='equation'">ListofEquations</xsl:when>
651 <xsl:when test="$titles='example'">ListofExamples</xsl:when>
652 <xsl:when test="$titles='procedure'">ListofProcedures</xsl:when>
653 <xsl:otherwise>ListofUnknown</xsl:otherwise>
662 <xsl:element name="{$toc.list.type}">
663 <xsl:apply-templates select="$nodes" mode="toc">
664 <xsl:with-param name="toc-context" select="$toc-context"/>
665 </xsl:apply-templates>
671 <xsl:template match="figure|table|example|equation|procedure" mode="toc">
672 <xsl:param name="toc-context" select="."/>
674 <xsl:element name="{$toc.listitem.type}">
675 <xsl:variable name="label">
676 <xsl:apply-templates select="." mode="label.markup"/>
678 <xsl:copy-of select="$label"/>
679 <xsl:if test="$label != ''">
680 <xsl:value-of select="$autotoc.label.separator"/>
683 <xsl:attribute name="href">
684 <xsl:call-template name="href.target">
685 <xsl:with-param name="toc-context" select="$toc-context"/>
688 <xsl:apply-templates select="." mode="titleabbrev.markup"/>
693 <!-- Used only if qanda.in.toc parameter is non-zero -->
694 <xsl:template match="qandaset" mode="toc">
695 <xsl:param name="toc-context" select="."/>
696 <xsl:call-template name="subtoc">
697 <xsl:with-param name="toc-context" select="$toc-context"/>
698 <xsl:with-param name="nodes" select="qandadiv | qandaentry"/>
702 <xsl:template match="qandadiv|qandaentry" mode="toc">
703 <xsl:apply-templates select="." mode="qandatoc.mode"/>