1
<?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
3
This program is free software; you can redistribute it and/or modify it under
4
the terms of the GNU Lesser General Public License as published by the Free
5
Software Foundation; either version 2 of the License, or (at your option) any
8
This program is distributed in the hope that it will be useful, but WITHOUT
9
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13
You should have received a copy of the GNU Lesser General Public License
14
along with this program; see the file COPYING.LGPL. If not, write to the
15
Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
20
xmlns:exsl="http://exslt.org/common"
21
xmlns:set="http://exslt.org/sets"
22
xmlns:db="http://docbook.org/ns/docbook"
23
extension-element-prefixes="exsl"
24
exclude-result-prefixes="db set"
27
<!--!!==========================================================================
30
REMARK: Describe this module
34
<!--@@==========================================================================
36
A space-seperated list of the names of elements that should be chunked
38
REMARK: This parameter sucks
40
<xsl:param name="db.chunk.chunks" select="
41
'appendix article bibliography bibliodiv book chapter
42
colophon dedication glossary glossdiv index
43
lot part preface refentry reference
44
sect1 sect2 sect3 sect4 sect5
45
section setindex simplesect toc'"/>
46
<xsl:variable name="db.chunk.chunks_" select="concat(' ', $db.chunk.chunks, ' ')"/>
49
<!--@@==========================================================================
51
Whether the top-level chunk should be output with the chunking mechanism
53
REMARK: Describe what this does
55
<xsl:param name="db.chunk.chunk_top" select="false()"/>
58
<!--@@==========================================================================
60
The maximum depth for chunking sections
62
REMARK: Describe what this does
64
<xsl:param name="db.chunk.max_depth">
66
<xsl:when test="number(processing-instruction('db.chunk.max_depth'))">
68
select="number(processing-instruction('db.chunk.max_depth'))"/>
70
<xsl:when test="/book | /db:book">
71
<xsl:value-of select="2"/>
74
<xsl:value-of select="1"/>
80
<!--@@==========================================================================
82
The base filename of the output file, without an extension
84
REMARK: Describe what this does
86
<xsl:param name="db.chunk.basename" select="/*/@id | /*/@xml:id"/>
89
<!--@@==========================================================================
91
The default file extension for new output documents
93
REMARK: Describe what this does
95
<xsl:param name="db.chunk.extension"/>
98
<!--@@==========================================================================
100
Whether to create a chunk for the title page
102
REMARK: Describe what this does
104
<xsl:param name="db.chunk.info_chunk" select="$db.chunk.max_depth != 0"/>
107
<!--@@==========================================================================
108
db.chunk.info_basename
109
The base filename for the title page
111
REMARK: Describe what this does
113
<xsl:param name="db.chunk.info_basename">
115
<xsl:when test="$db.chunk.basename">
116
<xsl:value-of select="concat($db.chunk.basename, '-info')"/>
118
<xsl:otherwise>info</xsl:otherwise>
123
<!--@@==========================================================================
124
db.chunk.doctype_public
125
The public DOCTYPE for output files
127
REMARK: Describe this
129
<xsl:param name="db.chunk.doctype_public"/>
132
<!--@@==========================================================================
133
db.chunk.doctype_system
134
The system DOCTYPE for output files
136
REMARK: Describe this
138
<xsl:param name="db.chunk.doctype_system"/>
141
<!--**==========================================================================
143
Creates a new page of output
144
$node: The source element for the output page
145
$template: The named template to call to create the page
146
$href: The name of the file for the output page
147
$depth_of_chunk: The depth of this chunk in the document
149
REMARK: We need a lot more explanation about chunk flow
151
The *{db.chunk} template creates a new output document using the #{exsl:document}
152
extension element. This template calls *{db.chunk.content} to create the content
153
of the document, passing through all parameters. This allows you to override the
154
chunking mechanism without having to duplicate the content-generation code.
156
<xsl:template name="db.chunk">
157
<xsl:param name="node" select="."/>
158
<xsl:param name="template"/>
159
<xsl:param name="href">
161
<xsl:when test="$template = 'info'">
162
<xsl:value-of select="$db.chunk.info_basename"/>
165
<xsl:call-template name="db.chunk.chunk-id">
166
<xsl:with-param name="node" select="$node"/>
167
<xsl:with-param name="depth_in_chunk" select="0"/>
168
<xsl:with-param name="chunk" select="$node"/>
172
<xsl:value-of select="$db.chunk.extension"/>
174
<xsl:param name="depth_of_chunk">
175
<xsl:call-template name="db.chunk.depth-of-chunk">
176
<xsl:with-param name="node" select="$node"/>
179
<exsl:document href="{$href}"
180
doctype-public="{$db.chunk.doctype_public}"
181
doctype-system="{$db.chunk.doctype_system}">
182
<xsl:call-template name="db.chunk.content">
183
<xsl:with-param name="node" select="$node"/>
184
<xsl:with-param name="template" select="$template"/>
185
<xsl:with-param name="depth_of_chunk" select="$depth_of_chunk"/>
189
<xsl:if test="string($template) = ''">
190
<xsl:call-template name="db.chunk.children">
191
<xsl:with-param name="node" select="$node"/>
192
<xsl:with-param name="depth_of_chunk" select="$depth_of_chunk"/>
199
<!--**==========================================================================
201
Creates the content of a new page of output
202
$node: The source element for the output page
203
$template: The named template to call to create the page
204
$depth_of_chunk: The depth of this chunk in the document
206
REMARK: We need a lot more explanation about chunk flow
208
The *{db.chunk.content} template creates the actual content of a new output page.
209
It should generally only be called by *{db.chunk}.
211
This template will always pass the ${depth_in_chunk} and ${depth_of_chunk}
212
parameters with appropriate values to the templates it calls.
214
<xsl:template name="db.chunk.content">
215
<xsl:param name="node" select="."/>
216
<xsl:param name="template"/>
217
<xsl:param name="depth_of_chunk">
218
<xsl:call-template name="db.chunk.depth-of-chunk">
219
<xsl:with-param name="node" select="$node"/>
223
<xsl:when test="$template = 'info'">
224
<xsl:apply-templates mode="db.chunk.info.content.mode" select="$node">
225
<xsl:with-param name="depth_in_chunk" select="0"/>
226
<xsl:with-param name="depth_of_chunk" select="$depth_of_chunk"/>
227
</xsl:apply-templates>
230
<xsl:apply-templates mode="db.chunk.content.mode" select="$node">
231
<xsl:with-param name="depth_in_chunk" select="0"/>
232
<xsl:with-param name="depth_of_chunk" select="$depth_of_chunk"/>
233
</xsl:apply-templates>
240
<!--**==========================================================================
241
db.chunk.depth-in-chunk
242
Determines the depth of an element in the containing chunk
243
$node: The element to determine the depth of
245
REMARK: Explain how this works
247
<xsl:template name="db.chunk.depth-in-chunk">
248
<xsl:param name="node" select="."/>
249
<xsl:variable name="divs"
251
count($node/ancestor-or-self::appendix ) +
252
count($node/ancestor-or-self::article ) +
253
count($node/ancestor-or-self::bibliography ) +
254
count($node/ancestor-or-self::bibliodiv ) +
255
count($node/ancestor-or-self::book ) +
256
count($node/ancestor-or-self::chapter ) +
257
count($node/ancestor-or-self::colophon ) +
258
count($node/ancestor-or-self::dedication ) +
259
count($node/ancestor-or-self::glossary ) +
260
count($node/ancestor-or-self::glossdiv ) +
261
count($node/ancestor-or-self::index ) +
262
count($node/ancestor-or-self::lot ) +
263
count($node/ancestor-or-self::part ) +
264
count($node/ancestor-or-self::preface ) +
265
count($node/ancestor-or-self::refentry ) +
266
count($node/ancestor-or-self::reference ) +
267
count($node/ancestor-or-self::sect1 ) +
268
count($node/ancestor-or-self::sect2 ) +
269
count($node/ancestor-or-self::sect3 ) +
270
count($node/ancestor-or-self::sect4 ) +
271
count($node/ancestor-or-self::sect5 ) +
272
count($node/ancestor-or-self::section ) +
273
count($node/ancestor-or-self::setindex ) +
274
count($node/ancestor-or-self::simplesect ) +
275
count($node/ancestor-or-self::toc ) +
276
count($node/ancestor-or-self::db:appendix ) +
277
count($node/ancestor-or-self::db:article ) +
278
count($node/ancestor-or-self::db:bibliography ) +
279
count($node/ancestor-or-self::db:bibliodiv ) +
280
count($node/ancestor-or-self::db:book ) +
281
count($node/ancestor-or-self::db:chapter ) +
282
count($node/ancestor-or-self::db:colophon ) +
283
count($node/ancestor-or-self::db:dedication ) +
284
count($node/ancestor-or-self::db:glossary ) +
285
count($node/ancestor-or-self::db:glossdiv ) +
286
count($node/ancestor-or-self::db:index ) +
287
count($node/ancestor-or-self::db:lot ) +
288
count($node/ancestor-or-self::db:part ) +
289
count($node/ancestor-or-self::db:preface ) +
290
count($node/ancestor-or-self::db:refentry ) +
291
count($node/ancestor-or-self::db:reference ) +
292
count($node/ancestor-or-self::db:sect1 ) +
293
count($node/ancestor-or-self::db:sect2 ) +
294
count($node/ancestor-or-self::db:sect3 ) +
295
count($node/ancestor-or-self::db:sect4 ) +
296
count($node/ancestor-or-self::db:sect5 ) +
297
count($node/ancestor-or-self::db:section ) +
298
count($node/ancestor-or-self::db:setindex ) +
299
count($node/ancestor-or-self::db:simplesect ) +
300
count($node/ancestor-or-self::db:toc )"/>
302
<xsl:when test="$divs < ($db.chunk.max_depth + 1)">
303
<xsl:value-of select="count($node/ancestor-or-self::*) - $divs"/>
306
<xsl:value-of select="count($node/ancestor::*) - $db.chunk.max_depth"/>
312
<!--**==========================================================================
313
db.chunk.depth-of-chunk
314
Determines the depth of teh containing chunk in the document
315
$node: The element to determine the depth of
317
REMARK: Explain how this works
319
<xsl:template name="db.chunk.depth-of-chunk">
320
<xsl:param name="node" select="."/>
321
<xsl:variable name="divs"
322
select="$node/ancestor-or-self::*
323
[contains($db.chunk.chunks_,
324
concat(' ', local-name(.), ' '))]"/>
326
<xsl:when test="count($divs) - 1 < $db.chunk.max_depth">
327
<xsl:value-of select="count($divs) - 1"/>
330
<xsl:value-of select="$db.chunk.max_depth"/>
336
<!--**==========================================================================
338
Determines the id of the chunk that contains an element
339
$id: The id of the element to determine the chunk id of
340
$node: The element to determine the chunk id of
341
$depth_in_chunk: The depth of ${node} in the containing chunk
343
REMARK: Explain how this works
345
<xsl:template name="db.chunk.chunk-id">
346
<xsl:param name="id" select="@id | @xml:id"/>
347
<xsl:param name="node" select="key('idkey', $id)"/>
348
<xsl:param name="depth_in_chunk">
349
<xsl:call-template name="db.chunk.depth-in-chunk">
350
<xsl:with-param name="node" select="$node"/>
353
<xsl:param name="chunk" select="$node/ancestor-or-self::*[$depth_in_chunk + 1]"/>
355
<xsl:when test="set:has-same-node($chunk, /*)">
356
<xsl:value-of select="$db.chunk.basename"/>
358
<xsl:when test="$chunk/@id">
359
<xsl:value-of select="string($chunk/@id)"/>
361
<xsl:when test="$chunk/@xml:id">
362
<xsl:value-of select="string($chunk/@xml:id)"/>
365
<xsl:value-of select="generate-id($chunk)"/>
371
<!--**==========================================================================
372
db.chunk.chunk-id.axis
373
Determines the id of the first chunk along a specified axis
374
$node: The base element
375
$node: The axis along which to find the first chunk
376
$depth_in_chunk: The depth of ${node} in the containing chunk
377
$depth_of_chunk: The depth of the containing chunk in the document
379
REMARK: Explain how this works, and what the axes are
381
<xsl:template name="db.chunk.chunk-id.axis">
382
<xsl:param name="node" select="."/>
383
<xsl:param name="axis"/>
384
<xsl:param name="depth_in_chunk">
385
<xsl:call-template name="db.chunk.depth-in-chunk">
386
<xsl:with-param name="node" select="$node"/>
389
<xsl:param name="depth_of_chunk">
390
<xsl:call-template name="db.chunk.depth-of-chunk">
391
<xsl:with-param name="node" select="$node"/>
395
<xsl:when test="depth_in_chunk != 0">
396
<xsl:call-template name="db.chunk.chunk-id.axis">
397
<xsl:with-param name="node" select="$node/ancestor::*[$depth_in_chunk]"/>
398
<xsl:with-param name="axis" select="$axis"/>
399
<xsl:with-param name="depth_in_chunk" select="0"/>
400
<xsl:with-param name="depth_of_chunk" select="$depth_of_chunk"/>
404
<xsl:when test="$axis = 'following'">
405
<xsl:variable name="divs"
406
select="$node/following-sibling::*
407
[contains($db.chunk.chunks_,
408
concat(' ', local-name(.), ' '))]"/>
410
<xsl:when test="$divs">
411
<xsl:call-template name="db.chunk.chunk-id">
412
<xsl:with-param name="node" select="$divs[1]"/>
413
<xsl:with-param name="depth_in_chunk" select="0"/>
414
<xsl:with-param name="chunk" select="$divs[1]"/>
417
<xsl:when test="$node/..">
418
<xsl:call-template name="db.chunk.chunk-id.axis">
419
<xsl:with-param name="node" select="$node/.."/>
420
<xsl:with-param name="axis" select="'following'"/>
421
<xsl:with-param name="depth_in_chunk" select="0"/>
422
<xsl:with-param name="depth_of_chunk" select="$depth_of_chunk - 1"/>
427
<!-- last-descendant -->
428
<xsl:when test="$axis = 'last-descendant'">
429
<xsl:variable name="divs"
430
select="$node/*[contains($db.chunk.chunks_,
431
concat(' ', local-name(.), ' '))]"/>
433
<xsl:when test="($depth_of_chunk >= $db.chunk.max_depth)">
434
<xsl:call-template name="db.chunk.chunk-id">
435
<xsl:with-param name="node" select="$node"/>
436
<xsl:with-param name="depth_in_chunk" select="0"/>
437
<xsl:with-param name="chunk" select="$node"/>
440
<xsl:when test="($depth_of_chunk + 1 = $db.chunk.max_depth) and $divs">
441
<xsl:call-template name="db.chunk.chunk-id">
442
<xsl:with-param name="node" select="$divs[last()]"/>
443
<xsl:with-param name="depth_in_chunk" select="0"/>
444
<xsl:with-param name="chunk" select="$divs[last()]"/>
447
<xsl:when test="$divs">
448
<xsl:call-template name="db.chunk.chunk-id.axis">
449
<xsl:with-param name="node" select="$divs[last()]"/>
450
<xsl:with-param name="axis" select="'last-descendant'"/>
451
<xsl:with-param name="depth_in_chunk" select="0"/>
452
<xsl:with-param name="depth_of_chunk" select="$depth_of_chunk + 1"/>
456
<xsl:call-template name="db.chunk.chunk-id">
457
<xsl:with-param name="node" select="$node"/>
458
<xsl:with-param name="depth_in_chunk" select="0"/>
459
<xsl:with-param name="chunk" select="$node"/>
465
<xsl:when test="$axis = 'next'">
466
<xsl:variable name="divs"
467
select="$node/*[contains($db.chunk.chunks_,
468
concat(' ', local-name(.), ' '))]"/>
470
<xsl:when test="($depth_of_chunk < $db.chunk.max_depth) and $divs">
471
<xsl:call-template name="db.chunk.chunk-id">
472
<xsl:with-param name="node" select="$divs[1]"/>
473
<xsl:with-param name="depth_in_chunk" select="0"/>
474
<xsl:with-param name="chunk" select="$divs[1]"/>
478
<xsl:call-template name="db.chunk.chunk-id.axis">
479
<xsl:with-param name="node" select="$node"/>
480
<xsl:with-param name="axis" select="'following'"/>
481
<xsl:with-param name="depth_in_chunk" select="$depth_in_chunk"/>
482
<xsl:with-param name="depth_of_chunk" select="$depth_of_chunk"/>
488
<xsl:when test="$axis = 'previous'">
489
<xsl:variable name="divs"
490
select="$node/preceding-sibling::*
491
[contains($db.chunk.chunks_,
492
concat(' ', local-name(.), ' '))]"/>
494
<xsl:when test="$divs and ($depth_of_chunk < $db.chunk.max_depth)">
495
<xsl:call-template name="db.chunk.chunk-id.axis">
496
<xsl:with-param name="node" select="$divs[last()]"/>
497
<xsl:with-param name="axis" select="'last-descendant'"/>
498
<xsl:with-param name="depth_in_chunk" select="$depth_in_chunk"/>
499
<xsl:with-param name="depth_of_chunk" select="$depth_of_chunk"/>
502
<xsl:when test="$divs">
503
<xsl:call-template name="db.chunk.chunk-id">
504
<xsl:with-param name="node" select="$divs[last()]"/>
505
<xsl:with-param name="depth_in_chunk" select="0"/>
506
<xsl:with-param name="chunk" select="$divs[last()]"/>
509
<xsl:when test="$node/..">
510
<xsl:call-template name="db.chunk.chunk-id">
511
<xsl:with-param name="node" select="$node"/>
512
<xsl:with-param name="depth_in_chunk" select="0"/>
513
<xsl:with-param name="chunk" select="$node"/>
521
<xsl:text>Unsupported axis: </xsl:text>
522
<xsl:value-of select="$axis"/>
529
<!--%%==========================================================================
530
db.chunk.info.content.mode
531
Renders the contents of the title page
532
$depth_in_chunk: The depth of the element in the containing chunk
533
$depth_of_chunk: The depth of the containing chunk in the document
535
When processed in this mode, a division element should output the top-level
536
markup for the output page.
538
<xsl:template mode="db.chunk.info.content.mode" match="*"/>
541
<!--%%==========================================================================
542
db.chunk.content.mode
543
Renders the entire contents of the chunk
544
$depth_in_chunk: The depth of the element in the containing chunk
545
$depth_of_chunk: The depth of the containing chunk in the document
547
When processed in this mode, a division element should output the top-level
548
markup for the output page.
550
<xsl:template mode="db.chunk.content.mode" match="*"/>
553
<!-- == Matched Templates == -->
555
<xsl:template match="/false">
557
<xsl:when test="$db.chunk.chunk_top">
558
<xsl:call-template name="db.chunk">
559
<xsl:with-param name="node" select="*[1]"/>
560
<xsl:with-param name="depth_of_chunk" select="0"/>
564
<xsl:apply-templates mode="db.chunk.content.mode" select="*">
565
<xsl:with-param name="depth_in_chunk" select="0"/>
566
<xsl:with-param name="depth_of_chunk" select="0"/>
567
</xsl:apply-templates>
569
<xsl:call-template name="db.chunk.children">
570
<xsl:with-param name="node" select="*[1]"/>
571
<xsl:with-param name="depth_of_chunk" select="0"/>