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 9286 2012-04-19 10:10:58Z 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="$chunk.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="topic">
171 <xsl:call-template name="process-chunk"/>
174 <xsl:template match="article/appendix">
175 <xsl:call-template name="process-chunk"/>
178 <xsl:template match="article/glossary">
179 <xsl:call-template name="process-chunk"/>
182 <xsl:template match="article/bibliography">
183 <xsl:call-template name="process-chunk"/>
186 <xsl:template match="sect1|sect2|sect3|sect4|sect5|section">
187 <xsl:variable name="ischunk">
188 <xsl:call-template name="chunk"/>
192 <xsl:when test="$ischunk != 0">
193 <xsl:call-template name="process-chunk"/>
201 <xsl:template match="setindex
204 <!-- some implementations use completely empty index tags to indicate -->
205 <!-- where an automatically generated index should be inserted. so -->
206 <!-- if the index is completely empty, skip it. -->
207 <xsl:if test="count(*)>0 or $generate.index != '0'">
208 <xsl:call-template name="process-chunk"/>
212 <!-- ==================================================================== -->
214 <xsl:template match="/">
215 <!-- * Get a title for current doc so that we let the user -->
216 <!-- * know what document we are processing at this point. -->
217 <xsl:variable name="doc.title">
218 <xsl:call-template name="get.doc.title"/>
221 <xsl:when test="$chunk.toc = ''">
222 <xsl:message terminate="yes">
223 <xsl:text>The chunk.toc file is not set.</xsl:text>
226 <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
227 toss the namespace and continue. Use the docbook5 namespaced
228 stylesheets for DocBook5 if you don't want to use this feature.-->
229 <!-- include extra test for Xalan quirk -->
230 <xsl:when test="$exsl.node.set.available != 0
231 and (*/self::ng:* or */self::db:*)">
232 <xsl:call-template name="log.message">
233 <xsl:with-param name="level">Note</xsl:with-param>
234 <xsl:with-param name="source" select="$doc.title"/>
235 <xsl:with-param name="context-desc">
236 <xsl:text>namesp. cut</xsl:text>
238 <xsl:with-param name="message">
239 <xsl:text>stripped namespace before processing</xsl:text>
242 <xsl:variable name="nons">
243 <xsl:apply-templates mode="stripNS"/>
245 <xsl:call-template name="log.message">
246 <xsl:with-param name="level">Note</xsl:with-param>
247 <xsl:with-param name="source" select="$doc.title"/>
248 <xsl:with-param name="context-desc">
249 <xsl:text>namesp. cut</xsl:text>
251 <xsl:with-param name="message">
252 <xsl:text>processing stripped document</xsl:text>
255 <xsl:apply-templates select="exsl:node-set($nons)"/>
257 <!-- Can't process unless namespace removed -->
258 <xsl:when test="*/self::ng:* or */self::db:*">
259 <xsl:message terminate="yes">
260 <xsl:text>Unable to strip the namespace from DB5 document,</xsl:text>
261 <xsl:text> cannot proceed.</xsl:text>
266 <xsl:when test="$rootid != ''">
268 <xsl:when test="count(key('id',$rootid)) = 0">
269 <xsl:message terminate="yes">
270 <xsl:text>ID '</xsl:text>
271 <xsl:value-of select="$rootid"/>
272 <xsl:text>' not found in document.</xsl:text>
276 <xsl:if test="$collect.xref.targets = 'yes' or
277 $collect.xref.targets = 'only'">
278 <xsl:apply-templates select="key('id', $rootid)"
279 mode="collect.targets"/>
281 <xsl:if test="$collect.xref.targets != 'only'">
282 <xsl:apply-templates select="key('id',$rootid)"
283 mode="process.root"/>
284 <xsl:if test="$tex.math.in.alt != ''">
285 <xsl:apply-templates select="key('id',$rootid)"
286 mode="collect.tex.math"/>
288 <xsl:if test="$generate.manifest != 0">
289 <xsl:call-template name="generate.manifest">
290 <xsl:with-param name="node" select="key('id',$rootid)"/>
298 <xsl:if test="$collect.xref.targets = 'yes' or
299 $collect.xref.targets = 'only'">
300 <xsl:apply-templates select="/" mode="collect.targets"/>
302 <xsl:if test="$collect.xref.targets != 'only'">
303 <xsl:apply-templates select="/" mode="process.root"/>
304 <xsl:if test="$tex.math.in.alt != ''">
305 <xsl:apply-templates select="/" mode="collect.tex.math"/>
307 <xsl:if test="$generate.manifest != 0">
308 <xsl:call-template name="generate.manifest">
309 <xsl:with-param name="node" select="/"/>
319 <xsl:template match="*" mode="process.root">
320 <xsl:apply-templates select="."/>
321 <xsl:call-template name="generate.css"/>
324 <xsl:template name="make.lots">
325 <xsl:param name="toc.params" select="''"/>
326 <xsl:param name="toc"/>
328 <xsl:variable name="lots">
329 <xsl:if test="contains($toc.params, 'toc')">
330 <xsl:copy-of select="$toc"/>
333 <xsl:if test="contains($toc.params, 'figure')">
335 <xsl:when test="$chunk.separate.lots != '0'">
336 <xsl:call-template name="make.lot.chunk">
337 <xsl:with-param name="type" select="'figure'"/>
338 <xsl:with-param name="lot">
339 <xsl:call-template name="list.of.titles">
340 <xsl:with-param name="titles" select="'figure'"/>
341 <xsl:with-param name="nodes" select=".//figure"/>
347 <xsl:call-template name="list.of.titles">
348 <xsl:with-param name="titles" select="'figure'"/>
349 <xsl:with-param name="nodes" select=".//figure"/>
355 <xsl:if test="contains($toc.params, 'table')">
357 <xsl:when test="$chunk.separate.lots != '0'">
358 <xsl:call-template name="make.lot.chunk">
359 <xsl:with-param name="type" select="'table'"/>
360 <xsl:with-param name="lot">
361 <xsl:call-template name="list.of.titles">
362 <xsl:with-param name="titles" select="'table'"/>
363 <xsl:with-param name="nodes" select=".//table"/>
369 <xsl:call-template name="list.of.titles">
370 <xsl:with-param name="titles" select="'table'"/>
371 <xsl:with-param name="nodes" select=".//table"/>
377 <xsl:if test="contains($toc.params, 'example')">
379 <xsl:when test="$chunk.separate.lots != '0'">
380 <xsl:call-template name="make.lot.chunk">
381 <xsl:with-param name="type" select="'example'"/>
382 <xsl:with-param name="lot">
383 <xsl:call-template name="list.of.titles">
384 <xsl:with-param name="titles" select="'example'"/>
385 <xsl:with-param name="nodes" select=".//example"/>
391 <xsl:call-template name="list.of.titles">
392 <xsl:with-param name="titles" select="'example'"/>
393 <xsl:with-param name="nodes" select=".//example"/>
399 <xsl:if test="contains($toc.params, 'equation')">
401 <xsl:when test="$chunk.separate.lots != '0'">
402 <xsl:call-template name="make.lot.chunk">
403 <xsl:with-param name="type" select="'equation'"/>
404 <xsl:with-param name="lot">
405 <xsl:call-template name="list.of.titles">
406 <xsl:with-param name="titles" select="'equation'"/>
407 <xsl:with-param name="nodes" select=".//equation"/>
413 <xsl:call-template name="list.of.titles">
414 <xsl:with-param name="titles" select="'equation'"/>
415 <xsl:with-param name="nodes" select=".//equation"/>
421 <xsl:if test="contains($toc.params, 'procedure')">
423 <xsl:when test="$chunk.separate.lots != '0'">
424 <xsl:call-template name="make.lot.chunk">
425 <xsl:with-param name="type" select="'procedure'"/>
426 <xsl:with-param name="lot">
427 <xsl:call-template name="list.of.titles">
428 <xsl:with-param name="titles" select="'procedure'"/>
429 <xsl:with-param name="nodes" select=".//procedure[title]"/>
435 <xsl:call-template name="list.of.titles">
436 <xsl:with-param name="titles" select="'procedure'"/>
437 <xsl:with-param name="nodes" select=".//procedure[title]"/>
444 <xsl:if test="string($lots) != ''">
446 <xsl:when test="$chunk.tocs.and.lots != 0 and not(parent::*)">
447 <xsl:call-template name="write.chunk">
448 <xsl:with-param name="filename">
449 <xsl:call-template name="make-relative-filename">
450 <xsl:with-param name="base.dir" select="$chunk.base.dir"/>
451 <xsl:with-param name="base.name">
452 <xsl:call-template name="dbhtml-dir"/>
453 <xsl:apply-templates select="." mode="recursive-chunk-filename">
454 <xsl:with-param name="recursive" select="true()"/>
455 </xsl:apply-templates>
456 <xsl:text>-toc</xsl:text>
457 <xsl:value-of select="$html.ext"/>
461 <xsl:with-param name="content">
462 <xsl:call-template name="chunk-element-content">
463 <xsl:with-param name="prev" select="/foo"/>
464 <xsl:with-param name="next" select="/foo"/>
465 <xsl:with-param name="nav.context" select="'toc'"/>
466 <xsl:with-param name="content">
468 <xsl:apply-templates select="." mode="object.title.markup"/>
470 <xsl:copy-of select="$lots"/>
474 <xsl:with-param name="quiet" select="$chunk.quietly"/>
478 <xsl:copy-of select="$lots"/>
484 <xsl:template name="make.lot.chunk">
485 <xsl:param name="type" select="''"/>
486 <xsl:param name="lot"/>
488 <xsl:if test="string($lot) != ''">
489 <xsl:variable name="filename">
490 <xsl:call-template name="make-relative-filename">
491 <xsl:with-param name="base.dir" select="$chunk.base.dir"/>
492 <xsl:with-param name="base.name">
493 <xsl:call-template name="dbhtml-dir"/>
494 <xsl:value-of select="$type"/>
495 <xsl:text>-toc</xsl:text>
496 <xsl:value-of select="$html.ext"/>
501 <xsl:variable name="href">
502 <xsl:call-template name="make-relative-filename">
503 <xsl:with-param name="base.dir" select="''"/>
504 <xsl:with-param name="base.name">
505 <xsl:call-template name="dbhtml-dir"/>
506 <xsl:value-of select="$type"/>
507 <xsl:text>-toc</xsl:text>
508 <xsl:value-of select="$html.ext"/>
513 <xsl:call-template name="write.chunk">
514 <xsl:with-param name="filename" select="$filename"/>
515 <xsl:with-param name="content">
516 <xsl:call-template name="chunk-element-content">
517 <xsl:with-param name="prev" select="/foo"/>
518 <xsl:with-param name="next" select="/foo"/>
519 <xsl:with-param name="nav.context" select="'toc'"/>
520 <xsl:with-param name="content">
521 <xsl:copy-of select="$lot"/>
525 <xsl:with-param name="quiet" select="$chunk.quietly"/>
527 <!-- And output a link to this file -->
529 <xsl:attribute name="class">
530 <xsl:text>ListofTitles</xsl:text>
533 <xsl:call-template name="gentext">
534 <xsl:with-param name="key">
536 <xsl:when test="$type='table'">ListofTables</xsl:when>
537 <xsl:when test="$type='figure'">ListofFigures</xsl:when>
538 <xsl:when test="$type='equation'">ListofEquations</xsl:when>
539 <xsl:when test="$type='example'">ListofExamples</xsl:when>
540 <xsl:when test="$type='procedure'">ListofProcedures</xsl:when>
541 <xsl:otherwise>ListofUnknown</xsl:otherwise>