source: trunk/Distribution/XSL/html/autotoc.xsl@ 2

Last change on this file since 2 was 2, checked in by jkacer, 18 years ago

Added all DocBook Framework stuff:

  • DocBook DTD
  • Transformation software FOP 0.20.5 and Saxon 6
  • XSL styles
  • Rexx scripts

Also added some WarpIN-related stuff for creation of WarpIN installation packages.
This state corresponds to version 1.0.0 from November 2005, just slightly modified to carry versioning information (Rexx scripts).

File size: 20.5 KB
Line 
1<?xml version='1.0'?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 version='1.0'>
4
5<!-- ********************************************************************
6 $Id: autotoc.xsl,v 1.34 2005/01/19 15:15:31 nwalsh Exp $
7 ********************************************************************
8
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.
12
13 ******************************************************************** -->
14
15<xsl:variable name="toc.listitem.type">
16 <xsl:choose>
17 <xsl:when test="$toc.list.type = 'dl'">dt</xsl:when>
18 <xsl:otherwise>li</xsl:otherwise>
19 </xsl:choose>
20</xsl:variable>
21
22<!-- this is just hack because dl and ul aren't completely isomorphic -->
23<xsl:variable name="toc.dd.type">
24 <xsl:choose>
25 <xsl:when test="$toc.list.type = 'dl'">dd</xsl:when>
26 <xsl:otherwise></xsl:otherwise>
27 </xsl:choose>
28</xsl:variable>
29
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"/>
34
35 <xsl:variable name="toc.title">
36 <xsl:if test="$toc.title.p">
37 <p>
38 <b>
39 <xsl:call-template name="gentext">
40 <xsl:with-param name="key">TableofContents</xsl:with-param>
41 </xsl:call-template>
42 </b>
43 </p>
44 </xsl:if>
45 </xsl:variable>
46
47 <xsl:choose>
48 <xsl:when test="$manual.toc != ''">
49 <xsl:variable name="id">
50 <xsl:call-template name="object.id"/>
51 </xsl:variable>
52 <xsl:variable name="toc" select="document($manual.toc, .)"/>
53 <xsl:variable name="tocentry" select="$toc//tocentry[@linkend=$id]"/>
54 <xsl:if test="$tocentry and $tocentry/*">
55 <div class="toc">
56 <xsl:copy-of select="$toc.title"/>
57 <xsl:element name="{$toc.list.type}">
58 <xsl:call-template name="manual-toc">
59 <xsl:with-param name="tocentry" select="$tocentry/*[1]"/>
60 </xsl:call-template>
61 </xsl:element>
62 </div>
63 </xsl:if>
64 </xsl:when>
65 <xsl:otherwise>
66 <xsl:if test="$nodes">
67 <div class="toc">
68 <xsl:copy-of select="$toc.title"/>
69 <xsl:element name="{$toc.list.type}">
70 <xsl:apply-templates select="$nodes" mode="toc">
71 <xsl:with-param name="toc-context" select="$toc-context"/>
72 </xsl:apply-templates>
73 </xsl:element>
74 </div>
75 </xsl:if>
76 </xsl:otherwise>
77 </xsl:choose>
78</xsl:template>
79
80<xsl:template name="make.lots">
81 <xsl:param name="toc.params" select="''"/>
82 <xsl:param name="toc"/>
83
84 <xsl:if test="contains($toc.params, 'toc')">
85 <xsl:copy-of select="$toc"/>
86 </xsl:if>
87
88 <xsl:if test="contains($toc.params, 'figure')">
89 <xsl:call-template name="list.of.titles">
90 <xsl:with-param name="titles" select="'figure'"/>
91 <xsl:with-param name="nodes" select=".//figure"/>
92 </xsl:call-template>
93 </xsl:if>
94
95 <xsl:if test="contains($toc.params, 'table')">
96 <xsl:call-template name="list.of.titles">
97 <xsl:with-param name="titles" select="'table'"/>
98 <xsl:with-param name="nodes" select=".//table"/>
99 </xsl:call-template>
100 </xsl:if>
101
102 <xsl:if test="contains($toc.params, 'example')">
103 <xsl:call-template name="list.of.titles">
104 <xsl:with-param name="titles" select="'example'"/>
105 <xsl:with-param name="nodes" select=".//example"/>
106 </xsl:call-template>
107 </xsl:if>
108
109 <xsl:if test="contains($toc.params, 'equation')">
110 <xsl:call-template name="list.of.titles">
111 <xsl:with-param name="titles" select="'equation'"/>
112 <xsl:with-param name="nodes" select=".//equation[title]"/>
113 </xsl:call-template>
114 </xsl:if>
115
116 <xsl:if test="contains($toc.params, 'procedure')">
117 <xsl:call-template name="list.of.titles">
118 <xsl:with-param name="titles" select="'procedure'"/>
119 <xsl:with-param name="nodes" select=".//procedure[title]"/>
120 </xsl:call-template>
121 </xsl:if>
122</xsl:template>
123
124<!-- ====================================================================== -->
125
126<xsl:template name="set.toc">
127 <xsl:param name="toc-context" select="."/>
128
129 <xsl:call-template name="make.toc">
130 <xsl:with-param name="toc-context" select="$toc-context"/>
131 <xsl:with-param name="nodes" select="book|setindex"/>
132 </xsl:call-template>
133</xsl:template>
134
135<xsl:template name="division.toc">
136 <xsl:param name="toc-context" select="."/>
137
138 <xsl:call-template name="make.toc">
139 <xsl:with-param name="toc-context" select="$toc-context"/>
140 <xsl:with-param name="nodes" select="part|reference
141 |preface|chapter|appendix
142 |article
143 |bibliography|glossary|index
144 |refentry
145 |bridgehead[$bridgehead.in.toc != 0]"/>
146
147 </xsl:call-template>
148</xsl:template>
149
150<xsl:template name="component.toc">
151 <xsl:param name="toc-context" select="."/>
152 <xsl:param name="toc.title.p" select="true()"/>
153
154 <xsl:call-template name="make.toc">
155 <xsl:with-param name="toc-context" select="$toc-context"/>
156 <xsl:with-param name="toc.title.p" select="$toc.title.p"/>
157 <xsl:with-param name="nodes" select="section|sect1
158 |simplesect[$simplesect.in.toc != 0]
159 |refentry
160 |article|bibliography|glossary
161 |appendix|index
162 |bridgehead[not(@renderas)
163 and $bridgehead.in.toc != 0]
164 |.//bridgehead[@renderas='sect1'
165 and $bridgehead.in.toc != 0]"/>
166 </xsl:call-template>
167</xsl:template>
168
169<xsl:template name="component.toc.separator">
170 <!-- Customize to output something between
171 component.toc and first output -->
172</xsl:template>
173
174<xsl:template name="section.toc">
175 <xsl:param name="toc-context" select="."/>
176 <xsl:param name="toc.title.p" select="true()"/>
177
178 <xsl:call-template name="make.toc">
179 <xsl:with-param name="toc-context" select="$toc-context"/>
180 <xsl:with-param name="toc.title.p" select="$toc.title.p"/>
181 <xsl:with-param name="nodes"
182 select="section|sect1|sect2|sect3|sect4|sect5|refentry
183 |bridgehead[$bridgehead.in.toc != 0]"/>
184
185 </xsl:call-template>
186</xsl:template>
187
188<xsl:template name="section.toc.separator">
189 <!-- Customize to output something between
190 section.toc and first output -->
191</xsl:template>
192<!-- ==================================================================== -->
193
194<xsl:template name="subtoc">
195 <xsl:param name="toc-context" select="."/>
196 <xsl:param name="nodes" select="NOT-AN-ELEMENT"/>
197
198 <xsl:variable name="subtoc">
199 <xsl:element name="{$toc.list.type}">
200 <xsl:apply-templates mode="toc" select="$nodes">
201 <xsl:with-param name="toc-context" select="$toc-context"/>
202 </xsl:apply-templates>
203 </xsl:element>
204 </xsl:variable>
205
206 <xsl:variable name="depth">
207 <xsl:choose>
208 <xsl:when test="local-name(.) = 'section'">
209 <xsl:value-of select="count(ancestor::section) + 1"/>
210 </xsl:when>
211 <xsl:when test="local-name(.) = 'sect1'">1</xsl:when>
212 <xsl:when test="local-name(.) = 'sect2'">2</xsl:when>
213 <xsl:when test="local-name(.) = 'sect3'">3</xsl:when>
214 <xsl:when test="local-name(.) = 'sect4'">4</xsl:when>
215 <xsl:when test="local-name(.) = 'sect5'">5</xsl:when>
216 <xsl:when test="local-name(.) = 'refsect1'">1</xsl:when>
217 <xsl:when test="local-name(.) = 'refsect2'">2</xsl:when>
218 <xsl:when test="local-name(.) = 'refsect3'">3</xsl:when>
219 <xsl:when test="local-name(.) = 'simplesect'">
220 <!-- sigh... -->
221 <xsl:choose>
222 <xsl:when test="local-name(..) = 'section'">
223 <xsl:value-of select="count(ancestor::section)"/>
224 </xsl:when>
225 <xsl:when test="local-name(..) = 'sect1'">2</xsl:when>
226 <xsl:when test="local-name(..) = 'sect2'">3</xsl:when>
227 <xsl:when test="local-name(..) = 'sect3'">4</xsl:when>
228 <xsl:when test="local-name(..) = 'sect4'">5</xsl:when>
229 <xsl:when test="local-name(..) = 'sect5'">6</xsl:when>
230 <xsl:when test="local-name(..) = 'refsect1'">2</xsl:when>
231 <xsl:when test="local-name(..) = 'refsect2'">3</xsl:when>
232 <xsl:when test="local-name(..) = 'refsect3'">4</xsl:when>
233 <xsl:otherwise>1</xsl:otherwise>
234 </xsl:choose>
235 </xsl:when>
236 <xsl:otherwise>0</xsl:otherwise>
237 </xsl:choose>
238 </xsl:variable>
239
240 <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
241
242 <xsl:variable name="subtoc.list">
243 <xsl:choose>
244 <xsl:when test="$toc.dd.type = ''">
245 <xsl:copy-of select="$subtoc"/>
246 </xsl:when>
247 <xsl:otherwise>
248 <xsl:element name="{$toc.dd.type}">
249 <xsl:copy-of select="$subtoc"/>
250 </xsl:element>
251 </xsl:otherwise>
252 </xsl:choose>
253 </xsl:variable>
254
255 <xsl:element name="{$toc.listitem.type}">
256 <xsl:call-template name="toc.line">
257 <xsl:with-param name="toc-context" select="$toc-context"/>
258 </xsl:call-template>
259 <xsl:if test="$toc.listitem.type = 'li'
260 and $toc.section.depth > $depth and count($nodes)&gt;0
261 and $toc.max.depth > $depth.from.context">
262 <xsl:copy-of select="$subtoc.list"/>
263 </xsl:if>
264 </xsl:element>
265 <xsl:if test="$toc.listitem.type != 'li'
266 and $toc.section.depth > $depth and count($nodes)&gt;0
267 and $toc.max.depth > $depth.from.context">
268 <xsl:copy-of select="$subtoc.list"/>
269 </xsl:if>
270</xsl:template>
271
272<xsl:template name="toc.line">
273 <xsl:param name="toc-context" select="."/>
274 <xsl:param name="depth" select="1"/>
275 <xsl:param name="depth.from.context" select="8"/>
276
277 <span>
278 <xsl:attribute name="class"><xsl:value-of select="local-name(.)"/></xsl:attribute>
279 <a>
280 <xsl:attribute name="href">
281 <xsl:call-template name="href.target">
282 <xsl:with-param name="context" select="$toc-context"/>
283 </xsl:call-template>
284 </xsl:attribute>
285
286 <xsl:variable name="label">
287 <xsl:apply-templates select="." mode="label.markup"/>
288 </xsl:variable>
289 <xsl:copy-of select="$label"/>
290 <xsl:if test="$label != ''">
291 <xsl:value-of select="$autotoc.label.separator"/>
292 </xsl:if>
293
294 <xsl:apply-templates select="." mode="titleabbrev.markup"/>
295 </a>
296 </span>
297</xsl:template>
298
299<xsl:template match="book" mode="toc">
300 <xsl:param name="toc-context" select="."/>
301
302 <xsl:call-template name="subtoc">
303 <xsl:with-param name="toc-context" select="$toc-context"/>
304 <xsl:with-param name="nodes" select="part|reference
305 |preface|chapter|appendix
306 |article
307 |bibliography|glossary|index
308 |refentry
309 |bridgehead[$bridgehead.in.toc != 0]"/>
310 </xsl:call-template>
311</xsl:template>
312
313<xsl:template match="setindex" mode="toc">
314 <xsl:param name="toc-context" select="."/>
315
316 <!-- If the setindex tag is not empty, it should be it in the TOC -->
317 <xsl:if test="* or $generate.index != 0">
318 <xsl:call-template name="subtoc">
319 <xsl:with-param name="toc-context" select="$toc-context"/>
320 </xsl:call-template>
321 </xsl:if>
322</xsl:template>
323
324<xsl:template match="part|reference" mode="toc">
325 <xsl:param name="toc-context" select="."/>
326
327 <xsl:call-template name="subtoc">
328 <xsl:with-param name="toc-context" select="$toc-context"/>
329 <xsl:with-param name="nodes" select="appendix|chapter|article
330 |index|glossary|bibliography
331 |preface|reference|refentry
332 |bridgehead[$bridgehead.in.toc != 0]"/>
333 </xsl:call-template>
334</xsl:template>
335
336<xsl:template match="preface|chapter|appendix|article" mode="toc">
337 <xsl:param name="toc-context" select="."/>
338
339 <xsl:call-template name="subtoc">
340 <xsl:with-param name="toc-context" select="$toc-context"/>
341 <xsl:with-param name="nodes" select="section|sect1
342 |simplesect[$simplesect.in.toc != 0]
343 |refentry
344 |glossary|bibliography|index
345 |bridgehead[$bridgehead.in.toc != 0]"/>
346 </xsl:call-template>
347</xsl:template>
348
349<xsl:template match="sect1" mode="toc">
350 <xsl:param name="toc-context" select="."/>
351 <xsl:call-template name="subtoc">
352 <xsl:with-param name="toc-context" select="$toc-context"/>
353 <xsl:with-param name="nodes" select="sect2
354 |bridgehead[$bridgehead.in.toc != 0]"/>
355 </xsl:call-template>
356</xsl:template>
357
358<xsl:template match="sect2" mode="toc">
359 <xsl:param name="toc-context" select="."/>
360
361 <xsl:call-template name="subtoc">
362 <xsl:with-param name="toc-context" select="$toc-context"/>
363 <xsl:with-param name="nodes" select="sect3
364 |bridgehead[$bridgehead.in.toc != 0]"/>
365 </xsl:call-template>
366</xsl:template>
367
368<xsl:template match="sect3" mode="toc">
369 <xsl:param name="toc-context" select="."/>
370
371 <xsl:call-template name="subtoc">
372 <xsl:with-param name="toc-context" select="$toc-context"/>
373 <xsl:with-param name="nodes" select="sect4
374 |bridgehead[$bridgehead.in.toc != 0]"/>
375 </xsl:call-template>
376</xsl:template>
377
378<xsl:template match="sect4" mode="toc">
379 <xsl:param name="toc-context" select="."/>
380
381 <xsl:call-template name="subtoc">
382 <xsl:with-param name="toc-context" select="$toc-context"/>
383 <xsl:with-param name="nodes" select="sect5
384 |bridgehead[$bridgehead.in.toc != 0]"/>
385 </xsl:call-template>
386</xsl:template>
387
388<xsl:template match="sect5" mode="toc">
389 <xsl:param name="toc-context" select="."/>
390
391 <xsl:call-template name="subtoc">
392 <xsl:with-param name="toc-context" select="$toc-context"/>
393 </xsl:call-template>
394</xsl:template>
395
396<xsl:template match="simplesect" mode="toc">
397 <xsl:param name="toc-context" select="."/>
398
399 <xsl:call-template name="subtoc">
400 <xsl:with-param name="toc-context" select="$toc-context"/>
401 </xsl:call-template>
402</xsl:template>
403
404<xsl:template match="section" mode="toc">
405 <xsl:param name="toc-context" select="."/>
406
407 <xsl:call-template name="subtoc">
408 <xsl:with-param name="toc-context" select="$toc-context"/>
409 <xsl:with-param name="nodes" select="section
410 |bridgehead[$bridgehead.in.toc != 0]"/>
411 </xsl:call-template>
412</xsl:template>
413
414<xsl:template match="bridgehead" mode="toc">
415 <xsl:param name="toc-context" select="."/>
416
417 <xsl:if test="$bridgehead.in.toc != 0">
418 <xsl:call-template name="subtoc">
419 <xsl:with-param name="toc-context" select="$toc-context"/>
420 </xsl:call-template>
421 </xsl:if>
422</xsl:template>
423
424<xsl:template match="bibliography|glossary" mode="toc">
425 <xsl:param name="toc-context" select="."/>
426
427 <xsl:call-template name="subtoc">
428 <xsl:with-param name="toc-context" select="$toc-context"/>
429 </xsl:call-template>
430</xsl:template>
431
432<xsl:template match="index" mode="toc">
433 <xsl:param name="toc-context" select="."/>
434
435 <!-- If the index tag is not empty, it should be it in the TOC -->
436 <xsl:if test="* or $generate.index != 0">
437 <xsl:call-template name="subtoc">
438 <xsl:with-param name="toc-context" select="$toc-context"/>
439 </xsl:call-template>
440 </xsl:if>
441</xsl:template>
442
443<xsl:template match="refentry" mode="toc">
444 <xsl:param name="toc-context" select="."/>
445
446 <xsl:variable name="refmeta" select=".//refmeta"/>
447 <xsl:variable name="refentrytitle" select="$refmeta//refentrytitle"/>
448 <xsl:variable name="refnamediv" select=".//refnamediv"/>
449 <xsl:variable name="refname" select="$refnamediv//refname"/>
450 <xsl:variable name="refdesc" select="$refnamediv//refdescriptor"/>
451 <xsl:variable name="title">
452 <xsl:choose>
453 <xsl:when test="$refentrytitle">
454 <xsl:apply-templates select="$refentrytitle[1]"
455 mode="titleabbrev.markup"/>
456 </xsl:when>
457 <xsl:when test="$refdesc">
458 <xsl:apply-templates select="$refdesc"
459 mode="titleabbrev.markup"/>
460 </xsl:when>
461 <xsl:when test="$refname">
462 <xsl:apply-templates select="$refname[1]"
463 mode="titleabbrev.markup"/>
464 </xsl:when>
465 </xsl:choose>
466 </xsl:variable>
467
468 <xsl:element name="{$toc.listitem.type}">
469 <span class='refentrytitle'>
470 <a>
471 <xsl:attribute name="href">
472 <xsl:call-template name="href.target"/>
473 </xsl:attribute>
474 <xsl:copy-of select="$title"/>
475 </a>
476 </span>
477 <span class='refpurpose'>
478 <xsl:if test="$annotate.toc != 0">
479 <xsl:text> - </xsl:text>
480 <xsl:value-of select="refnamediv/refpurpose"/>
481 </xsl:if>
482 </span>
483 </xsl:element>
484</xsl:template>
485
486<xsl:template match="title" mode="toc">
487 <xsl:param name="toc-context" select="."/>
488
489 <a>
490 <xsl:attribute name="href">
491 <xsl:call-template name="href.target">
492 <xsl:with-param name="object" select=".."/>
493 </xsl:call-template>
494 </xsl:attribute>
495 <xsl:apply-templates/>
496 </a>
497</xsl:template>
498
499<xsl:template name="manual-toc">
500 <xsl:param name="toc-context" select="."/>
501 <xsl:param name="tocentry"/>
502
503 <!-- be careful, we don't want to change the current document to the other tree! -->
504
505 <xsl:if test="$tocentry">
506 <xsl:variable name="node" select="key('id', $tocentry/@linkend)"/>
507
508 <xsl:element name="{$toc.listitem.type}">
509 <xsl:variable name="label">
510 <xsl:apply-templates select="$node" mode="label.markup"/>
511 </xsl:variable>
512 <xsl:copy-of select="$label"/>
513 <xsl:if test="$label != ''">
514 <xsl:value-of select="$autotoc.label.separator"/>
515 </xsl:if>
516 <a>
517 <xsl:attribute name="href">
518 <xsl:call-template name="href.target">
519 <xsl:with-param name="object" select="$node"/>
520 </xsl:call-template>
521 </xsl:attribute>
522 <xsl:apply-templates select="$node" mode="titleabbrev.markup"/>
523 </a>
524 </xsl:element>
525
526 <xsl:if test="$tocentry/*">
527 <xsl:element name="{$toc.list.type}">
528 <xsl:call-template name="manual-toc">
529 <xsl:with-param name="tocentry" select="$tocentry/*[1]"/>
530 </xsl:call-template>
531 </xsl:element>
532 </xsl:if>
533
534 <xsl:if test="$tocentry/following-sibling::*">
535 <xsl:call-template name="manual-toc">
536 <xsl:with-param name="tocentry" select="$tocentry/following-sibling::*[1]"/>
537 </xsl:call-template>
538 </xsl:if>
539 </xsl:if>
540</xsl:template>
541
542<!-- ==================================================================== -->
543
544<xsl:template name="list.of.titles">
545 <xsl:param name="toc-context" select="."/>
546 <xsl:param name="titles" select="'table'"/>
547 <xsl:param name="nodes" select=".//table"/>
548
549 <xsl:if test="$nodes">
550 <div class="list-of-{$titles}s">
551 <p>
552 <b>
553 <xsl:call-template name="gentext">
554 <xsl:with-param name="key">
555 <xsl:choose>
556 <xsl:when test="$titles='table'">ListofTables</xsl:when>
557 <xsl:when test="$titles='figure'">ListofFigures</xsl:when>
558 <xsl:when test="$titles='equation'">ListofEquations</xsl:when>
559 <xsl:when test="$titles='example'">ListofExamples</xsl:when>
560 <xsl:when test="$titles='procedure'">ListofProcedures</xsl:when>
561 <xsl:otherwise>ListofUnknown</xsl:otherwise>
562 </xsl:choose>
563 </xsl:with-param>
564 </xsl:call-template>
565 </b>
566 </p>
567
568 <xsl:element name="{$toc.list.type}">
569 <xsl:apply-templates select="$nodes" mode="toc">
570 <xsl:with-param name="toc-context" select="$toc-context"/>
571 </xsl:apply-templates>
572 </xsl:element>
573 </div>
574 </xsl:if>
575</xsl:template>
576
577<xsl:template match="figure|table|example|equation|procedure" mode="toc">
578 <xsl:param name="toc-context" select="."/>
579
580 <xsl:element name="{$toc.listitem.type}">
581 <xsl:variable name="label">
582 <xsl:apply-templates select="." mode="label.markup"/>
583 </xsl:variable>
584 <xsl:copy-of select="$label"/>
585 <xsl:if test="$label != ''">
586 <xsl:value-of select="$autotoc.label.separator"/>
587 </xsl:if>
588 <a>
589 <xsl:attribute name="href">
590 <xsl:call-template name="href.target"/>
591 </xsl:attribute>
592 <xsl:apply-templates select="." mode="titleabbrev.markup"/>
593 </a>
594 </xsl:element>
595</xsl:template>
596
597</xsl:stylesheet>
598
Note: See TracBrowser for help on using the repository browser.