1 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
4 exclude-result-prefixes="doc">
6 <!-- ********************************************************************
7 $Id: chunktoc.xsl 8399 2009-04-08 07:37:42Z 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 <xsl:import href="docbook.xsl"/>
19 <xsl:import href="chunk-common.xsl"/>
21 <xsl:template name="chunk">
22 <xsl:param name="node" select="."/>
23 <!-- returns 1 if $node is a chunk -->
25 <xsl:variable name="id">
26 <xsl:call-template name="object.id">
27 <xsl:with-param name="object" select="$node"/>
31 <xsl:variable name="chunks" select="document($chunk.toc,/)"/>
34 <xsl:when test="$chunks//tocentry[@linkend=$id]">1</xsl:when>
35 <xsl:otherwise>0</xsl:otherwise>
39 <!-- ==================================================================== -->
41 <xsl:template match="*" mode="chunk-filename">
42 <!-- returns the filename of a chunk -->
44 <xsl:variable name="id">
45 <xsl:call-template name="object.id"/>
48 <xsl:variable name="chunks" select="document($chunk.toc,/)"/>
50 <xsl:variable name="chunk" select="$chunks//tocentry[@linkend=$id]"/>
51 <xsl:variable name="filename">
52 <xsl:call-template name="pi.dbhtml_filename">
53 <xsl:with-param name="node" select="$chunk"/>
58 <xsl:when test="$chunk">
59 <xsl:value-of select="$filename"/>
62 <xsl:apply-templates select="parent::*" mode="chunk-filename"/>
67 <!-- ==================================================================== -->
69 <xsl:template name="process-chunk">
70 <xsl:variable name="id">
71 <xsl:call-template name="object.id"/>
74 <xsl:variable name="chunks" select="document($chunk.toc,/)"/>
76 <xsl:variable name="chunk" select="$chunks//tocentry[@linkend=$id]"/>
77 <xsl:variable name="prev-id"
78 select="($chunk/preceding::tocentry
79 |$chunk/ancestor::tocentry)[last()]/@linkend"/>
80 <xsl:variable name="next-id"
81 select="($chunk/following::tocentry
82 |$chunk/child::tocentry)[1]/@linkend"/>
84 <xsl:variable name="prev" select="key('id',$prev-id)"/>
85 <xsl:variable name="next" select="key('id',$next-id)"/>
87 <xsl:variable name="ischunk">
88 <xsl:call-template name="chunk"/>
91 <xsl:variable name="chunkfn">
92 <xsl:if test="$ischunk='1'">
93 <xsl:apply-templates mode="chunk-filename" select="."/>
97 <xsl:variable name="filename">
98 <xsl:call-template name="make-relative-filename">
99 <xsl:with-param name="base.dir" select="$base.dir"/>
100 <xsl:with-param name="base.name" select="$chunkfn"/>
105 <xsl:when test="$ischunk = 0">
110 <xsl:call-template name="write.chunk">
111 <xsl:with-param name="filename" select="$filename"/>
112 <xsl:with-param name="content">
113 <xsl:call-template name="chunk-element-content">
114 <xsl:with-param name="prev" select="$prev"/>
115 <xsl:with-param name="next" select="$next"/>
118 <xsl:with-param name="quiet" select="$chunk.quietly"/>
124 <!-- ==================================================================== -->
126 <xsl:template match="set">
127 <xsl:call-template name="process-chunk"/>
130 <xsl:template match="book">
131 <xsl:call-template name="process-chunk"/>
134 <xsl:template match="book/appendix">
135 <xsl:call-template name="process-chunk"/>
138 <xsl:template match="book/glossary">
139 <xsl:call-template name="process-chunk"/>
142 <xsl:template match="book/bibliography">
143 <xsl:call-template name="process-chunk"/>
146 <xsl:template match="dedication" mode="dedication">
147 <xsl:call-template name="process-chunk"/>
150 <xsl:template match="preface|chapter">
151 <xsl:call-template name="process-chunk"/>
154 <xsl:template match="part|reference">
155 <xsl:call-template name="process-chunk"/>
158 <xsl:template match="refentry">
159 <xsl:call-template name="process-chunk"/>
162 <xsl:template match="colophon">
163 <xsl:call-template name="process-chunk"/>
166 <xsl:template match="article">
167 <xsl:call-template name="process-chunk"/>
170 <xsl:template match="article/appendix">
171 <xsl:call-template name="process-chunk"/>
174 <xsl:template match="article/glossary">
175 <xsl:call-template name="process-chunk"/>
178 <xsl:template match="article/bibliography">
179 <xsl:call-template name="process-chunk"/>
182 <xsl:template match="sect1|sect2|sect3|sect4|sect5|section">
183 <xsl:variable name="ischunk">
184 <xsl:call-template name="chunk"/>
188 <xsl:when test="$ischunk != 0">
189 <xsl:call-template name="process-chunk"/>
197 <xsl:template match="setindex
200 <!-- some implementations use completely empty index tags to indicate -->
201 <!-- where an automatically generated index should be inserted. so -->
202 <!-- if the index is completely empty, skip it. -->
203 <xsl:if test="count(*)>0 or $generate.index != '0'">
204 <xsl:call-template name="process-chunk"/>
208 <!-- ==================================================================== -->
210 <xsl:template match="/">
211 <!-- * Get a title for current doc so that we let the user -->
212 <!-- * know what document we are processing at this point. -->
213 <xsl:variable name="doc.title">
214 <xsl:call-template name="get.doc.title"/>
217 <xsl:when test="$chunk.toc = ''">
218 <xsl:message terminate="yes">
219 <xsl:text>The chunk.toc file is not set.</xsl:text>
222 <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
223 toss the namespace and continue. Use the docbook5 namespaced
224 stylesheets for DocBook5 if you don't want to use this feature.-->
225 <!-- include extra test for Xalan quirk -->
226 <xsl:when test="$exsl.node.set.available != 0
227 and (*/self::ng:* or */self::db:*)">
228 <xsl:call-template name="log.message">
229 <xsl:with-param name="level">Note</xsl:with-param>
230 <xsl:with-param name="source" select="$doc.title"/>
231 <xsl:with-param name="context-desc">
232 <xsl:text>namesp. cut</xsl:text>
234 <xsl:with-param name="message">
235 <xsl:text>stripped namespace before processing</xsl:text>
238 <xsl:variable name="nons">
239 <xsl:apply-templates mode="stripNS"/>
241 <xsl:call-template name="log.message">
242 <xsl:with-param name="level">Note</xsl:with-param>
243 <xsl:with-param name="source" select="$doc.title"/>
244 <xsl:with-param name="context-desc">
245 <xsl:text>namesp. cut</xsl:text>
247 <xsl:with-param name="message">
248 <xsl:text>processing stripped document</xsl:text>
251 <xsl:apply-templates select="exsl:node-set($nons)"/>
253 <!-- Can't process unless namespace removed -->
254 <xsl:when test="*/self::ng:* or */self::db:*">
255 <xsl:message terminate="yes">
256 <xsl:text>Unable to strip the namespace from DB5 document,</xsl:text>
257 <xsl:text> cannot proceed.</xsl:text>
262 <xsl:when test="$rootid != ''">
264 <xsl:when test="count(key('id',$rootid)) = 0">
265 <xsl:message terminate="yes">
266 <xsl:text>ID '</xsl:text>
267 <xsl:value-of select="$rootid"/>
268 <xsl:text>' not found in document.</xsl:text>
272 <xsl:if test="$collect.xref.targets = 'yes' or
273 $collect.xref.targets = 'only'">
274 <xsl:apply-templates select="key('id', $rootid)"
275 mode="collect.targets"/>
277 <xsl:if test="$collect.xref.targets != 'only'">
278 <xsl:apply-templates select="key('id',$rootid)"
279 mode="process.root"/>
280 <xsl:if test="$tex.math.in.alt != ''">
281 <xsl:apply-templates select="key('id',$rootid)"
282 mode="collect.tex.math"/>
284 <xsl:if test="$generate.manifest != 0">
285 <xsl:call-template name="generate.manifest">
286 <xsl:with-param name="node" select="key('id',$rootid)"/>
294 <xsl:if test="$collect.xref.targets = 'yes' or
295 $collect.xref.targets = 'only'">
296 <xsl:apply-templates select="/" mode="collect.targets"/>
298 <xsl:if test="$collect.xref.targets != 'only'">
299 <xsl:apply-templates select="/" mode="process.root"/>
300 <xsl:if test="$tex.math.in.alt != ''">
301 <xsl:apply-templates select="/" mode="collect.tex.math"/>
303 <xsl:if test="$generate.manifest != 0">
304 <xsl:call-template name="generate.manifest">
305 <xsl:with-param name="node" select="/"/>
315 <xsl:template match="*" mode="process.root">
316 <xsl:apply-templates select="."/>
319 <xsl:template name="make.lots">
320 <xsl:param name="toc.params" select="''"/>
321 <xsl:param name="toc"/>
323 <xsl:variable name="lots">
324 <xsl:if test="contains($toc.params, 'toc')">
325 <xsl:copy-of select="$toc"/>
328 <xsl:if test="contains($toc.params, 'figure')">
330 <xsl:when test="$chunk.separate.lots != '0'">
331 <xsl:call-template name="make.lot.chunk">
332 <xsl:with-param name="type" select="'figure'"/>
333 <xsl:with-param name="lot">
334 <xsl:call-template name="list.of.titles">
335 <xsl:with-param name="titles" select="'figure'"/>
336 <xsl:with-param name="nodes" select=".//figure"/>
342 <xsl:call-template name="list.of.titles">
343 <xsl:with-param name="titles" select="'figure'"/>
344 <xsl:with-param name="nodes" select=".//figure"/>
350 <xsl:if test="contains($toc.params, 'table')">
352 <xsl:when test="$chunk.separate.lots != '0'">
353 <xsl:call-template name="make.lot.chunk">
354 <xsl:with-param name="type" select="'table'"/>
355 <xsl:with-param name="lot">
356 <xsl:call-template name="list.of.titles">
357 <xsl:with-param name="titles" select="'table'"/>
358 <xsl:with-param name="nodes" select=".//table"/>
364 <xsl:call-template name="list.of.titles">
365 <xsl:with-param name="titles" select="'table'"/>
366 <xsl:with-param name="nodes" select=".//table"/>
372 <xsl:if test="contains($toc.params, 'example')">
374 <xsl:when test="$chunk.separate.lots != '0'">
375 <xsl:call-template name="make.lot.chunk">
376 <xsl:with-param name="type" select="'example'"/>
377 <xsl:with-param name="lot">
378 <xsl:call-template name="list.of.titles">
379 <xsl:with-param name="titles" select="'example'"/>
380 <xsl:with-param name="nodes" select=".//example"/>
386 <xsl:call-template name="list.of.titles">
387 <xsl:with-param name="titles" select="'example'"/>
388 <xsl:with-param name="nodes" select=".//example"/>
394 <xsl:if test="contains($toc.params, 'equation')">
396 <xsl:when test="$chunk.separate.lots != '0'">
397 <xsl:call-template name="make.lot.chunk">
398 <xsl:with-param name="type" select="'equation'"/>
399 <xsl:with-param name="lot">
400 <xsl:call-template name="list.of.titles">
401 <xsl:with-param name="titles" select="'equation'"/>
402 <xsl:with-param name="nodes" select=".//equation"/>
408 <xsl:call-template name="list.of.titles">
409 <xsl:with-param name="titles" select="'equation'"/>
410 <xsl:with-param name="nodes" select=".//equation"/>
416 <xsl:if test="contains($toc.params, 'procedure')">
418 <xsl:when test="$chunk.separate.lots != '0'">
419 <xsl:call-template name="make.lot.chunk">
420 <xsl:with-param name="type" select="'procedure'"/>
421 <xsl:with-param name="lot">
422 <xsl:call-template name="list.of.titles">
423 <xsl:with-param name="titles" select="'procedure'"/>
424 <xsl:with-param name="nodes" select=".//procedure[title]"/>
430 <xsl:call-template name="list.of.titles">
431 <xsl:with-param name="titles" select="'procedure'"/>
432 <xsl:with-param name="nodes" select=".//procedure[title]"/>
439 <xsl:if test="string($lots) != ''">
441 <xsl:when test="$chunk.tocs.and.lots != 0 and not(parent::*)">
442 <xsl:call-template name="write.chunk">
443 <xsl:with-param name="filename">
444 <xsl:call-template name="make-relative-filename">
445 <xsl:with-param name="base.dir" select="$base.dir"/>
446 <xsl:with-param name="base.name">
447 <xsl:call-template name="dbhtml-dir"/>
448 <xsl:apply-templates select="." mode="recursive-chunk-filename">
449 <xsl:with-param name="recursive" select="true()"/>
450 </xsl:apply-templates>
451 <xsl:text>-toc</xsl:text>
452 <xsl:value-of select="$html.ext"/>
456 <xsl:with-param name="content">
457 <xsl:call-template name="chunk-element-content">
458 <xsl:with-param name="prev" select="/foo"/>
459 <xsl:with-param name="next" select="/foo"/>
460 <xsl:with-param name="nav.context" select="'toc'"/>
461 <xsl:with-param name="content">
463 <xsl:apply-templates select="." mode="object.title.markup"/>
465 <xsl:copy-of select="$lots"/>
469 <xsl:with-param name="quiet" select="$chunk.quietly"/>
473 <xsl:copy-of select="$lots"/>
479 <xsl:template name="make.lot.chunk">
480 <xsl:param name="type" select="''"/>
481 <xsl:param name="lot"/>
483 <xsl:if test="string($lot) != ''">
484 <xsl:variable name="filename">
485 <xsl:call-template name="make-relative-filename">
486 <xsl:with-param name="base.dir" select="$base.dir"/>
487 <xsl:with-param name="base.name">
488 <xsl:call-template name="dbhtml-dir"/>
489 <xsl:value-of select="$type"/>
490 <xsl:text>-toc</xsl:text>
491 <xsl:value-of select="$html.ext"/>
496 <xsl:variable name="href">
497 <xsl:call-template name="make-relative-filename">
498 <xsl:with-param name="base.name">
499 <xsl:call-template name="dbhtml-dir"/>
500 <xsl:value-of select="$type"/>
501 <xsl:text>-toc</xsl:text>
502 <xsl:value-of select="$html.ext"/>
507 <xsl:call-template name="write.chunk">
508 <xsl:with-param name="filename" select="$filename"/>
509 <xsl:with-param name="content">
510 <xsl:call-template name="chunk-element-content">
511 <xsl:with-param name="prev" select="/foo"/>
512 <xsl:with-param name="next" select="/foo"/>
513 <xsl:with-param name="nav.context" select="'toc'"/>
514 <xsl:with-param name="content">
515 <xsl:copy-of select="$lot"/>
519 <xsl:with-param name="quiet" select="$chunk.quietly"/>
521 <!-- And output a link to this file -->
523 <xsl:attribute name="class">
524 <xsl:text>ListofTitles</xsl:text>
527 <xsl:call-template name="gentext">
528 <xsl:with-param name="key">
530 <xsl:when test="$type='table'">ListofTables</xsl:when>
531 <xsl:when test="$type='figure'">ListofFigures</xsl:when>
532 <xsl:when test="$type='equation'">ListofEquations</xsl:when>
533 <xsl:when test="$type='example'">ListofExamples</xsl:when>
534 <xsl:when test="$type='procedure'">ListofProcedures</xsl:when>
535 <xsl:otherwise>ListofUnknown</xsl:otherwise>