1 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
3 xmlns:exsl="http://exslt.org/common"
4 xmlns:ng="http://docbook.org/docbook-ng"
5 xmlns:db="http://docbook.org/ns/docbook"
7 exclude-result-prefixes="doc exsl ng db">
9 <!-- ********************************************************************
10 $Id: chunktoc.xsl 8545 2009-12-02 07:22:10Z bobstayton $
11 ********************************************************************
13 This file is part of the XSL DocBook Stylesheet distribution.
14 See ../README or http://docbook.sf.net/release/xsl/current/ for
15 copyright and other information.
17 ******************************************************************** -->
19 <!-- ==================================================================== -->
21 <xsl:import href="docbook.xsl"/>
22 <xsl:import href="chunk-common.xsl"/>
24 <xsl:template name="chunk">
25 <xsl:param name="node" select="."/>
26 <!-- returns 1 if $node is a chunk -->
28 <xsl:variable name="id">
29 <xsl:call-template name="object.id">
30 <xsl:with-param name="object" select="$node"/>
34 <xsl:variable name="chunks" select="document($chunk.toc,/)"/>
37 <xsl:when test="$chunks//tocentry[@linkend=$id]">1</xsl:when>
38 <xsl:otherwise>0</xsl:otherwise>
42 <!-- ==================================================================== -->
44 <xsl:template match="*" mode="chunk-filename">
45 <!-- returns the filename of a chunk -->
47 <xsl:variable name="id">
48 <xsl:call-template name="object.id"/>
51 <xsl:variable name="chunks" select="document($chunk.toc,/)"/>
53 <xsl:variable name="chunk" select="$chunks//tocentry[@linkend=$id]"/>
54 <xsl:variable name="filename">
55 <xsl:call-template name="pi.dbhtml_filename">
56 <xsl:with-param name="node" select="$chunk"/>
61 <xsl:when test="$chunk">
62 <xsl:value-of select="$filename"/>
65 <xsl:apply-templates select="parent::*" mode="chunk-filename"/>
70 <!-- ==================================================================== -->
72 <xsl:template name="process-chunk">
73 <xsl:variable name="id">
74 <xsl:call-template name="object.id"/>
77 <xsl:variable name="chunks" select="document($chunk.toc,/)"/>
79 <xsl:variable name="chunk" select="$chunks//tocentry[@linkend=$id]"/>
80 <xsl:variable name="prev-id"
81 select="($chunk/preceding::tocentry
82 |$chunk/ancestor::tocentry)[last()]/@linkend"/>
83 <xsl:variable name="next-id"
84 select="($chunk/following::tocentry
85 |$chunk/child::tocentry)[1]/@linkend"/>
87 <xsl:variable name="prev" select="key('id',$prev-id)"/>
88 <xsl:variable name="next" select="key('id',$next-id)"/>
90 <xsl:variable name="ischunk">
91 <xsl:call-template name="chunk"/>
94 <xsl:variable name="chunkfn">
95 <xsl:if test="$ischunk='1'">
96 <xsl:apply-templates mode="chunk-filename" select="."/>
100 <xsl:variable name="filename">
101 <xsl:call-template name="make-relative-filename">
102 <xsl:with-param name="base.dir" select="$base.dir"/>
103 <xsl:with-param name="base.name" select="$chunkfn"/>
108 <xsl:when test="$ischunk = 0">
113 <xsl:call-template name="write.chunk">
114 <xsl:with-param name="filename" select="$filename"/>
115 <xsl:with-param name="content">
116 <xsl:call-template name="chunk-element-content">
117 <xsl:with-param name="prev" select="$prev"/>
118 <xsl:with-param name="next" select="$next"/>
121 <xsl:with-param name="quiet" select="$chunk.quietly"/>
127 <!-- ==================================================================== -->
129 <xsl:template match="set">
130 <xsl:call-template name="process-chunk"/>
133 <xsl:template match="book">
134 <xsl:call-template name="process-chunk"/>
137 <xsl:template match="appendix">
138 <xsl:call-template name="process-chunk"/>
141 <xsl:template match="book/glossary">
142 <xsl:call-template name="process-chunk"/>
145 <xsl:template match="book/bibliography">
146 <xsl:call-template name="process-chunk"/>
149 <xsl:template match="dedication" mode="dedication">
150 <xsl:call-template name="process-chunk"/>
153 <xsl:template match="preface|chapter">
154 <xsl:call-template name="process-chunk"/>
157 <xsl:template match="part|reference">
158 <xsl:call-template name="process-chunk"/>
161 <xsl:template match="refentry">
162 <xsl:call-template name="process-chunk"/>
165 <xsl:template match="colophon">
166 <xsl:call-template name="process-chunk"/>
169 <xsl:template match="article">
170 <xsl:call-template name="process-chunk"/>
173 <xsl:template match="article/glossary">
174 <xsl:call-template name="process-chunk"/>
177 <xsl:template match="article/bibliography">
178 <xsl:call-template name="process-chunk"/>
181 <xsl:template match="sect1|sect2|sect3|sect4|sect5|section">
182 <xsl:variable name="ischunk">
183 <xsl:call-template name="chunk"/>
187 <xsl:when test="$ischunk != 0">
188 <xsl:call-template name="process-chunk"/>
196 <xsl:template match="setindex
199 <!-- some implementations use completely empty index tags to indicate -->
200 <!-- where an automatically generated index should be inserted. so -->
201 <!-- if the index is completely empty, skip it. -->
202 <xsl:if test="count(*)>0 or $generate.index != '0'">
203 <xsl:call-template name="process-chunk"/>
207 <!-- ==================================================================== -->
209 <xsl:template match="/">
210 <!-- * Get a title for current doc so that we let the user -->
211 <!-- * know what document we are processing at this point. -->
212 <xsl:variable name="doc.title">
213 <xsl:call-template name="get.doc.title"/>
216 <xsl:when test="$chunk.toc = ''">
217 <xsl:message terminate="yes">
218 <xsl:text>The chunk.toc file is not set.</xsl:text>
221 <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
222 toss the namespace and continue. Use the docbook5 namespaced
223 stylesheets for DocBook5 if you don't want to use this feature.-->
224 <!-- include extra test for Xalan quirk -->
225 <xsl:when test="$exsl.node.set.available != 0
226 and (*/self::ng:* or */self::db:*)">
227 <xsl:call-template name="log.message">
228 <xsl:with-param name="level">Note</xsl:with-param>
229 <xsl:with-param name="source" select="$doc.title"/>
230 <xsl:with-param name="context-desc">
231 <xsl:text>namesp. cut</xsl:text>
233 <xsl:with-param name="message">
234 <xsl:text>stripped namespace before processing</xsl:text>
237 <xsl:variable name="nons">
238 <xsl:apply-templates mode="stripNS"/>
240 <xsl:call-template name="log.message">
241 <xsl:with-param name="level">Note</xsl:with-param>
242 <xsl:with-param name="source" select="$doc.title"/>
243 <xsl:with-param name="context-desc">
244 <xsl:text>namesp. cut</xsl:text>
246 <xsl:with-param name="message">
247 <xsl:text>processing stripped document</xsl:text>
250 <xsl:apply-templates select="exsl:node-set($nons)"/>
252 <!-- Can't process unless namespace removed -->
253 <xsl:when test="*/self::ng:* or */self::db:*">
254 <xsl:message terminate="yes">
255 <xsl:text>Unable to strip the namespace from DB5 document,</xsl:text>
256 <xsl:text> cannot proceed.</xsl:text>
261 <xsl:when test="$rootid != ''">
263 <xsl:when test="count(key('id',$rootid)) = 0">
264 <xsl:message terminate="yes">
265 <xsl:text>ID '</xsl:text>
266 <xsl:value-of select="$rootid"/>
267 <xsl:text>' not found in document.</xsl:text>
271 <xsl:if test="$collect.xref.targets = 'yes' or
272 $collect.xref.targets = 'only'">
273 <xsl:apply-templates select="key('id', $rootid)"
274 mode="collect.targets"/>
276 <xsl:if test="$collect.xref.targets != 'only'">
277 <xsl:apply-templates select="key('id',$rootid)"
278 mode="process.root"/>
279 <xsl:if test="$tex.math.in.alt != ''">
280 <xsl:apply-templates select="key('id',$rootid)"
281 mode="collect.tex.math"/>
283 <xsl:if test="$generate.manifest != 0">
284 <xsl:call-template name="generate.manifest">
285 <xsl:with-param name="node" select="key('id',$rootid)"/>
293 <xsl:if test="$collect.xref.targets = 'yes' or
294 $collect.xref.targets = 'only'">
295 <xsl:apply-templates select="/" mode="collect.targets"/>
297 <xsl:if test="$collect.xref.targets != 'only'">
298 <xsl:apply-templates select="/" mode="process.root"/>
299 <xsl:if test="$tex.math.in.alt != ''">
300 <xsl:apply-templates select="/" mode="collect.tex.math"/>
302 <xsl:if test="$generate.manifest != 0">
303 <xsl:call-template name="generate.manifest">
304 <xsl:with-param name="node" select="/"/>
314 <xsl:template match="*" mode="process.root">
315 <xsl:apply-templates select="."/>
318 <xsl:template name="make.lots">
319 <xsl:param name="toc.params" select="''"/>
320 <xsl:param name="toc"/>
322 <xsl:variable name="lots">
323 <xsl:if test="contains($toc.params, 'toc')">
324 <xsl:copy-of select="$toc"/>
327 <xsl:if test="contains($toc.params, 'figure')">
329 <xsl:when test="$chunk.separate.lots != '0'">
330 <xsl:call-template name="make.lot.chunk">
331 <xsl:with-param name="type" select="'figure'"/>
332 <xsl:with-param name="lot">
333 <xsl:call-template name="list.of.titles">
334 <xsl:with-param name="titles" select="'figure'"/>
335 <xsl:with-param name="nodes" select=".//figure"/>
341 <xsl:call-template name="list.of.titles">
342 <xsl:with-param name="titles" select="'figure'"/>
343 <xsl:with-param name="nodes" select=".//figure"/>
349 <xsl:if test="contains($toc.params, 'table')">
351 <xsl:when test="$chunk.separate.lots != '0'">
352 <xsl:call-template name="make.lot.chunk">
353 <xsl:with-param name="type" select="'table'"/>
354 <xsl:with-param name="lot">
355 <xsl:call-template name="list.of.titles">
356 <xsl:with-param name="titles" select="'table'"/>
357 <xsl:with-param name="nodes" select=".//table"/>
363 <xsl:call-template name="list.of.titles">
364 <xsl:with-param name="titles" select="'table'"/>
365 <xsl:with-param name="nodes" select=".//table"/>
371 <xsl:if test="contains($toc.params, 'example')">
373 <xsl:when test="$chunk.separate.lots != '0'">
374 <xsl:call-template name="make.lot.chunk">
375 <xsl:with-param name="type" select="'example'"/>
376 <xsl:with-param name="lot">
377 <xsl:call-template name="list.of.titles">
378 <xsl:with-param name="titles" select="'example'"/>
379 <xsl:with-param name="nodes" select=".//example"/>
385 <xsl:call-template name="list.of.titles">
386 <xsl:with-param name="titles" select="'example'"/>
387 <xsl:with-param name="nodes" select=".//example"/>
393 <xsl:if test="contains($toc.params, 'equation')">
395 <xsl:when test="$chunk.separate.lots != '0'">
396 <xsl:call-template name="make.lot.chunk">
397 <xsl:with-param name="type" select="'equation'"/>
398 <xsl:with-param name="lot">
399 <xsl:call-template name="list.of.titles">
400 <xsl:with-param name="titles" select="'equation'"/>
401 <xsl:with-param name="nodes" select=".//equation"/>
407 <xsl:call-template name="list.of.titles">
408 <xsl:with-param name="titles" select="'equation'"/>
409 <xsl:with-param name="nodes" select=".//equation"/>
415 <xsl:if test="contains($toc.params, 'procedure')">
417 <xsl:when test="$chunk.separate.lots != '0'">
418 <xsl:call-template name="make.lot.chunk">
419 <xsl:with-param name="type" select="'procedure'"/>
420 <xsl:with-param name="lot">
421 <xsl:call-template name="list.of.titles">
422 <xsl:with-param name="titles" select="'procedure'"/>
423 <xsl:with-param name="nodes" select=".//procedure[title]"/>
429 <xsl:call-template name="list.of.titles">
430 <xsl:with-param name="titles" select="'procedure'"/>
431 <xsl:with-param name="nodes" select=".//procedure[title]"/>
438 <xsl:if test="string($lots) != ''">
440 <xsl:when test="$chunk.tocs.and.lots != 0 and not(parent::*)">
441 <xsl:call-template name="write.chunk">
442 <xsl:with-param name="filename">
443 <xsl:call-template name="make-relative-filename">
444 <xsl:with-param name="base.dir" select="$base.dir"/>
445 <xsl:with-param name="base.name">
446 <xsl:call-template name="dbhtml-dir"/>
447 <xsl:apply-templates select="." mode="recursive-chunk-filename">
448 <xsl:with-param name="recursive" select="true()"/>
449 </xsl:apply-templates>
450 <xsl:text>-toc</xsl:text>
451 <xsl:value-of select="$html.ext"/>
455 <xsl:with-param name="content">
456 <xsl:call-template name="chunk-element-content">
457 <xsl:with-param name="prev" select="/foo"/>
458 <xsl:with-param name="next" select="/foo"/>
459 <xsl:with-param name="nav.context" select="'toc'"/>
460 <xsl:with-param name="content">
462 <xsl:apply-templates select="." mode="object.title.markup"/>
464 <xsl:copy-of select="$lots"/>
468 <xsl:with-param name="quiet" select="$chunk.quietly"/>
472 <xsl:copy-of select="$lots"/>
478 <xsl:template name="make.lot.chunk">
479 <xsl:param name="type" select="''"/>
480 <xsl:param name="lot"/>
482 <xsl:if test="string($lot) != ''">
483 <xsl:variable name="filename">
484 <xsl:call-template name="make-relative-filename">
485 <xsl:with-param name="base.dir" select="$base.dir"/>
486 <xsl:with-param name="base.name">
487 <xsl:call-template name="dbhtml-dir"/>
488 <xsl:value-of select="$type"/>
489 <xsl:text>-toc</xsl:text>
490 <xsl:value-of select="$html.ext"/>
495 <xsl:variable name="href">
496 <xsl:call-template name="make-relative-filename">
497 <xsl:with-param name="base.name">
498 <xsl:call-template name="dbhtml-dir"/>
499 <xsl:value-of select="$type"/>
500 <xsl:text>-toc</xsl:text>
501 <xsl:value-of select="$html.ext"/>
506 <xsl:call-template name="write.chunk">
507 <xsl:with-param name="filename" select="$filename"/>
508 <xsl:with-param name="content">
509 <xsl:call-template name="chunk-element-content">
510 <xsl:with-param name="prev" select="/foo"/>
511 <xsl:with-param name="next" select="/foo"/>
512 <xsl:with-param name="nav.context" select="'toc'"/>
513 <xsl:with-param name="content">
514 <xsl:copy-of select="$lot"/>
518 <xsl:with-param name="quiet" select="$chunk.quietly"/>
520 <!-- And output a link to this file -->
522 <xsl:attribute name="class">
523 <xsl:text>ListofTitles</xsl:text>
526 <xsl:call-template name="gentext">
527 <xsl:with-param name="key">
529 <xsl:when test="$type='table'">ListofTables</xsl:when>
530 <xsl:when test="$type='figure'">ListofFigures</xsl:when>
531 <xsl:when test="$type='equation'">ListofEquations</xsl:when>
532 <xsl:when test="$type='example'">ListofExamples</xsl:when>
533 <xsl:when test="$type='procedure'">ListofProcedures</xsl:when>
534 <xsl:otherwise>ListofUnknown</xsl:otherwise>