2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:exsl="http://exslt.org/common"
4 xmlns:cf="http://docbook.sourceforge.net/xmlns/chunkfast/1.0"
5 xmlns:ng="http://docbook.org/docbook-ng"
6 xmlns:db="http://docbook.org/ns/docbook"
7 exclude-result-prefixes="exsl cf ng db"
10 <!-- ********************************************************************
11 $Id: chunk-code.xsl 8345 2009-03-16 06:44:07Z bobstayton $
12 ********************************************************************
14 This file is part of the XSL DocBook Stylesheet distribution.
15 See ../README or http://docbook.sf.net/release/xsl/current/ for
16 copyright and other information.
18 ******************************************************************** -->
20 <!-- ==================================================================== -->
23 <xsl:template match="*" mode="chunk-filename">
24 <!-- returns the filename of a chunk -->
25 <xsl:variable name="ischunk">
26 <xsl:call-template name="chunk"/>
29 <xsl:variable name="fn">
30 <xsl:apply-templates select="." mode="recursive-chunk-filename"/>
35 <xsl:value-of select="$ischunk"/>
36 <xsl:text> (</xsl:text>
37 <xsl:value-of select="local-name(.)"/>
38 <xsl:text>) </xsl:text>
39 <xsl:value-of select="$fn"/>
40 <xsl:text>, </xsl:text>
41 <xsl:call-template name="dbhtml-dir"/>
45 <!-- 2003-11-25 by ndw:
46 The following test used to read test="$ischunk != 0 and $fn != ''"
47 I've removed the ischunk part of the test so that href.to.uri and
48 href.from.uri will be fully qualified even if the source or target
49 isn't a chunk. I *think* that if $fn != '' then it's appropriate
50 to put the directory on the front, even if the element isn't a
51 chunk. I could be wrong. -->
53 <xsl:if test="$fn != ''">
54 <xsl:call-template name="dbhtml-dir"/>
57 <xsl:value-of select="$fn"/>
58 <!-- You can't add the html.ext here because dbhtml filename= may already -->
59 <!-- have added it. It really does have to be handled in the recursive template -->
62 <xsl:template match="*" mode="recursive-chunk-filename">
63 <xsl:param name="recursive" select="false()"/>
65 <!-- returns the filename of a chunk -->
66 <xsl:variable name="ischunk">
67 <xsl:call-template name="chunk"/>
70 <xsl:variable name="dbhtml-filename">
71 <xsl:call-template name="pi.dbhtml_filename"/>
74 <xsl:variable name="filename">
76 <xsl:when test="$dbhtml-filename != ''">
77 <xsl:value-of select="$dbhtml-filename"/>
79 <!-- if this is the root element, use the root.filename -->
80 <xsl:when test="not(parent::*) and $root.filename != ''">
81 <xsl:value-of select="$root.filename"/>
82 <xsl:value-of select="$html.ext"/>
85 <xsl:when test="self::legalnotice and not($generate.legalnotice.link = 0)">
87 <xsl:when test="(@id or @xml:id) and not($use.id.as.filename = 0)">
88 <!-- * if this legalnotice has an ID, then go ahead and use -->
89 <!-- * just the value of that ID as the basename for the file -->
90 <!-- * (that is, without prepending an "ln-" too it) -->
91 <xsl:value-of select="(@id|@xml:id)[1]"/>
92 <xsl:value-of select="$html.ext"/>
95 <!-- * otherwise, if this legalnotice does not have an ID, -->
96 <!-- * then we generate an ID... -->
97 <xsl:variable name="id">
98 <xsl:call-template name="object.id"/>
100 <!-- * ...and then we take that generated ID, prepend an -->
101 <!-- * "ln-" to it, and use that as the basename for the file -->
102 <xsl:value-of select="concat('ln-',$id,$html.ext)"/>
106 <!-- if there's no dbhtml filename, and if we're to use IDs as -->
107 <!-- filenames, then use the ID to generate the filename. -->
108 <xsl:when test="(@id or @xml:id) and $use.id.as.filename != 0">
109 <xsl:value-of select="(@id|@xml:id)[1]"/>
110 <xsl:value-of select="$html.ext"/>
112 <xsl:otherwise></xsl:otherwise>
117 <xsl:when test="$ischunk='0'">
118 <!-- if called on something that isn't a chunk, walk up... -->
120 <xsl:when test="count(parent::*)>0">
121 <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
122 <xsl:with-param name="recursive" select="$recursive"/>
123 </xsl:apply-templates>
125 <!-- unless there is no up, in which case return "" -->
126 <xsl:otherwise></xsl:otherwise>
130 <xsl:when test="not($recursive) and $filename != ''">
131 <!-- if this chunk has an explicit name, use it -->
132 <xsl:value-of select="$filename"/>
135 <xsl:when test="self::set">
136 <xsl:value-of select="$root.filename"/>
137 <xsl:if test="not($recursive)">
138 <xsl:value-of select="$html.ext"/>
142 <xsl:when test="self::book">
143 <xsl:text>bk</xsl:text>
144 <xsl:number level="any" format="01"/>
145 <xsl:if test="not($recursive)">
146 <xsl:value-of select="$html.ext"/>
150 <xsl:when test="self::article">
152 <!-- in a set, make sure we inherit the right book info... -->
153 <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
154 <xsl:with-param name="recursive" select="true()"/>
155 </xsl:apply-templates>
158 <xsl:text>ar</xsl:text>
159 <xsl:number level="any" format="01" from="book"/>
160 <xsl:if test="not($recursive)">
161 <xsl:value-of select="$html.ext"/>
165 <xsl:when test="self::preface">
167 <!-- in a set, make sure we inherit the right book info... -->
168 <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
169 <xsl:with-param name="recursive" select="true()"/>
170 </xsl:apply-templates>
173 <xsl:text>pr</xsl:text>
174 <xsl:number level="any" format="01" from="book"/>
175 <xsl:if test="not($recursive)">
176 <xsl:value-of select="$html.ext"/>
180 <xsl:when test="self::chapter">
182 <!-- in a set, make sure we inherit the right book info... -->
183 <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
184 <xsl:with-param name="recursive" select="true()"/>
185 </xsl:apply-templates>
188 <xsl:text>ch</xsl:text>
189 <xsl:number level="any" format="01" from="book"/>
190 <xsl:if test="not($recursive)">
191 <xsl:value-of select="$html.ext"/>
195 <xsl:when test="self::appendix">
197 <!-- in a set, make sure we inherit the right book info... -->
198 <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
199 <xsl:with-param name="recursive" select="true()"/>
200 </xsl:apply-templates>
203 <xsl:text>ap</xsl:text>
204 <xsl:number level="any" format="a" from="book"/>
205 <xsl:if test="not($recursive)">
206 <xsl:value-of select="$html.ext"/>
210 <xsl:when test="self::part">
212 <xsl:when test="/set">
213 <!-- in a set, make sure we inherit the right book info... -->
214 <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
215 <xsl:with-param name="recursive" select="true()"/>
216 </xsl:apply-templates>
222 <xsl:text>pt</xsl:text>
223 <xsl:number level="any" format="01" from="book"/>
224 <xsl:if test="not($recursive)">
225 <xsl:value-of select="$html.ext"/>
229 <xsl:when test="self::reference">
231 <xsl:when test="/set">
232 <!-- in a set, make sure we inherit the right book info... -->
233 <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
234 <xsl:with-param name="recursive" select="true()"/>
235 </xsl:apply-templates>
241 <xsl:text>rn</xsl:text>
242 <xsl:number level="any" format="01" from="book"/>
243 <xsl:if test="not($recursive)">
244 <xsl:value-of select="$html.ext"/>
248 <xsl:when test="self::refentry">
250 <xsl:when test="parent::reference">
251 <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
252 <xsl:with-param name="recursive" select="true()"/>
253 </xsl:apply-templates>
259 <xsl:text>re</xsl:text>
260 <xsl:number level="any" format="01" from="book"/>
261 <xsl:if test="not($recursive)">
262 <xsl:value-of select="$html.ext"/>
266 <xsl:when test="self::colophon">
268 <xsl:when test="/set">
269 <!-- in a set, make sure we inherit the right book info... -->
270 <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
271 <xsl:with-param name="recursive" select="true()"/>
272 </xsl:apply-templates>
278 <xsl:text>co</xsl:text>
279 <xsl:number level="any" format="01" from="book"/>
280 <xsl:if test="not($recursive)">
281 <xsl:value-of select="$html.ext"/>
285 <xsl:when test="self::sect1
291 <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
292 <xsl:with-param name="recursive" select="true()"/>
293 </xsl:apply-templates>
294 <xsl:text>s</xsl:text>
295 <xsl:number format="01"/>
296 <xsl:if test="not($recursive)">
297 <xsl:value-of select="$html.ext"/>
301 <xsl:when test="self::bibliography">
303 <xsl:when test="/set">
304 <!-- in a set, make sure we inherit the right book info... -->
305 <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
306 <xsl:with-param name="recursive" select="true()"/>
307 </xsl:apply-templates>
313 <xsl:text>bi</xsl:text>
314 <xsl:number level="any" format="01" from="book"/>
315 <xsl:if test="not($recursive)">
316 <xsl:value-of select="$html.ext"/>
320 <xsl:when test="self::glossary">
322 <xsl:when test="/set">
323 <!-- in a set, make sure we inherit the right book info... -->
324 <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
325 <xsl:with-param name="recursive" select="true()"/>
326 </xsl:apply-templates>
332 <xsl:text>go</xsl:text>
333 <xsl:number level="any" format="01" from="book"/>
334 <xsl:if test="not($recursive)">
335 <xsl:value-of select="$html.ext"/>
339 <xsl:when test="self::index">
341 <xsl:when test="/set">
342 <!-- in a set, make sure we inherit the right book info... -->
343 <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
344 <xsl:with-param name="recursive" select="true()"/>
345 </xsl:apply-templates>
351 <xsl:text>ix</xsl:text>
352 <xsl:number level="any" format="01" from="book"/>
353 <xsl:if test="not($recursive)">
354 <xsl:value-of select="$html.ext"/>
358 <xsl:when test="self::setindex">
359 <xsl:text>si</xsl:text>
360 <xsl:number level="any" format="01" from="set"/>
361 <xsl:if test="not($recursive)">
362 <xsl:value-of select="$html.ext"/>
367 <xsl:text>chunk-filename-error-</xsl:text>
368 <xsl:value-of select="name(.)"/>
369 <xsl:number level="any" format="01" from="set"/>
370 <xsl:if test="not($recursive)">
371 <xsl:value-of select="$html.ext"/>
377 <!-- ==================================================================== -->
381 <xsl:template match="processing-instruction('dbhtml')">
385 <!-- ==================================================================== -->
388 <xsl:template match="*" mode="find.chunks">
389 <xsl:variable name="chunk">
390 <xsl:call-template name="chunk"/>
394 <xsl:when test="$chunk != 0">
395 <cf:div id="{generate-id()}">
396 <xsl:apply-templates select="." mode="class.attribute"/>
397 <xsl:apply-templates select="*" mode="find.chunks"/>
401 <xsl:apply-templates select="*" mode="find.chunks"/>
406 <xsl:template match="/">
407 <!-- * Get a title for current doc so that we let the user -->
408 <!-- * know what document we are processing at this point. -->
409 <xsl:variable name="doc.title">
410 <xsl:call-template name="get.doc.title"/>
413 <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
414 toss the namespace and continue. Use the docbook5 namespaced
415 stylesheets for DocBook5 if you don't want to use this feature.-->
416 <xsl:when test="$exsl.node.set.available != 0
417 and (*/self::ng:* or */self::db:*)">
418 <xsl:call-template name="log.message">
419 <xsl:with-param name="level">Note</xsl:with-param>
420 <xsl:with-param name="source" select="$doc.title"/>
421 <xsl:with-param name="context-desc">
422 <xsl:text>namesp. cut</xsl:text>
424 <xsl:with-param name="message">
425 <xsl:text>stripped namespace before processing</xsl:text>
428 <xsl:variable name="nons">
429 <xsl:apply-templates mode="stripNS"/>
431 <xsl:call-template name="log.message">
432 <xsl:with-param name="level">Note</xsl:with-param>
433 <xsl:with-param name="source" select="$doc.title"/>
434 <xsl:with-param name="context-desc">
435 <xsl:text>namesp. cut</xsl:text>
437 <xsl:with-param name="message">
438 <xsl:text>processing stripped document</xsl:text>
441 <xsl:apply-templates select="exsl:node-set($nons)"/>
443 <!-- Can't process unless namespace removed -->
444 <xsl:when test="*/self::ng:* or */self::db:*">
445 <xsl:message terminate="yes">
446 <xsl:text>Unable to strip the namespace from DB5 document,</xsl:text>
447 <xsl:text> cannot proceed.</xsl:text>
452 <xsl:when test="$rootid != ''">
454 <xsl:when test="count(key('id',$rootid)) = 0">
455 <xsl:message terminate="yes">
456 <xsl:text>ID '</xsl:text>
457 <xsl:value-of select="$rootid"/>
458 <xsl:text>' not found in document.</xsl:text>
462 <xsl:if test="$collect.xref.targets = 'yes' or
463 $collect.xref.targets = 'only'">
464 <xsl:apply-templates select="key('id', $rootid)"
465 mode="collect.targets"/>
467 <xsl:if test="$collect.xref.targets != 'only'">
468 <xsl:apply-templates select="key('id',$rootid)"
469 mode="process.root"/>
470 <xsl:if test="$tex.math.in.alt != ''">
471 <xsl:apply-templates select="key('id',$rootid)"
472 mode="collect.tex.math"/>
474 <xsl:if test="$generate.manifest != 0">
475 <xsl:call-template name="generate.manifest">
476 <xsl:with-param name="node" select="key('id',$rootid)"/>
484 <xsl:if test="$collect.xref.targets = 'yes' or
485 $collect.xref.targets = 'only'">
486 <xsl:apply-templates select="/" mode="collect.targets"/>
488 <xsl:if test="$collect.xref.targets != 'only'">
489 <xsl:apply-templates select="/" mode="process.root"/>
490 <xsl:if test="$tex.math.in.alt != ''">
491 <xsl:apply-templates select="/" mode="collect.tex.math"/>
493 <xsl:if test="$generate.manifest != 0">
494 <xsl:call-template name="generate.manifest">
495 <xsl:with-param name="node" select="/"/>
505 <xsl:template match="*" mode="process.root">
506 <xsl:apply-templates select="."/>
509 <!-- ====================================================================== -->
511 <xsl:template match="set|book|part|preface|chapter|appendix
514 |book/glossary|article/glossary|part/glossary
515 |book/bibliography|article/bibliography|part/bibliography
518 <xsl:when test="$onechunk != 0 and parent::*">
522 <xsl:call-template name="process-chunk-element"/>
527 <xsl:template match="sect1|sect2|sect3|sect4|sect5|section">
528 <xsl:variable name="ischunk">
529 <xsl:call-template name="chunk"/>
533 <xsl:when test="not(parent::*)">
534 <xsl:call-template name="process-chunk-element"/>
536 <xsl:when test="$ischunk = 0">
540 <xsl:call-template name="process-chunk-element"/>
545 <xsl:template match="setindex
549 <!-- some implementations use completely empty index tags to indicate -->
550 <!-- where an automatically generated index should be inserted. so -->
551 <!-- if the index is completely empty, skip it. -->
552 <xsl:if test="count(*)>0 or $generate.index != '0'">
553 <xsl:call-template name="process-chunk-element"/>
557 <!-- Resolve xml:base attributes -->
558 <xsl:template match="@fileref">
559 <!-- need a check for absolute urls -->
561 <xsl:when test="contains(., ':')">
562 <!-- it has a uri scheme so it is an absolute uri -->
563 <xsl:value-of select="."/>
565 <xsl:when test="$keep.relative.image.uris != 0">
566 <!-- leave it alone -->
567 <xsl:value-of select="."/>
570 <!-- its a relative uri -->
571 <xsl:call-template name="relative-uri">
572 <xsl:with-param name="destdir">
573 <xsl:call-template name="dbhtml-dir">
574 <xsl:with-param name="context" select=".."/>
582 <!-- ==================================================================== -->
583 <xsl:template match="set|book|part|preface|chapter|appendix
586 |sect1|sect2|sect3|sect4|sect5
588 |book/glossary|article/glossary|part/glossary
589 |book/bibliography|article/bibliography|part/bibliography
591 mode="enumerate-files">
592 <xsl:variable name="ischunk"><xsl:call-template name="chunk"/></xsl:variable>
593 <xsl:if test="$ischunk='1'">
594 <xsl:call-template name="make-relative-filename">
595 <xsl:with-param name="base.dir">
596 <xsl:if test="$manifest.in.base.dir = 0">
597 <xsl:value-of select="$base.dir"/>
600 <xsl:with-param name="base.name">
601 <xsl:apply-templates mode="chunk-filename" select="."/>
604 <xsl:text> </xsl:text>
606 <xsl:apply-templates select="*" mode="enumerate-files"/>
609 <xsl:template match="book/index|article/index|part/index"
610 mode="enumerate-files">
611 <xsl:if test="$htmlhelp.output != 1">
612 <xsl:variable name="ischunk"><xsl:call-template name="chunk"/></xsl:variable>
613 <xsl:if test="$ischunk='1'">
614 <xsl:call-template name="make-relative-filename">
615 <xsl:with-param name="base.dir">
616 <xsl:if test="$manifest.in.base.dir = 0">
617 <xsl:value-of select="$base.dir"/>
620 <xsl:with-param name="base.name">
621 <xsl:apply-templates mode="chunk-filename" select="."/>
624 <xsl:text> </xsl:text>
626 <xsl:apply-templates select="*" mode="enumerate-files"/>
630 <xsl:template match="legalnotice" mode="enumerate-files">
631 <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
632 <xsl:if test="$generate.legalnotice.link != 0">
633 <xsl:call-template name="make-relative-filename">
634 <xsl:with-param name="base.dir">
635 <xsl:if test="$manifest.in.base.dir = 0">
636 <xsl:value-of select="$base.dir"/>
639 <xsl:with-param name="base.name">
640 <xsl:apply-templates mode="chunk-filename" select="."/>
643 <xsl:text> </xsl:text>
647 <xsl:template match="mediaobject[imageobject] | inlinemediaobject[imageobject]" mode="enumerate-files">
648 <xsl:variable name="longdesc.uri">
649 <xsl:call-template name="longdesc.uri">
650 <xsl:with-param name="mediaobject"
654 <xsl:variable name="mediaobject" select="."/>
656 <xsl:if test="$html.longdesc != 0 and $mediaobject/textobject[not(phrase)]">
657 <xsl:call-template name="longdesc.uri">
658 <xsl:with-param name="mediaobject" select="$mediaobject"/>
660 <xsl:text> </xsl:text>
664 <xsl:template match="text()" mode="enumerate-files">