source: trunk/Distribution/XSL/html/chunk-code.xsl@ 3

Last change on this file since 3 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: 40.0 KB
Line 
1<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2 xmlns:exsl="http://exslt.org/common"
3 xmlns:cf="http://docbook.sourceforge.net/xmlns/chunkfast/1.0"
4 xmlns:ng="http://docbook.org/docbook-ng"
5 xmlns:db="http://docbook.org/ns/docbook"
6 version="1.0"
7 exclude-result-prefixes="exsl cf ng db">
8
9<!-- ********************************************************************
10 $Id: chunk-code.xsl,v 1.14 2005/08/04 07:03:47 bobstayton Exp $
11 ********************************************************************
12
13 This file is part of the XSL DocBook Stylesheet distribution.
14 See ../README or http://nwalsh.com/docbook/xsl/ for copyright
15 and other information.
16
17 ******************************************************************** -->
18
19<!-- ==================================================================== -->
20
21<xsl:param name="onechunk" select="0"/>
22<xsl:param name="refentry.separator" select="0"/>
23<xsl:param name="chunk.fast" select="0"/>
24
25<xsl:key name="genid" match="*" use="generate-id()"/>
26
27<!-- ==================================================================== -->
28
29<xsl:variable name="chunk.hierarchy">
30 <xsl:if test="$chunk.fast != 0">
31 <xsl:choose>
32 <xsl:when test="function-available('exsl:node-set')">
33 <xsl:message>Computing chunks...</xsl:message>
34 <xsl:apply-templates select="/*" mode="find.chunks"/>
35 </xsl:when>
36 <xsl:otherwise>
37 <xsl:message>
38 <xsl:text>Fast chunking requires exsl:node-set(). </xsl:text>
39 <xsl:text>Using "slow" chunking.</xsl:text>
40 </xsl:message>
41 </xsl:otherwise>
42 </xsl:choose>
43 </xsl:if>
44</xsl:variable>
45
46<xsl:template match="*" mode="find.chunks">
47 <xsl:variable name="chunk">
48 <xsl:call-template name="chunk"/>
49 </xsl:variable>
50
51 <xsl:choose>
52 <xsl:when test="$chunk != 0">
53 <cf:div class="{local-name(.)}" id="{generate-id()}">
54 <xsl:apply-templates select="*" mode="find.chunks"/>
55 </cf:div>
56 </xsl:when>
57 <xsl:otherwise>
58 <xsl:apply-templates select="*" mode="find.chunks"/>
59 </xsl:otherwise>
60 </xsl:choose>
61</xsl:template>
62
63<!-- ==================================================================== -->
64
65<xsl:template name="process-chunk-element">
66 <xsl:param name="content">
67 <xsl:apply-imports/>
68 </xsl:param>
69
70 <xsl:choose>
71 <xsl:when test="$chunk.fast != 0 and function-available('exsl:node-set')">
72 <xsl:variable name="chunks" select="exsl:node-set($chunk.hierarchy)//cf:div"/>
73 <xsl:variable name="genid" select="generate-id()"/>
74
75 <xsl:variable name="div" select="$chunks[@id=$genid]"/>
76
77 <xsl:variable name="prevdiv"
78 select="($div/preceding-sibling::cf:div|$div/preceding::cf:div|$div/parent::cf:div)[last()]"/>
79 <xsl:variable name="prev" select="key('genid', $prevdiv/@id)"/>
80
81 <xsl:variable name="nextdiv"
82 select="($div/following-sibling::cf:div|$div/following::cf:div|$div/cf:div)[1]"/>
83 <xsl:variable name="next" select="key('genid', $nextdiv/@id)"/>
84
85 <xsl:choose>
86 <xsl:when test="$onechunk != 0 and parent::*">
87 <xsl:copy-of select="$content"/>
88 </xsl:when>
89 <xsl:otherwise>
90 <xsl:call-template name="process-chunk">
91 <xsl:with-param name="prev" select="$prev"/>
92 <xsl:with-param name="next" select="$next"/>
93 <xsl:with-param name="content" select="$content"/>
94 </xsl:call-template>
95 </xsl:otherwise>
96 </xsl:choose>
97 </xsl:when>
98 <xsl:otherwise>
99 <xsl:choose>
100 <xsl:when test="$onechunk != 0 and not(parent::*)">
101 <xsl:call-template name="chunk-all-sections">
102 <xsl:with-param name="content" select="$content"/>
103 </xsl:call-template>
104 </xsl:when>
105 <xsl:when test="$onechunk != 0">
106 <xsl:copy-of select="$content"/>
107 </xsl:when>
108 <xsl:when test="$chunk.first.sections = 0">
109 <xsl:call-template name="chunk-first-section-with-parent">
110 <xsl:with-param name="content" select="$content"/>
111 </xsl:call-template>
112 </xsl:when>
113 <xsl:otherwise>
114 <xsl:call-template name="chunk-all-sections">
115 <xsl:with-param name="content" select="$content"/>
116 </xsl:call-template>
117 </xsl:otherwise>
118 </xsl:choose>
119 </xsl:otherwise>
120 </xsl:choose>
121</xsl:template>
122
123<xsl:template name="process-chunk">
124 <xsl:param name="prev" select="."/>
125 <xsl:param name="next" select="."/>
126 <xsl:param name="content">
127 <xsl:apply-imports/>
128 </xsl:param>
129
130 <xsl:variable name="ischunk">
131 <xsl:call-template name="chunk"/>
132 </xsl:variable>
133
134 <xsl:variable name="chunkfn">
135 <xsl:if test="$ischunk='1'">
136 <xsl:apply-templates mode="chunk-filename" select="."/>
137 </xsl:if>
138 </xsl:variable>
139
140 <xsl:if test="$ischunk='0'">
141 <xsl:message>
142 <xsl:text>Error </xsl:text>
143 <xsl:value-of select="name(.)"/>
144 <xsl:text> is not a chunk!</xsl:text>
145 </xsl:message>
146 </xsl:if>
147
148 <xsl:variable name="filename">
149 <xsl:call-template name="make-relative-filename">
150 <xsl:with-param name="base.dir" select="$base.dir"/>
151 <xsl:with-param name="base.name" select="$chunkfn"/>
152 </xsl:call-template>
153 </xsl:variable>
154
155 <xsl:call-template name="write.chunk">
156 <xsl:with-param name="filename" select="$filename"/>
157 <xsl:with-param name="content">
158 <xsl:call-template name="chunk-element-content">
159 <xsl:with-param name="prev" select="$prev"/>
160 <xsl:with-param name="next" select="$next"/>
161 <xsl:with-param name="content" select="$content"/>
162 </xsl:call-template>
163 </xsl:with-param>
164 <xsl:with-param name="quiet" select="$chunk.quietly"/>
165 </xsl:call-template>
166</xsl:template>
167
168<xsl:template name="chunk-first-section-with-parent">
169 <xsl:param name="content">
170 <xsl:apply-imports/>
171 </xsl:param>
172
173 <!-- These xpath expressions are really hairy. The trick is to pick sections -->
174 <!-- that are not first children and are not the children of first children -->
175
176 <!-- Break these variables into pieces to work around
177 http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6063 -->
178
179 <xsl:variable name="prev-v1"
180 select="(ancestor::sect1[$chunk.section.depth &gt; 0
181 and preceding-sibling::sect1][1]
182
183 |ancestor::sect2[$chunk.section.depth &gt; 1
184 and preceding-sibling::sect2
185 and parent::sect1[preceding-sibling::sect1]][1]
186
187 |ancestor::sect3[$chunk.section.depth &gt; 2
188 and preceding-sibling::sect3
189 and parent::sect2[preceding-sibling::sect2]
190 and ancestor::sect1[preceding-sibling::sect1]][1]
191
192 |ancestor::sect4[$chunk.section.depth &gt; 3
193 and preceding-sibling::sect4
194 and parent::sect3[preceding-sibling::sect2]
195 and ancestor::sect2[preceding-sibling::sect2]
196 and ancestor::sect1[preceding-sibling::sect1]][1]
197
198 |ancestor::sect5[$chunk.section.depth &gt; 4
199 and preceding-sibling::sect5
200 and parent::sect4[preceding-sibling::sect4]
201 and ancestor::sect3[preceding-sibling::sect3]
202 and ancestor::sect2[preceding-sibling::sect2]
203 and ancestor::sect1[preceding-sibling::sect1]][1]
204
205 |ancestor::section[$chunk.section.depth &gt; count(ancestor::section)
206 and not(ancestor::section[not(preceding-sibling::section)])][1])[last()]"/>
207
208 <xsl:variable name="prev-v2"
209 select="(preceding::sect1[$chunk.section.depth &gt; 0
210 and preceding-sibling::sect1][1]
211
212 |preceding::sect2[$chunk.section.depth &gt; 1
213 and preceding-sibling::sect2
214 and parent::sect1[preceding-sibling::sect1]][1]
215
216 |preceding::sect3[$chunk.section.depth &gt; 2
217 and preceding-sibling::sect3
218 and parent::sect2[preceding-sibling::sect2]
219 and ancestor::sect1[preceding-sibling::sect1]][1]
220
221 |preceding::sect4[$chunk.section.depth &gt; 3
222 and preceding-sibling::sect4
223 and parent::sect3[preceding-sibling::sect2]
224 and ancestor::sect2[preceding-sibling::sect2]
225 and ancestor::sect1[preceding-sibling::sect1]][1]
226
227 |preceding::sect5[$chunk.section.depth &gt; 4
228 and preceding-sibling::sect5
229 and parent::sect4[preceding-sibling::sect4]
230 and ancestor::sect3[preceding-sibling::sect3]
231 and ancestor::sect2[preceding-sibling::sect2]
232 and ancestor::sect1[preceding-sibling::sect1]][1]
233
234 |preceding::section[$chunk.section.depth &gt; count(ancestor::section)
235 and preceding-sibling::section
236 and not(ancestor::section[not(preceding-sibling::section)])][1])[last()]"/>
237
238 <xsl:variable name="prev"
239 select="(preceding::book[1]
240 |preceding::preface[1]
241 |preceding::chapter[1]
242 |preceding::appendix[1]
243 |preceding::part[1]
244 |preceding::reference[1]
245 |preceding::refentry[1]
246 |preceding::colophon[1]
247 |preceding::article[1]
248 |preceding::bibliography[parent::article or parent::book or parent::part][1]
249 |preceding::glossary[parent::article or parent::book or parent::part][1]
250 |preceding::index[$generate.index != 0]
251 [parent::article or parent::book or parent::part][1]
252 |preceding::setindex[$generate.index != 0][1]
253 |ancestor::set
254 |ancestor::book[1]
255 |ancestor::preface[1]
256 |ancestor::chapter[1]
257 |ancestor::appendix[1]
258 |ancestor::part[1]
259 |ancestor::reference[1]
260 |ancestor::article[1]
261 |$prev-v1
262 |$prev-v2)[last()]"/>
263
264 <xsl:variable name="next-v1"
265 select="(following::sect1[$chunk.section.depth &gt; 0
266 and preceding-sibling::sect1][1]
267
268 |following::sect2[$chunk.section.depth &gt; 1
269 and preceding-sibling::sect2
270 and parent::sect1[preceding-sibling::sect1]][1]
271
272 |following::sect3[$chunk.section.depth &gt; 2
273 and preceding-sibling::sect3
274 and parent::sect2[preceding-sibling::sect2]
275 and ancestor::sect1[preceding-sibling::sect1]][1]
276
277 |following::sect4[$chunk.section.depth &gt; 3
278 and preceding-sibling::sect4
279 and parent::sect3[preceding-sibling::sect2]
280 and ancestor::sect2[preceding-sibling::sect2]
281 and ancestor::sect1[preceding-sibling::sect1]][1]
282
283 |following::sect5[$chunk.section.depth &gt; 4
284 and preceding-sibling::sect5
285 and parent::sect4[preceding-sibling::sect4]
286 and ancestor::sect3[preceding-sibling::sect3]
287 and ancestor::sect2[preceding-sibling::sect2]
288 and ancestor::sect1[preceding-sibling::sect1]][1]
289
290 |following::section[$chunk.section.depth &gt; count(ancestor::section)
291 and preceding-sibling::section
292 and not(ancestor::section[not(preceding-sibling::section)])][1])[1]"/>
293
294 <xsl:variable name="next-v2"
295 select="(descendant::sect1[$chunk.section.depth &gt; 0
296 and preceding-sibling::sect1][1]
297
298 |descendant::sect2[$chunk.section.depth &gt; 1
299 and preceding-sibling::sect2
300 and parent::sect1[preceding-sibling::sect1]][1]
301
302 |descendant::sect3[$chunk.section.depth &gt; 2
303 and preceding-sibling::sect3
304 and parent::sect2[preceding-sibling::sect2]
305 and ancestor::sect1[preceding-sibling::sect1]][1]
306
307 |descendant::sect4[$chunk.section.depth &gt; 3
308 and preceding-sibling::sect4
309 and parent::sect3[preceding-sibling::sect2]
310 and ancestor::sect2[preceding-sibling::sect2]
311 and ancestor::sect1[preceding-sibling::sect1]][1]
312
313 |descendant::sect5[$chunk.section.depth &gt; 4
314 and preceding-sibling::sect5
315 and parent::sect4[preceding-sibling::sect4]
316 and ancestor::sect3[preceding-sibling::sect3]
317 and ancestor::sect2[preceding-sibling::sect2]
318 and ancestor::sect1[preceding-sibling::sect1]][1]
319
320 |descendant::section[$chunk.section.depth &gt; count(ancestor::section)
321 and preceding-sibling::section
322 and not(ancestor::section[not(preceding-sibling::section)])])[1]"/>
323
324 <xsl:variable name="next"
325 select="(following::book[1]
326 |following::preface[1]
327 |following::chapter[1]
328 |following::appendix[1]
329 |following::part[1]
330 |following::reference[1]
331 |following::refentry[1]
332 |following::colophon[1]
333 |following::bibliography[parent::article or parent::book or parent::part][1]
334 |following::glossary[parent::article or parent::book or parent::part][1]
335 |following::index[$generate.index != 0]
336 [parent::article or parent::book or parent::part][1]
337 |following::article[1]
338 |following::setindex[$generate.index != 0][1]
339 |descendant::book[1]
340 |descendant::preface[1]
341 |descendant::chapter[1]
342 |descendant::appendix[1]
343 |descendant::article[1]
344 |descendant::bibliography[parent::article or parent::book or parent::part][1]
345 |descendant::glossary[parent::article or parent::book or parent::part][1]
346 |descendant::index[$generate.index != 0]
347 [parent::article or parent::book or parent::part][1]
348 |descendant::colophon[1]
349 |descendant::setindex[$generate.index != 0][1]
350 |descendant::part[1]
351 |descendant::reference[1]
352 |descendant::refentry[1]
353 |$next-v1
354 |$next-v2)[1]"/>
355
356 <xsl:call-template name="process-chunk">
357 <xsl:with-param name="prev" select="$prev"/>
358 <xsl:with-param name="next" select="$next"/>
359 <xsl:with-param name="content" select="$content"/>
360 </xsl:call-template>
361</xsl:template>
362
363<xsl:template name="chunk-all-sections">
364 <xsl:param name="content">
365 <xsl:apply-imports/>
366 </xsl:param>
367
368 <xsl:variable name="prev-v1"
369 select="(preceding::sect1[$chunk.section.depth &gt; 0][1]
370 |preceding::sect2[$chunk.section.depth &gt; 1][1]
371 |preceding::sect3[$chunk.section.depth &gt; 2][1]
372 |preceding::sect4[$chunk.section.depth &gt; 3][1]
373 |preceding::sect5[$chunk.section.depth &gt; 4][1]
374 |preceding::section[$chunk.section.depth &gt; count(ancestor::section)][1])[last()]"/>
375
376 <xsl:variable name="prev-v2"
377 select="(ancestor::sect1[$chunk.section.depth &gt; 0][1]
378 |ancestor::sect2[$chunk.section.depth &gt; 1][1]
379 |ancestor::sect3[$chunk.section.depth &gt; 2][1]
380 |ancestor::sect4[$chunk.section.depth &gt; 3][1]
381 |ancestor::sect5[$chunk.section.depth &gt; 4][1]
382 |ancestor::section[$chunk.section.depth &gt; count(ancestor::section)][1])[last()]"/>
383
384 <xsl:variable name="prev"
385 select="(preceding::book[1]
386 |preceding::preface[1]
387 |preceding::chapter[1]
388 |preceding::appendix[1]
389 |preceding::part[1]
390 |preceding::reference[1]
391 |preceding::refentry[1]
392 |preceding::colophon[1]
393 |preceding::article[1]
394 |preceding::bibliography[parent::article or parent::book or parent::part][1]
395 |preceding::glossary[parent::article or parent::book or parent::part][1]
396 |preceding::index[$generate.index != 0]
397 [parent::article or parent::book or parent::part][1]
398 |preceding::setindex[$generate.index != 0][1]
399 |ancestor::set
400 |ancestor::book[1]
401 |ancestor::preface[1]
402 |ancestor::chapter[1]
403 |ancestor::appendix[1]
404 |ancestor::part[1]
405 |ancestor::reference[1]
406 |ancestor::article[1]
407 |$prev-v1
408 |$prev-v2)[last()]"/>
409
410 <xsl:variable name="next-v1"
411 select="(following::sect1[$chunk.section.depth &gt; 0][1]
412 |following::sect2[$chunk.section.depth &gt; 1][1]
413 |following::sect3[$chunk.section.depth &gt; 2][1]
414 |following::sect4[$chunk.section.depth &gt; 3][1]
415 |following::sect5[$chunk.section.depth &gt; 4][1]
416 |following::section[$chunk.section.depth &gt; count(ancestor::section)][1])[1]"/>
417
418 <xsl:variable name="next-v2"
419 select="(descendant::sect1[$chunk.section.depth &gt; 0][1]
420 |descendant::sect2[$chunk.section.depth &gt; 1][1]
421 |descendant::sect3[$chunk.section.depth &gt; 2][1]
422 |descendant::sect4[$chunk.section.depth &gt; 3][1]
423 |descendant::sect5[$chunk.section.depth &gt; 4][1]
424 |descendant::section[$chunk.section.depth
425 &gt; count(ancestor::section)][1])[1]"/>
426
427 <xsl:variable name="next"
428 select="(following::book[1]
429 |following::preface[1]
430 |following::chapter[1]
431 |following::appendix[1]
432 |following::part[1]
433 |following::reference[1]
434 |following::refentry[1]
435 |following::colophon[1]
436 |following::bibliography[parent::article or parent::book or parent::part][1]
437 |following::glossary[parent::article or parent::book or parent::part][1]
438 |following::index[$generate.index != 0]
439 [parent::article or parent::book][1]
440 |following::article[1]
441 |following::setindex[$generate.index != 0][1]
442 |descendant::book[1]
443 |descendant::preface[1]
444 |descendant::chapter[1]
445 |descendant::appendix[1]
446 |descendant::article[1]
447 |descendant::bibliography[parent::article or parent::book][1]
448 |descendant::glossary[parent::article or parent::book or parent::part][1]
449 |descendant::index[$generate.index != 0]
450 [parent::article or parent::book][1]
451 |descendant::colophon[1]
452 |descendant::setindex[$generate.index != 0][1]
453 |descendant::part[1]
454 |descendant::reference[1]
455 |descendant::refentry[1]
456 |$next-v1
457 |$next-v2)[1]"/>
458
459 <xsl:call-template name="process-chunk">
460 <xsl:with-param name="prev" select="$prev"/>
461 <xsl:with-param name="next" select="$next"/>
462 <xsl:with-param name="content" select="$content"/>
463 </xsl:call-template>
464</xsl:template>
465
466<!-- ==================================================================== -->
467
468<xsl:template match="/">
469 <xsl:choose>
470 <xsl:when test="function-available('exsl:node-set')
471 and (*/self::ng:* or */self::db:*)">
472 <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
473 toss the namespace and continue. Someday we'll reverse this logic
474 and add the namespace to documents that don't have one.
475 But not before the whole stylesheet has been converted to use
476 namespaces. i.e., don't hold your breath -->
477 <xsl:message>Stripping NS from DocBook 5/NG document.</xsl:message>
478 <xsl:variable name="nons">
479 <xsl:apply-templates mode="stripNS"/>
480 </xsl:variable>
481 <xsl:message>Processing stripped document.</xsl:message>
482 <xsl:apply-templates select="exsl:node-set($nons)"/>
483 </xsl:when>
484 <xsl:otherwise>
485 <xsl:choose>
486 <xsl:when test="$rootid != ''">
487 <xsl:choose>
488 <xsl:when test="count(key('id',$rootid)) = 0">
489 <xsl:message terminate="yes">
490 <xsl:text>ID '</xsl:text>
491 <xsl:value-of select="$rootid"/>
492 <xsl:text>' not found in document.</xsl:text>
493 </xsl:message>
494 </xsl:when>
495 <xsl:otherwise>
496 <xsl:if test="$collect.xref.targets = 'yes' or
497 $collect.xref.targets = 'only'">
498 <xsl:apply-templates select="key('id', $rootid)"
499 mode="collect.targets"/>
500 </xsl:if>
501 <xsl:if test="$collect.xref.targets != 'only'">
502 <xsl:apply-templates select="key('id',$rootid)"
503 mode="process.root"/>
504 <xsl:if test="$tex.math.in.alt != ''">
505 <xsl:apply-templates select="key('id',$rootid)"
506 mode="collect.tex.math"/>
507 </xsl:if>
508 <xsl:if test="$generate.manifest != 0">
509 <xsl:call-template name="generate.manifest">
510 <xsl:with-param name="node" select="key('id',$rootid)"/>
511 </xsl:call-template>
512 </xsl:if>
513 </xsl:if>
514 </xsl:otherwise>
515 </xsl:choose>
516 </xsl:when>
517 <xsl:otherwise>
518 <xsl:if test="$collect.xref.targets = 'yes' or
519 $collect.xref.targets = 'only'">
520 <xsl:apply-templates select="/" mode="collect.targets"/>
521 </xsl:if>
522 <xsl:if test="$collect.xref.targets != 'only'">
523 <xsl:apply-templates select="/" mode="process.root"/>
524 <xsl:if test="$tex.math.in.alt != ''">
525 <xsl:apply-templates select="/" mode="collect.tex.math"/>
526 </xsl:if>
527 <xsl:if test="$generate.manifest != 0">
528 <xsl:call-template name="generate.manifest">
529 <xsl:with-param name="node" select="/"/>
530 </xsl:call-template>
531 </xsl:if>
532 </xsl:if>
533 </xsl:otherwise>
534 </xsl:choose>
535 </xsl:otherwise>
536 </xsl:choose>
537</xsl:template>
538
539<xsl:template match="*" mode="process.root">
540 <xsl:apply-templates select="."/>
541</xsl:template>
542
543<!-- ====================================================================== -->
544
545<xsl:template match="set|book|part|preface|chapter|appendix
546 |article
547 |reference|refentry
548 |book/glossary|article/glossary|part/glossary
549 |book/bibliography|article/bibliography|part/bibliography
550 |colophon">
551 <xsl:choose>
552 <xsl:when test="$onechunk != 0 and parent::*">
553 <xsl:apply-imports/>
554 </xsl:when>
555 <xsl:otherwise>
556 <xsl:call-template name="process-chunk-element"/>
557 </xsl:otherwise>
558 </xsl:choose>
559</xsl:template>
560
561<xsl:template match="sect1|sect2|sect3|sect4|sect5|section">
562 <xsl:variable name="ischunk">
563 <xsl:call-template name="chunk"/>
564 </xsl:variable>
565
566 <xsl:choose>
567 <xsl:when test="not(parent::*)">
568 <xsl:call-template name="process-chunk-element"/>
569 </xsl:when>
570 <xsl:when test="$ischunk = 0">
571 <xsl:apply-imports/>
572 </xsl:when>
573 <xsl:otherwise>
574 <xsl:call-template name="process-chunk-element"/>
575 </xsl:otherwise>
576 </xsl:choose>
577</xsl:template>
578
579<xsl:template match="setindex
580 |book/index
581 |article/index
582 |part/index">
583 <!-- some implementations use completely empty index tags to indicate -->
584 <!-- where an automatically generated index should be inserted. so -->
585 <!-- if the index is completely empty, skip it. -->
586 <xsl:if test="count(*)>0 or $generate.index != '0'">
587 <xsl:call-template name="process-chunk-element"/>
588 </xsl:if>
589</xsl:template>
590
591<!-- ==================================================================== -->
592
593<xsl:template name="make.lots">
594 <xsl:param name="toc.params" select="''"/>
595 <xsl:param name="toc"/>
596
597 <xsl:variable name="lots">
598 <xsl:if test="contains($toc.params, 'toc')">
599 <xsl:copy-of select="$toc"/>
600 </xsl:if>
601
602 <xsl:if test="contains($toc.params, 'figure')">
603 <xsl:choose>
604 <xsl:when test="$chunk.separate.lots != '0'">
605 <xsl:call-template name="make.lot.chunk">
606 <xsl:with-param name="type" select="'figure'"/>
607 <xsl:with-param name="lot">
608 <xsl:call-template name="list.of.titles">
609 <xsl:with-param name="titles" select="'figure'"/>
610 <xsl:with-param name="nodes" select=".//figure"/>
611 </xsl:call-template>
612 </xsl:with-param>
613 </xsl:call-template>
614 </xsl:when>
615 <xsl:otherwise>
616 <xsl:call-template name="list.of.titles">
617 <xsl:with-param name="titles" select="'figure'"/>
618 <xsl:with-param name="nodes" select=".//figure"/>
619 </xsl:call-template>
620 </xsl:otherwise>
621 </xsl:choose>
622 </xsl:if>
623
624 <xsl:if test="contains($toc.params, 'table')">
625 <xsl:choose>
626 <xsl:when test="$chunk.separate.lots != '0'">
627 <xsl:call-template name="make.lot.chunk">
628 <xsl:with-param name="type" select="'table'"/>
629 <xsl:with-param name="lot">
630 <xsl:call-template name="list.of.titles">
631 <xsl:with-param name="titles" select="'table'"/>
632 <xsl:with-param name="nodes" select=".//table"/>
633 </xsl:call-template>
634 </xsl:with-param>
635 </xsl:call-template>
636 </xsl:when>
637 <xsl:otherwise>
638 <xsl:call-template name="list.of.titles">
639 <xsl:with-param name="titles" select="'table'"/>
640 <xsl:with-param name="nodes" select=".//table"/>
641 </xsl:call-template>
642 </xsl:otherwise>
643 </xsl:choose>
644 </xsl:if>
645
646 <xsl:if test="contains($toc.params, 'example')">
647 <xsl:choose>
648 <xsl:when test="$chunk.separate.lots != '0'">
649 <xsl:call-template name="make.lot.chunk">
650 <xsl:with-param name="type" select="'example'"/>
651 <xsl:with-param name="lot">
652 <xsl:call-template name="list.of.titles">
653 <xsl:with-param name="titles" select="'example'"/>
654 <xsl:with-param name="nodes" select=".//example"/>
655 </xsl:call-template>
656 </xsl:with-param>
657 </xsl:call-template>
658 </xsl:when>
659 <xsl:otherwise>
660 <xsl:call-template name="list.of.titles">
661 <xsl:with-param name="titles" select="'example'"/>
662 <xsl:with-param name="nodes" select=".//example"/>
663 </xsl:call-template>
664 </xsl:otherwise>
665 </xsl:choose>
666 </xsl:if>
667
668 <xsl:if test="contains($toc.params, 'equation')">
669 <xsl:choose>
670 <xsl:when test="$chunk.separate.lots != '0'">
671 <xsl:call-template name="make.lot.chunk">
672 <xsl:with-param name="type" select="'equation'"/>
673 <xsl:with-param name="lot">
674 <xsl:call-template name="list.of.titles">
675 <xsl:with-param name="titles" select="'equation'"/>
676 <xsl:with-param name="nodes" select=".//equation"/>
677 </xsl:call-template>
678 </xsl:with-param>
679 </xsl:call-template>
680 </xsl:when>
681 <xsl:otherwise>
682 <xsl:call-template name="list.of.titles">
683 <xsl:with-param name="titles" select="'equation'"/>
684 <xsl:with-param name="nodes" select=".//equation"/>
685 </xsl:call-template>
686 </xsl:otherwise>
687 </xsl:choose>
688 </xsl:if>
689
690 <xsl:if test="contains($toc.params, 'procedure')">
691 <xsl:choose>
692 <xsl:when test="$chunk.separate.lots != '0'">
693 <xsl:call-template name="make.lot.chunk">
694 <xsl:with-param name="type" select="'procedure'"/>
695 <xsl:with-param name="lot">
696 <xsl:call-template name="list.of.titles">
697 <xsl:with-param name="titles" select="'procedure'"/>
698 <xsl:with-param name="nodes" select=".//procedure[title]"/>
699 </xsl:call-template>
700 </xsl:with-param>
701 </xsl:call-template>
702 </xsl:when>
703 <xsl:otherwise>
704 <xsl:call-template name="list.of.titles">
705 <xsl:with-param name="titles" select="'procedure'"/>
706 <xsl:with-param name="nodes" select=".//procedure[title]"/>
707 </xsl:call-template>
708 </xsl:otherwise>
709 </xsl:choose>
710 </xsl:if>
711 </xsl:variable>
712
713 <xsl:if test="string($lots) != ''">
714 <xsl:choose>
715 <xsl:when test="$chunk.tocs.and.lots != 0 and not(parent::*)">
716 <xsl:call-template name="write.chunk">
717 <xsl:with-param name="filename">
718 <xsl:call-template name="make-relative-filename">
719 <xsl:with-param name="base.dir" select="$base.dir"/>
720 <xsl:with-param name="base.name">
721 <xsl:call-template name="dbhtml-dir"/>
722 <xsl:apply-templates select="." mode="recursive-chunk-filename">
723 <xsl:with-param name="recursive" select="true()"/>
724 </xsl:apply-templates>
725 <xsl:text>-toc</xsl:text>
726 <xsl:value-of select="$html.ext"/>
727 </xsl:with-param>
728 </xsl:call-template>
729 </xsl:with-param>
730 <xsl:with-param name="content">
731 <xsl:call-template name="chunk-element-content">
732 <xsl:with-param name="prev" select="/foo"/>
733 <xsl:with-param name="next" select="/foo"/>
734 <xsl:with-param name="nav.context" select="'toc'"/>
735 <xsl:with-param name="content">
736 <h1>
737 <xsl:apply-templates select="." mode="object.title.markup"/>
738 </h1>
739 <xsl:copy-of select="$lots"/>
740 </xsl:with-param>
741 </xsl:call-template>
742 </xsl:with-param>
743 <xsl:with-param name="quiet" select="$chunk.quietly"/>
744 </xsl:call-template>
745 </xsl:when>
746 <xsl:otherwise>
747 <xsl:copy-of select="$lots"/>
748 </xsl:otherwise>
749 </xsl:choose>
750 </xsl:if>
751</xsl:template>
752
753<xsl:template name="make.lot.chunk">
754 <xsl:param name="type" select="''"/>
755 <xsl:param name="lot"/>
756
757 <xsl:if test="string($lot) != ''">
758 <xsl:variable name="filename">
759 <xsl:call-template name="make-relative-filename">
760 <xsl:with-param name="base.dir" select="$base.dir"/>
761 <xsl:with-param name="base.name">
762 <xsl:call-template name="dbhtml-dir"/>
763 <xsl:value-of select="$type"/>
764 <xsl:text>-toc</xsl:text>
765 <xsl:value-of select="$html.ext"/>
766 </xsl:with-param>
767 </xsl:call-template>
768 </xsl:variable>
769
770 <xsl:variable name="href">
771 <xsl:call-template name="make-relative-filename">
772 <xsl:with-param name="base.name">
773 <xsl:call-template name="dbhtml-dir"/>
774 <xsl:value-of select="$type"/>
775 <xsl:text>-toc</xsl:text>
776 <xsl:value-of select="$html.ext"/>
777 </xsl:with-param>
778 </xsl:call-template>
779 </xsl:variable>
780
781 <xsl:call-template name="write.chunk">
782 <xsl:with-param name="filename" select="$filename"/>
783 <xsl:with-param name="content">
784 <xsl:call-template name="chunk-element-content">
785 <xsl:with-param name="prev" select="/foo"/>
786 <xsl:with-param name="next" select="/foo"/>
787 <xsl:with-param name="nav.context" select="'toc'"/>
788 <xsl:with-param name="content">
789 <xsl:copy-of select="$lot"/>
790 </xsl:with-param>
791 </xsl:call-template>
792 </xsl:with-param>
793 <xsl:with-param name="quiet" select="$chunk.quietly"/>
794 </xsl:call-template>
795 <!-- And output a link to this file -->
796 <div>
797 <xsl:attribute name="class">
798 <xsl:text>ListofTitles</xsl:text>
799 </xsl:attribute>
800 <a href="{$href}">
801 <xsl:call-template name="gentext">
802 <xsl:with-param name="key">
803 <xsl:choose>
804 <xsl:when test="$type='table'">ListofTables</xsl:when>
805 <xsl:when test="$type='figure'">ListofFigures</xsl:when>
806 <xsl:when test="$type='equation'">ListofEquations</xsl:when>
807 <xsl:when test="$type='example'">ListofExamples</xsl:when>
808 <xsl:when test="$type='procedure'">ListofProcedures</xsl:when>
809 <xsl:otherwise>ListofUnknown</xsl:otherwise>
810 </xsl:choose>
811 </xsl:with-param>
812 </xsl:call-template>
813 </a>
814 </div>
815 </xsl:if>
816</xsl:template>
817
818<!-- ==================================================================== -->
819
820<xsl:template name="in.other.chunk">
821 <xsl:param name="chunk" select="."/>
822 <xsl:param name="node" select="."/>
823
824 <xsl:variable name="is.chunk">
825 <xsl:call-template name="chunk">
826 <xsl:with-param name="node" select="$node"/>
827 </xsl:call-template>
828 </xsl:variable>
829
830<!--
831 <xsl:message>
832 <xsl:text>in.other.chunk: </xsl:text>
833 <xsl:value-of select="name($chunk)"/>
834 <xsl:text> </xsl:text>
835 <xsl:value-of select="name($node)"/>
836 <xsl:text> </xsl:text>
837 <xsl:value-of select="$chunk = $node"/>
838 <xsl:text> </xsl:text>
839 <xsl:value-of select="$is.chunk"/>
840 </xsl:message>
841-->
842
843 <xsl:choose>
844 <xsl:when test="$chunk = $node">0</xsl:when>
845 <xsl:when test="$is.chunk = 1">1</xsl:when>
846 <xsl:when test="count($node) = 0">0</xsl:when>
847 <xsl:otherwise>
848 <xsl:call-template name="in.other.chunk">
849 <xsl:with-param name="chunk" select="$chunk"/>
850 <xsl:with-param name="node" select="$node/parent::*"/>
851 </xsl:call-template>
852 </xsl:otherwise>
853 </xsl:choose>
854</xsl:template>
855
856<xsl:template name="count.footnotes.in.this.chunk">
857 <xsl:param name="node" select="."/>
858 <xsl:param name="footnotes" select="$node//footnote"/>
859 <xsl:param name="count" select="0"/>
860
861<!--
862 <xsl:message>
863 <xsl:text>count.footnotes.in.this.chunk: </xsl:text>
864 <xsl:value-of select="name($node)"/>
865 </xsl:message>
866-->
867
868 <xsl:variable name="in.other.chunk">
869 <xsl:call-template name="in.other.chunk">
870 <xsl:with-param name="chunk" select="$node"/>
871 <xsl:with-param name="node" select="$footnotes[1]"/>
872 </xsl:call-template>
873 </xsl:variable>
874
875 <xsl:choose>
876 <xsl:when test="count($footnotes) = 0">
877 <xsl:value-of select="$count"/>
878 </xsl:when>
879 <xsl:otherwise>
880 <xsl:choose>
881 <xsl:when test="$in.other.chunk != 0">
882 <xsl:call-template name="count.footnotes.in.this.chunk">
883 <xsl:with-param name="node" select="$node"/>
884 <xsl:with-param name="footnotes"
885 select="$footnotes[position() &gt; 1]"/>
886 <xsl:with-param name="count" select="$count"/>
887 </xsl:call-template>
888 </xsl:when>
889 <xsl:when test="$footnotes[1]/ancestor::table
890 |$footnotes[1]/ancestor::informaltable">
891 <xsl:call-template name="count.footnotes.in.this.chunk">
892 <xsl:with-param name="node" select="$node"/>
893 <xsl:with-param name="footnotes"
894 select="$footnotes[position() &gt; 1]"/>
895 <xsl:with-param name="count" select="$count"/>
896 </xsl:call-template>
897 </xsl:when>
898 <xsl:otherwise>
899 <xsl:call-template name="count.footnotes.in.this.chunk">
900 <xsl:with-param name="node" select="$node"/>
901 <xsl:with-param name="footnotes"
902 select="$footnotes[position() &gt; 1]"/>
903 <xsl:with-param name="count" select="$count + 1"/>
904 </xsl:call-template>
905 </xsl:otherwise>
906 </xsl:choose>
907 </xsl:otherwise>
908 </xsl:choose>
909</xsl:template>
910
911<xsl:template name="process.footnotes.in.this.chunk">
912 <xsl:param name="node" select="."/>
913 <xsl:param name="footnotes" select="$node//footnote"/>
914
915<!--
916 <xsl:message>process.footnotes.in.this.chunk</xsl:message>
917-->
918
919 <xsl:variable name="in.other.chunk">
920 <xsl:call-template name="in.other.chunk">
921 <xsl:with-param name="chunk" select="$node"/>
922 <xsl:with-param name="node" select="$footnotes[1]"/>
923 </xsl:call-template>
924 </xsl:variable>
925
926 <xsl:choose>
927 <xsl:when test="count($footnotes) = 0">
928 <!-- nop -->
929 </xsl:when>
930 <xsl:otherwise>
931 <xsl:choose>
932 <xsl:when test="$in.other.chunk != 0">
933 <xsl:call-template name="process.footnotes.in.this.chunk">
934 <xsl:with-param name="node" select="$node"/>
935 <xsl:with-param name="footnotes"
936 select="$footnotes[position() &gt; 1]"/>
937 </xsl:call-template>
938 </xsl:when>
939 <xsl:when test="$footnotes[1]/ancestor::table
940 |$footnotes[1]/ancestor::informaltable">
941 <xsl:call-template name="process.footnotes.in.this.chunk">
942 <xsl:with-param name="node" select="$node"/>
943 <xsl:with-param name="footnotes"
944 select="$footnotes[position() &gt; 1]"/>
945 </xsl:call-template>
946 </xsl:when>
947 <xsl:otherwise>
948 <xsl:apply-templates select="$footnotes[1]"
949 mode="process.footnote.mode"/>
950 <xsl:call-template name="process.footnotes.in.this.chunk">
951 <xsl:with-param name="node" select="$node"/>
952 <xsl:with-param name="footnotes"
953 select="$footnotes[position() &gt; 1]"/>
954 </xsl:call-template>
955 </xsl:otherwise>
956 </xsl:choose>
957 </xsl:otherwise>
958 </xsl:choose>
959</xsl:template>
960
961<xsl:template name="process.footnotes">
962 <xsl:variable name="footnotes" select=".//footnote"/>
963 <xsl:variable name="fcount">
964 <xsl:call-template name="count.footnotes.in.this.chunk">
965 <xsl:with-param name="node" select="."/>
966 <xsl:with-param name="footnotes" select="$footnotes"/>
967 </xsl:call-template>
968 </xsl:variable>
969
970<!--
971 <xsl:message>
972 <xsl:value-of select="name(.)"/>
973 <xsl:text> fcount: </xsl:text>
974 <xsl:value-of select="$fcount"/>
975 </xsl:message>
976-->
977
978 <!-- Only bother to do this if there's at least one non-table footnote -->
979 <xsl:if test="$fcount &gt; 0">
980 <div class="footnotes">
981 <br/>
982 <hr width="100" align="left"/>
983 <xsl:call-template name="process.footnotes.in.this.chunk">
984 <xsl:with-param name="node" select="."/>
985 <xsl:with-param name="footnotes" select="$footnotes"/>
986 </xsl:call-template>
987 </div>
988 </xsl:if>
989
990 <!-- FIXME: When chunking, only the annotations actually used
991 in this chunk should be referenced. I don't think it
992 does any harm to reference them all, but it adds
993 unnecessary bloat to each chunk. -->
994 <xsl:if test="$annotation.support != 0 and //annotation">
995 <div class="annotation-list">
996 <div class="annotation-nocss">
997 <p>The following annotations are from this essay. You are seeing
998 them here because your browser doesn’t support the user-interface
999 techniques used to make them appear as ‘popups’ on modern browsers.</p>
1000 </div>
1001
1002 <xsl:apply-templates select="//annotation"
1003 mode="annotation-popup"/>
1004 </div>
1005 </xsl:if>
1006</xsl:template>
1007
1008<xsl:template name="process.chunk.footnotes">
1009 <xsl:variable name="is.chunk">
1010 <xsl:call-template name="chunk"/>
1011 </xsl:variable>
1012 <xsl:if test="$is.chunk = 1">
1013 <xsl:call-template name="process.footnotes"/>
1014 </xsl:if>
1015</xsl:template>
1016
1017<!-- ====================================================================== -->
1018
1019<!-- Resolve xml:base attributes -->
1020<xsl:template match="@fileref">
1021 <!-- need a check for absolute urls -->
1022 <xsl:choose>
1023 <xsl:when test="contains(., ':')">
1024 <!-- it has a uri scheme so it is an absolute uri -->
1025 <xsl:value-of select="."/>
1026 </xsl:when>
1027 <xsl:otherwise>
1028 <!-- its a relative uri -->
1029 <xsl:call-template name="relative-uri">
1030 <xsl:with-param name="destdir">
1031 <xsl:call-template name="dbhtml-dir">
1032 <xsl:with-param name="context" select=".."/>
1033 </xsl:call-template>
1034 </xsl:with-param>
1035 </xsl:call-template>
1036 </xsl:otherwise>
1037 </xsl:choose>
1038</xsl:template>
1039
1040</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.