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
<xsl:param name="html.ext" select="'.html'"/>
7
<doc:param name="html.ext" xmlns="">
8
<refpurpose>Extension for chunked files</refpurpose>
10
<para>The extension identified by <parameter>html.ext</parameter> will
11
be used as the filename extension for chunks created by this stylesheet.
16
<xsl:param name="root.filename" select="'index'"/>
17
<doc:param name="root.filename" xmlns="">
18
<refpurpose>Filename for the root chunk</refpurpose>
20
<para>The <parameter>root.filename</parameter> is the base filename for
21
the chunk created for the root of each document processed.
26
<xsl:param name="base.dir" select="''"/>
27
<doc:param name="base.dir" xmlns="">
28
<refpurpose>Output directory for chunks</refpurpose>
30
<para>If specified, the <literal>base.dir</literal> identifies
31
the output directory for chunks. (If not specified, the output directory
32
is system dependent.)</para>
36
<xsl:param name="chunk.sections" select="'1'"/>
37
<doc:param name="chunk.sections" xmlns="">
38
<refpurpose>Create chunks for top-level sections in components?</refpurpose>
40
<para>If non-zero, chunks will be created for top-level
41
<sgmltag>sect1</sgmltag> and <sgmltag>section</sgmltag> elements in
47
<xsl:param name="chunk.first.sections" select="'0'"/>
48
<doc:param name="chunk.first.sections" xmlns="">
49
<refpurpose>Create a chunk for the first top-level section in each component?</refpurpose>
51
<para>If non-zero, a chunk will be created for the first top-level
52
<sgmltag>sect1</sgmltag> or <sgmltag>section</sgmltag> elements in
53
each component. Otherwise, that section will be part of the chunk for
59
<xsl:param name="chunk.datafile" select="'.chunks'"/>
60
<doc:param name="chunk.datafile" xmlns="">
61
<refpurpose>Name of the temporary file used to hold chunking data</refpurpose>
63
<para>Chunking is now a two-step process. The
64
<parameter>chunk.datafile</parameter> is the name of the file used to
65
hold the chunking data.
70
<!-- ==================================================================== -->
75
bibliography in article or book
79
glossary in article or book
80
index in article or book
86
section if position()>1 && parent != section
90
<!-- ==================================================================== -->
92
<xsl:template name="chunk">
93
<xsl:param name="node" select="."/>
94
<!-- returns 1 if $node is a chunk -->
96
<xsl:variable name="id">
98
<xsl:when test="$node/@id">
99
<xsl:value-of select="$node/@id"/>
102
<xsl:value-of select="generate-id($node)"/>
107
<xsl:variable name="chunks" select="document($chunk.datafile,.)"/>
110
<xsl:when test="$chunks/chunks/chunk[@id=$id]">1</xsl:when>
111
<xsl:otherwise>0</xsl:otherwise>
115
<!-- ==================================================================== -->
117
<xsl:template match="*" mode="chunk-filename">
118
<!-- returns the filename of a chunk -->
120
<xsl:variable name="id">
122
<xsl:when test="@id">
123
<xsl:value-of select="@id"/>
126
<xsl:value-of select="generate-id(.)"/>
131
<xsl:variable name="chunks" select="document($chunk.datafile,.)"/>
132
<xsl:variable name="chunk" select="$chunks/chunks/chunk[@id=$id]"/>
135
<xsl:when test="$chunk">
136
<xsl:value-of select="$chunk/@filename"/>
139
<xsl:apply-templates select="parent::*" mode="chunk-filename"/>
144
<!-- ==================================================================== -->
146
<xsl:template name="href.target">
147
<xsl:param name="object" select="."/>
148
<xsl:variable name="ischunk">
149
<xsl:call-template name="chunk">
150
<xsl:with-param name="node" select="$object"/>
154
<xsl:apply-templates mode="chunk-filename" select="$object"/>
156
<xsl:if test="$ischunk='0'">
157
<xsl:text>#</xsl:text>
158
<xsl:call-template name="object.id">
159
<xsl:with-param name="object" select="$object"/>
164
<!-- ==================================================================== -->
166
<xsl:template name="html.head">
167
<xsl:param name="prev" select="/foo"/>
168
<xsl:param name="next" select="/foo"/>
169
<xsl:variable name="home" select="/*[1]"/>
170
<xsl:variable name="up" select="parent::*"/>
173
<xsl:call-template name="head.content"/>
174
<xsl:call-template name="user.head.content"/>
176
<xsl:if test="$home">
178
<xsl:attribute name="href">
179
<xsl:call-template name="href.target">
180
<xsl:with-param name="object" select="$home"/>
183
<xsl:attribute name="title">
184
<xsl:apply-templates select="$home"
185
mode="object.title.markup.textonly"/>
192
<xsl:attribute name="href">
193
<xsl:call-template name="href.target">
194
<xsl:with-param name="object" select="$up"/>
197
<xsl:attribute name="title">
198
<xsl:apply-templates select="$up" mode="object.title.markup.textonly"/>
203
<xsl:if test="$prev">
204
<link rel="previous">
205
<xsl:attribute name="href">
206
<xsl:call-template name="href.target">
207
<xsl:with-param name="object" select="$prev"/>
210
<xsl:attribute name="title">
211
<xsl:apply-templates select="$prev" mode="object.title.markup.textonly"/>
216
<xsl:if test="$next">
218
<xsl:attribute name="href">
219
<xsl:call-template name="href.target">
220
<xsl:with-param name="object" select="$next"/>
223
<xsl:attribute name="title">
224
<xsl:apply-templates select="$next" mode="object.title.markup.textonly"/>
231
<!-- ==================================================================== -->
233
<xsl:template name="header.navigation">
234
<xsl:param name="prev" select="/foo"/>
235
<xsl:param name="next" select="/foo"/>
236
<xsl:variable name="home" select="/*[1]"/>
237
<xsl:variable name="up" select="parent::*"/>
239
<xsl:if test="$suppress.navigation = '0'">
240
<div class="navheader">
241
<table width="100%" summary="Navigation header">
243
<th colspan="3" align="center">
244
<xsl:apply-templates select="." mode="object.title.markup"/>
248
<td width="20%" align="left">
249
<xsl:if test="count($prev)>0">
251
<xsl:attribute name="href">
252
<xsl:call-template name="href.target">
253
<xsl:with-param name="object" select="$prev"/>
256
<xsl:call-template name="gentext">
257
<xsl:with-param name="key">nav-prev</xsl:with-param>
261
<xsl:text> </xsl:text>
263
<th width="60%" align="center">
265
<xsl:when test="count($up) > 0 and $up != $home">
266
<xsl:apply-templates select="$up" mode="object.title.markup"/>
268
<xsl:otherwise> </xsl:otherwise>
271
<td width="20%" align="right">
272
<xsl:text> </xsl:text>
273
<xsl:if test="count($next)>0">
275
<xsl:attribute name="href">
276
<xsl:call-template name="href.target">
277
<xsl:with-param name="object" select="$next"/>
280
<xsl:call-template name="gentext">
281
<xsl:with-param name="key">nav-next</xsl:with-param>
293
<!-- ==================================================================== -->
295
<xsl:template name="footer.navigation">
296
<xsl:param name="prev" select="/foo"/>
297
<xsl:param name="next" select="/foo"/>
298
<xsl:variable name="home" select="/*[1]"/>
299
<xsl:variable name="up" select="parent::*"/>
301
<xsl:if test="$suppress.navigation = '0'">
302
<div class="navfooter">
304
<table width="100%" summary="Navigation footer">
306
<td width="40%" align="left">
307
<xsl:if test="count($prev)>0">
309
<xsl:attribute name="href">
310
<xsl:call-template name="href.target">
311
<xsl:with-param name="object" select="$prev"/>
314
<xsl:call-template name="gentext">
315
<xsl:with-param name="key">nav-prev</xsl:with-param>
319
<xsl:text> </xsl:text>
321
<td width="20%" align="center">
323
<xsl:when test="$home != .">
325
<xsl:attribute name="href">
326
<xsl:call-template name="href.target">
327
<xsl:with-param name="object" select="$home"/>
330
<xsl:call-template name="gentext">
331
<xsl:with-param name="key">nav-home</xsl:with-param>
335
<xsl:otherwise> </xsl:otherwise>
338
<td width="40%" align="right">
339
<xsl:text> </xsl:text>
340
<xsl:if test="count($next)>0">
342
<xsl:attribute name="href">
343
<xsl:call-template name="href.target">
344
<xsl:with-param name="object" select="$next"/>
347
<xsl:call-template name="gentext">
348
<xsl:with-param name="key">nav-next</xsl:with-param>
356
<td width="40%" align="left">
357
<xsl:apply-templates select="$prev" mode="object.title.markup"/>
358
<xsl:text> </xsl:text>
360
<td width="20%" align="center">
362
<xsl:when test="count($up)>0">
364
<xsl:attribute name="href">
365
<xsl:call-template name="href.target">
366
<xsl:with-param name="object" select="$up"/>
369
<xsl:call-template name="gentext">
370
<xsl:with-param name="key">nav-up</xsl:with-param>
374
<xsl:otherwise> </xsl:otherwise>
377
<td width="40%" align="right">
378
<xsl:text> </xsl:text>
379
<xsl:apply-templates select="$next" mode="object.title.markup"/>
387
<!-- ==================================================================== -->
389
<xsl:template match="processing-instruction('dbhtml')">
393
<!-- ==================================================================== -->
395
<xsl:template name="process-chunk">
396
<xsl:variable name="id">
398
<xsl:when test="@id">
399
<xsl:value-of select="@id"/>
402
<xsl:value-of select="generate-id(.)"/>
407
<xsl:variable name="chunks" select="document($chunk.datafile,.)"/>
409
<xsl:variable name="chunk" select="$chunks/chunks/chunk[@id=$id]"/>
410
<xsl:variable name="prev-id"
411
select="$chunk/preceding-sibling::chunk[1]/@id"/>
412
<xsl:variable name="next-id"
413
select="$chunk/following-sibling::chunk[1]/@id"/>
415
<xsl:variable name="prev" select="id($prev-id)"/>
416
<xsl:variable name="next" select="id($next-id)"/>
418
<xsl:variable name="ischunk">
419
<xsl:call-template name="chunk"/>
422
<xsl:variable name="chunkfn">
423
<xsl:if test="$ischunk='1'">
424
<xsl:apply-templates mode="chunk-filename" select="."/>
428
<xsl:if test="$ischunk='0'">
430
<xsl:text>Error </xsl:text>
431
<xsl:value-of select="name(.)"/>
432
<xsl:text> is not a chunk!</xsl:text>
436
<xsl:variable name="filename">
437
<xsl:call-template name="make-relative-filename">
438
<xsl:with-param name="base.dir" select="$base.dir"/>
439
<xsl:with-param name="base.name" select="$chunkfn"/>
443
<xsl:call-template name="write.chunk">
444
<xsl:with-param name="filename" select="$filename"/>
445
<xsl:with-param name="content">
446
<xsl:call-template name="chunk-element-content">
447
<xsl:with-param name="prev" select="$prev"/>
448
<xsl:with-param name="next" select="$next"/>
454
<xsl:template name="chunk-element-content">
455
<xsl:param name="prev"></xsl:param>
456
<xsl:param name="next"></xsl:param>
459
<xsl:call-template name="html.head">
460
<xsl:with-param name="prev" select="$prev"/>
461
<xsl:with-param name="next" select="$next"/>
465
<xsl:call-template name="body.attributes"/>
466
<xsl:call-template name="user.header.navigation"/>
468
<xsl:call-template name="header.navigation">
469
<xsl:with-param name="prev" select="$prev"/>
470
<xsl:with-param name="next" select="$next"/>
473
<xsl:call-template name="user.header.content"/>
477
<xsl:call-template name="user.footer.content"/>
479
<xsl:call-template name="footer.navigation">
480
<xsl:with-param name="prev" select="$prev"/>
481
<xsl:with-param name="next" select="$next"/>
484
<xsl:call-template name="user.footer.navigation"/>
489
<!-- ==================================================================== -->
491
<xsl:template match="set">
492
<xsl:call-template name="process-chunk"/>
495
<xsl:template match="book">
496
<xsl:call-template name="process-chunk"/>
499
<xsl:template match="book/appendix">
500
<xsl:call-template name="process-chunk"/>
503
<xsl:template match="book/glossary">
504
<xsl:call-template name="process-chunk"/>
507
<xsl:template match="book/bibliography">
508
<xsl:call-template name="process-chunk"/>
511
<xsl:template match="preface|chapter">
512
<xsl:call-template name="process-chunk"/>
515
<xsl:template match="part|reference">
516
<xsl:call-template name="process-chunk"/>
519
<xsl:template match="refentry">
520
<xsl:call-template name="process-chunk"/>
523
<xsl:template match="colophon">
524
<xsl:call-template name="process-chunk"/>
527
<xsl:template match="article">
528
<xsl:call-template name="process-chunk"/>
531
<xsl:template match="article/appendix">
532
<xsl:call-template name="process-chunk"/>
535
<xsl:template match="article/glossary">
536
<xsl:call-template name="process-chunk"/>
539
<xsl:template match="article/bibliography">
540
<xsl:call-template name="process-chunk"/>
543
<xsl:template match="sect1
545
|section[local-name(parent::*) != 'section']">
547
<xsl:when test=". = /section">
548
<xsl:call-template name="process-chunk"/>
550
<xsl:when test="$chunk.sections = 0">
553
<xsl:when test="ancestor::partintro">
556
<xsl:when test="$chunk.first.sections = 0">
558
<xsl:when test="count(preceding-sibling::section) > 0
559
or count(preceding-sibling::sect1) > 0">
560
<xsl:call-template name="process-chunk"/>
568
<xsl:call-template name="process-chunk"/>
573
<xsl:template match="setindex
576
<!-- some implementations use completely empty index tags to indicate -->
577
<!-- where an automatically generated index should be inserted. so -->
578
<!-- if the index is completely empty, skip it. -->
579
<xsl:if test="count(*)>0 or $generate.index != '0'">
580
<xsl:call-template name="process-chunk"/>
584
<!-- ==================================================================== -->
586
<xsl:template match="/">
588
<xsl:when test="$rootid != ''">
590
<xsl:when test="count(id($rootid)) = 0">
591
<xsl:message terminate="yes">
592
<xsl:text>ID '</xsl:text>
593
<xsl:value-of select="$rootid"/>
594
<xsl:text>' not found in document.</xsl:text>
598
<xsl:apply-templates select="id($rootid)"/>
603
<xsl:apply-templates select="/" mode="process.root"/>
608
<xsl:template match="*" mode="process.root">
609
<xsl:apply-templates select="."/>
612
<!-- ==================================================================== -->
614
<xsl:template name="in.other.chunk">
615
<xsl:param name="chunk" select="."/>
616
<xsl:param name="node" select="."/>
618
<xsl:variable name="is.chunk">
619
<xsl:call-template name="chunk">
620
<xsl:with-param name="node" select="$node"/>
626
<xsl:text>in.other.chunk: </xsl:text>
627
<xsl:value-of select="name($chunk)"/>
628
<xsl:text> </xsl:text>
629
<xsl:value-of select="name($node)"/>
630
<xsl:text> </xsl:text>
631
<xsl:value-of select="$chunk = $node"/>
632
<xsl:text> </xsl:text>
633
<xsl:value-of select="$is.chunk"/>
638
<xsl:when test="$chunk = $node">0</xsl:when>
639
<xsl:when test="$is.chunk = 1">1</xsl:when>
640
<xsl:when test="count($node) = 0">0</xsl:when>
642
<xsl:call-template name="in.other.chunk">
643
<xsl:with-param name="chunk" select="$chunk"/>
644
<xsl:with-param name="node" select="$node/parent::*"/>
650
<xsl:template name="count.footnotes.in.this.chunk">
651
<xsl:param name="node" select="."/>
652
<xsl:param name="footnotes" select="$node//footnote"/>
653
<xsl:param name="count" select="0"/>
657
<xsl:text>count.footnotes.in.this.chunk: </xsl:text>
658
<xsl:value-of select="name($node)"/>
662
<xsl:variable name="in.other.chunk">
663
<xsl:call-template name="in.other.chunk">
664
<xsl:with-param name="chunk" select="$node"/>
665
<xsl:with-param name="node" select="$footnotes[1]"/>
670
<xsl:when test="count($footnotes) = 0">
671
<xsl:value-of select="$count"/>
675
<xsl:when test="$in.other.chunk != 0">
676
<xsl:call-template name="count.footnotes.in.this.chunk">
677
<xsl:with-param name="node" select="$node"/>
678
<xsl:with-param name="footnotes"
679
select="$footnotes[position() > 1]"/>
680
<xsl:with-param name="count" select="$count"/>
683
<xsl:when test="$footnotes[1]/ancestor::table
684
|$footnotes[1]/ancestor::informaltable">
685
<xsl:call-template name="count.footnotes.in.this.chunk">
686
<xsl:with-param name="node" select="$node"/>
687
<xsl:with-param name="footnotes"
688
select="$footnotes[position() > 1]"/>
689
<xsl:with-param name="count" select="$count"/>
693
<xsl:call-template name="count.footnotes.in.this.chunk">
694
<xsl:with-param name="node" select="$node"/>
695
<xsl:with-param name="footnotes"
696
select="$footnotes[position() > 1]"/>
697
<xsl:with-param name="count" select="$count + 1"/>
705
<xsl:template name="process.footnotes.in.this.chunk">
706
<xsl:param name="node" select="."/>
707
<xsl:param name="footnotes" select="$node//footnote"/>
710
<xsl:message>process.footnotes.in.this.chunk</xsl:message>
713
<xsl:variable name="in.other.chunk">
714
<xsl:call-template name="in.other.chunk">
715
<xsl:with-param name="chunk" select="$node"/>
716
<xsl:with-param name="node" select="$footnotes[1]"/>
721
<xsl:when test="count($footnotes) = 0">
726
<xsl:when test="$in.other.chunk != 0">
727
<xsl:call-template name="process.footnotes.in.this.chunk">
728
<xsl:with-param name="node" select="$node"/>
729
<xsl:with-param name="footnotes"
730
select="$footnotes[position() > 1]"/>
733
<xsl:when test="$footnotes[1]/ancestor::table
734
|$footnotes[1]/ancestor::informaltable">
735
<xsl:call-template name="process.footnotes.in.this.chunk">
736
<xsl:with-param name="node" select="$node"/>
737
<xsl:with-param name="footnotes"
738
select="$footnotes[position() > 1]"/>
742
<xsl:apply-templates select="$footnotes[1]"
743
mode="process.footnote.mode"/>
744
<xsl:call-template name="process.footnotes.in.this.chunk">
745
<xsl:with-param name="node" select="$node"/>
746
<xsl:with-param name="footnotes"
747
select="$footnotes[position() > 1]"/>
755
<xsl:template name="process.footnotes">
756
<xsl:variable name="footnotes" select=".//footnote"/>
757
<xsl:variable name="fcount">
758
<xsl:call-template name="count.footnotes.in.this.chunk">
759
<xsl:with-param name="node" select="."/>
760
<xsl:with-param name="footnotes" select="$footnotes"/>
766
<xsl:value-of select="name(.)"/>
767
<xsl:text> fcount: </xsl:text>
768
<xsl:value-of select="$fcount"/>
772
<!-- Only bother to do this if there's at least one non-table footnote -->
773
<xsl:if test="$fcount > 0">
774
<div class="footnotes">
776
<hr width="100" align="left"/>
777
<xsl:call-template name="process.footnotes.in.this.chunk">
778
<xsl:with-param name="node" select="."/>
779
<xsl:with-param name="footnotes" select="$footnotes"/>
785
<xsl:template name="process.chunk.footnotes">
786
<xsl:variable name="is.chunk">
787
<xsl:call-template name="chunk"/>
789
<xsl:if test="$is.chunk = 1">
790
<xsl:call-template name="process.footnotes"/>
794
<!-- ==================================================================== -->