2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
4
exclude-result-prefixes="doc"
7
<!-- ********************************************************************
8
$Id: common.xsl,v 1.6 2004/01/04 09:25:06 j-devenish Exp $
9
********************************************************************
11
This file is part of the XSL DocBook Stylesheet distribution.
13
Copyright (C) 1999, 2000, 2001, 2002 Norman Walsh.
14
******************************************************************** -->
16
<doc:reference xmlns="">
18
<releaseinfo role="meta">
19
$Id: common.xsl,v 1.6 2004/01/04 09:25:06 j-devenish Exp $
21
<author><surname>Walsh</surname>
22
<firstname>Norman</firstname></author>
23
<copyright><year>1999</year><year>2000</year>
24
<holder>Norman Walsh</holder>
27
<title>Common Template Reference</title>
30
<section><title>Introduction</title>
32
<para>This is technical reference documentation for the DocBook XSL
33
Stylesheets; it documents (some of) the parameters, templates, and
34
other elements of the stylesheets.</para>
36
<para>This is not intended to be <quote>user</quote> documentation.
37
It is provided for developers writing customization layers for the
38
stylesheets, and for anyone who's interested in <quote>how it
41
<para>Although I am trying to be thorough, this documentation is known
42
to be incomplete. Don't forget to read the source, too :-)</para>
48
<!-- ==================================================================== -->
49
<!-- Establish strip/preserve whitespace rules -->
51
<xsl:preserve-space elements="*"/>
53
<xsl:strip-space elements="
54
abstract affiliation anchor answer appendix area areaset areaspec
55
artheader article audiodata audioobject author authorblurb authorgroup
56
beginpage bibliodiv biblioentry bibliography biblioset blockquote book
57
bookbiblio bookinfo callout calloutlist caption caution chapter
58
citerefentry cmdsynopsis co collab colophon colspec confgroup
59
copyright dedication docinfo editor entry entrytbl epigraph equation
60
example figure footnote footnoteref formalpara funcprototype
61
funcsynopsis glossary glossdef glossdiv glossentry glosslist graphicco
62
group highlights imagedata imageobject imageobjectco important index
63
indexdiv indexentry indexterm informalequation informalexample
64
informalfigure informaltable inlineequation inlinemediaobject
65
itemizedlist itermset keycombo keywordset legalnotice listitem lot
66
mediaobject mediaobjectco menuchoice msg msgentry msgexplan msginfo
67
msgmain msgrel msgset msgsub msgtext note objectinfo
68
orderedlist othercredit part partintro preface printhistory procedure
69
programlistingco publisher qandadiv qandaentry qandaset question
70
refentry reference refmeta refnamediv refsect1 refsect1info refsect2
71
refsect2info refsect3 refsect3info refsynopsisdiv refsynopsisdivinfo
72
revhistory revision row sbr screenco screenshot sect1 sect1info sect2
73
sect2info sect3 sect3info sect4 sect4info sect5 sect5info section
74
sectioninfo seglistitem segmentedlist seriesinfo set setindex setinfo
75
shortcut sidebar simplelist simplesect spanspec step subject
76
subjectset substeps synopfragment table tbody textobject tfoot tgroup
77
thead tip toc tocchap toclevel1 toclevel2 toclevel3 toclevel4
78
toclevel5 tocpart varargs variablelist varlistentry videodata
79
videoobject void warning subjectset
93
<!-- ====================================================================== -->
95
<doc:template name="is.component" xmlns="">
96
<refpurpose>Tests if a given node is a component-level element</refpurpose>
99
<para>This template returns '1' if the specified node is a component
100
(Chapter, Appendix, etc.), and '0' otherwise.</para>
105
<varlistentry><term>node</term>
107
<para>The node which is to be tested.</para>
114
<para>This template returns '1' if the specified node is a component
115
(Chapter, Appendix, etc.), and '0' otherwise.</para>
119
<xsl:template name="is.component">
120
<xsl:param name="node" select="."/>
122
<xsl:when test="local-name($node) = 'appendix'
123
or local-name($node) = 'article'
124
or local-name($node) = 'chapter'
125
or local-name($node) = 'preface'
126
or local-name($node) = 'bibliography'
127
or local-name($node) = 'glossary'
128
or local-name($node) = 'index'">1</xsl:when>
129
<xsl:otherwise>0</xsl:otherwise>
133
<!-- ====================================================================== -->
135
<doc:template name="is.section" xmlns="">
136
<refpurpose>Tests if a given node is a section-level element</refpurpose>
139
<para>This template returns '1' if the specified node is a section
140
(Section, Sect1, Sect2, etc.), and '0' otherwise.</para>
145
<varlistentry><term>node</term>
147
<para>The node which is to be tested.</para>
154
<para>This template returns '1' if the specified node is a section
155
(Section, Sect1, Sect2, etc.), and '0' otherwise.</para>
159
<xsl:template name="is.section">
160
<xsl:param name="node" select="."/>
162
<xsl:when test="local-name($node) = 'section'
163
or local-name($node) = 'sect1'
164
or local-name($node) = 'sect2'
165
or local-name($node) = 'sect3'
166
or local-name($node) = 'sect4'
167
or local-name($node) = 'sect5'
168
or local-name($node) = 'refsect1'
169
or local-name($node) = 'refsect2'
170
or local-name($node) = 'refsect3'
171
or local-name($node) = 'simplesect'">1</xsl:when>
172
<xsl:otherwise>0</xsl:otherwise>
176
<!-- ====================================================================== -->
178
<doc:template name="section.level" xmlns="">
179
<refpurpose>Returns the hierarchical level of a section.</refpurpose>
182
<para>This template calculates the hierarchical level of a section.
183
The element <sgmltag>sect1</sgmltag> is at level 1, <sgmltag>sect2</sgmltag> is
184
at level 2, etc.</para>
186
<para>Recursive sections are calculated down to the fifth level.</para>
191
<varlistentry><term>node</term>
193
<para>The section node for which the level should be calculated.
194
Defaults to the context node.</para>
201
<para>The section level, <quote>1</quote>, <quote>2</quote>, etc.
206
<xsl:template name="section.level">
207
<xsl:param name="node" select="."/>
209
<xsl:when test="name($node)='sect1'">1</xsl:when>
210
<xsl:when test="name($node)='sect2'">2</xsl:when>
211
<xsl:when test="name($node)='sect3'">3</xsl:when>
212
<xsl:when test="name($node)='sect4'">4</xsl:when>
213
<xsl:when test="name($node)='sect5'">5</xsl:when>
214
<xsl:when test="name($node)='section'">
216
<xsl:when test="$node/../../../../../../section">6</xsl:when>
217
<xsl:when test="$node/../../../../../section">5</xsl:when>
218
<xsl:when test="$node/../../../../section">4</xsl:when>
219
<xsl:when test="$node/../../../section">3</xsl:when>
220
<xsl:when test="$node/../../section">2</xsl:when>
221
<xsl:otherwise>1</xsl:otherwise>
224
<xsl:when test="name($node)='refsect1' or
225
name($node)='refsect2' or
226
name($node)='refsect3' or
227
name($node)='refsection' or
228
name($node)='refsynopsisdiv'">
229
<xsl:call-template name="refentry.section.level">
230
<xsl:with-param name="node" select="$node"/>
233
<xsl:when test="name($node)='simplesect'">
235
<xsl:when test="$node/../../sect1">2</xsl:when>
236
<xsl:when test="$node/../../sect2">3</xsl:when>
237
<xsl:when test="$node/../../sect3">4</xsl:when>
238
<xsl:when test="$node/../../sect4">5</xsl:when>
239
<xsl:when test="$node/../../sect5">5</xsl:when>
240
<xsl:when test="$node/../../section">
242
<xsl:when test="$node/../../../../../section">5</xsl:when>
243
<xsl:when test="$node/../../../../section">4</xsl:when>
244
<xsl:when test="$node/../../../section">3</xsl:when>
245
<xsl:otherwise>2</xsl:otherwise>
248
<xsl:otherwise>1</xsl:otherwise>
251
<xsl:otherwise>1</xsl:otherwise>
253
</xsl:template><!-- section.level -->
255
<doc:template name="qanda.section.level" xmlns="">
256
<refpurpose>Returns the hierarchical level of a QandASet.</refpurpose>
259
<para>This template calculates the hierarchical level of a QandASet.
264
<para>The level, <quote>1</quote>, <quote>2</quote>, etc.
269
<xsl:template name="qanda.section.level">
270
<xsl:variable name="section"
271
select="(ancestor::section
272
|ancestor::simplesect
280
|ancestor::refsect1)[last()]"/>
283
<xsl:when test="count($section) = 0">1</xsl:when>
285
<xsl:variable name="slevel">
286
<xsl:call-template name="section.level">
287
<xsl:with-param name="node" select="$section"/>
290
<xsl:value-of select="$slevel + 1"/>
295
<!-- Finds the total section depth of a section in a refentry -->
296
<xsl:template name="refentry.section.level">
297
<xsl:param name="node" select="."/>
299
<xsl:variable name="RElevel">
300
<xsl:call-template name="refentry.level">
301
<xsl:with-param name="node" select="$node/ancestor::refentry[1]"/>
305
<xsl:variable name="levelinRE">
307
<xsl:when test="name($node)='refsynopsisdiv'">1</xsl:when>
308
<xsl:when test="name($node)='refsect1'">1</xsl:when>
309
<xsl:when test="name($node)='refsect2'">2</xsl:when>
310
<xsl:when test="name($node)='refsect3'">3</xsl:when>
311
<xsl:when test="name($node)='refsection'">
313
<xsl:when test="$node/../../../../../refsection">5</xsl:when>
314
<xsl:when test="$node/../../../../refsection">4</xsl:when>
315
<xsl:when test="$node/../../../refsection">3</xsl:when>
316
<xsl:when test="$node/../../refsection">2</xsl:when>
317
<xsl:otherwise>1</xsl:otherwise>
323
<xsl:value-of select="$levelinRE + $RElevel"/>
326
<!-- Finds the section depth of a refentry -->
327
<xsl:template name="refentry.level">
328
<xsl:param name="node" select="."/>
329
<xsl:variable name="container"
330
select="($node/ancestor::section |
331
$node/ancestor::sect1 |
332
$node/ancestor::sect2 |
333
$node/ancestor::sect3 |
334
$node/ancestor::sect4 |
335
$node/ancestor::sect5)[last()]"/>
338
<xsl:when test="$container">
339
<xsl:variable name="slevel">
340
<xsl:call-template name="section.level">
341
<xsl:with-param name="node" select="$container"/>
344
<xsl:value-of select="$slevel + 1"/>
346
<xsl:otherwise>1</xsl:otherwise>
350
<xsl:template name="qandadiv.section.level">
351
<xsl:variable name="section.level">
352
<xsl:call-template name="qanda.section.level"/>
354
<xsl:variable name="anc.divs" select="ancestor::qandadiv"/>
356
<xsl:value-of select="count($anc.divs) + number($section.level)"/>
360
<xsl:template match="qandaset" mode="number">
364
<xsl:template match="qandadiv" mode="number">
365
<xsl:number level="multiple" from="qandaset" format="1."/>
368
<xsl:template match="qandaentry" mode="number">
370
<xsl:when test="ancestor::qandadiv">
371
<xsl:number level="single" from="qandadiv" format="1."/>
374
<xsl:number level="single" from="qandaset" format="1."/>
379
<!-- ====================================================================== -->
381
<xsl:template name="object.id">
382
<xsl:param name="object" select="."/>
384
<xsl:when test="$object/@id">
385
<xsl:value-of select="$object/@id"/>
388
<xsl:value-of select="generate-id($object)"/>
393
<xsl:template name="person.name">
394
<!-- Formats a personal name. Handles corpauthor as a special case. -->
395
<xsl:param name="node" select="."/>
397
<xsl:variable name="style">
399
<xsl:when test="$node/@role">
400
<xsl:value-of select="$node/@role"/>
403
<xsl:call-template name="gentext.template">
404
<xsl:with-param name="context" select="'styles'"/>
405
<xsl:with-param name="name" select="'person-name'"/>
412
<!-- the personname element is a specialcase -->
413
<xsl:when test="$node/personname">
414
<xsl:call-template name="person.name">
415
<xsl:with-param name="node" select="$node/personname"/>
419
<!-- handle corpauthor as a special case...-->
420
<xsl:when test="name($node)='corpauthor'">
421
<xsl:apply-templates select="$node"/>
426
<xsl:when test="$style = 'family-given'">
427
<xsl:call-template name="person.name.family-given">
428
<xsl:with-param name="node" select="$node"/>
431
<xsl:when test="$style = 'last-first'">
432
<xsl:call-template name="person.name.last-first">
433
<xsl:with-param name="node" select="$node"/>
437
<xsl:call-template name="person.name.first-last">
438
<xsl:with-param name="node" select="$node"/>
446
<xsl:template name="person.name.family-given">
447
<xsl:param name="node" select="."/>
449
<!-- The family-given style applies a convention for identifying given -->
450
<!-- and family names in locales where it may be ambiguous -->
451
<xsl:apply-templates select="$node//surname[1]"/>
453
<xsl:if test="$node//surname and $node//firstname">
454
<xsl:text> </xsl:text>
457
<xsl:apply-templates select="$node//firstname[1]"/>
459
<xsl:text> [FAMILY Given]</xsl:text>
462
<xsl:template name="person.name.last-first">
463
<xsl:param name="node" select="."/>
465
<xsl:apply-templates select="$node//surname[1]"/>
467
<xsl:if test="$node//surname and $node//firstname">
468
<xsl:text>, </xsl:text>
471
<xsl:apply-templates select="$node//firstname[1]"/>
474
<xsl:template name="person.name.first-last">
475
<xsl:param name="node" select="."/>
477
<xsl:if test="$node//honorific">
478
<xsl:apply-templates select="$node//honorific[1]"/>
479
<xsl:value-of select="$punct.honorific"/>
482
<xsl:if test="$node//firstname">
483
<xsl:if test="$node//honorific">
484
<xsl:text> </xsl:text>
486
<xsl:apply-templates select="$node//firstname[1]"/>
489
<xsl:if test="$node//othername and $author.othername.in.middle != 0">
490
<xsl:if test="$node//honorific or $node//firstname">
491
<xsl:text> </xsl:text>
493
<xsl:apply-templates select="$node//othername[1]"/>
496
<xsl:if test="$node//surname">
497
<xsl:if test="$node//honorific or $node//firstname
498
or ($node//othername and $author.othername.in.middle != 0)">
499
<xsl:text> </xsl:text>
501
<xsl:apply-templates select="$node//surname[1]"/>
504
<xsl:if test="$node//lineage">
505
<xsl:text>, </xsl:text>
506
<xsl:apply-templates select="$node//lineage[1]"/>
510
<xsl:template name="person.name.list">
511
<!-- Return a formatted string representation of the contents of
512
the current element. The current element must contain one or
513
more AUTHORs, CORPAUTHORs, OTHERCREDITs, and/or EDITORs.
517
John Doe and Jane Doe
519
John Doe, Jane Doe, and A. Nonymous
521
<xsl:param name="person.list"
522
select="author|corpauthor|othercredit|editor"/>
523
<xsl:param name="person.count" select="count($person.list)"/>
524
<xsl:param name="count" select="1"/>
527
<xsl:when test="$count > $person.count"></xsl:when>
529
<xsl:call-template name="person.name">
530
<xsl:with-param name="node" select="$person.list[position()=$count]"/>
534
<xsl:when test="$person.count = 2 and $count = 1">
535
<xsl:call-template name="gentext.template">
536
<xsl:with-param name="context" select="'authorgroup'"/>
537
<xsl:with-param name="name" select="'sep2'"/>
540
<xsl:when test="$person.count > 2 and $count+1 = $person.count">
541
<xsl:call-template name="gentext.template">
542
<xsl:with-param name="context" select="'authorgroup'"/>
543
<xsl:with-param name="name" select="'seplast'"/>
546
<xsl:when test="$count < $person.count">
547
<xsl:call-template name="gentext.template">
548
<xsl:with-param name="context" select="'authorgroup'"/>
549
<xsl:with-param name="name" select="'sep'"/>
554
<xsl:call-template name="person.name.list">
555
<xsl:with-param name="person.list" select="$person.list"/>
556
<xsl:with-param name="person.count" select="$person.count"/>
557
<xsl:with-param name="count" select="$count+1"/>
561
</xsl:template><!-- person.name.list -->
563
<!-- === synopsis ======================================================= -->
564
<!-- The following definitions match those given in the reference
565
documentation for DocBook V3.0
568
<xsl:variable name="arg.choice.opt.open.str">[</xsl:variable>
569
<xsl:variable name="arg.choice.opt.close.str">]</xsl:variable>
570
<xsl:variable name="arg.choice.req.open.str">{</xsl:variable>
571
<xsl:variable name="arg.choice.req.close.str">}</xsl:variable>
572
<xsl:variable name="arg.choice.plain.open.str"><xsl:text> </xsl:text></xsl:variable>
573
<xsl:variable name="arg.choice.plain.close.str"><xsl:text> </xsl:text></xsl:variable>
574
<xsl:variable name="arg.choice.def.open.str">[</xsl:variable>
575
<xsl:variable name="arg.choice.def.close.str">]</xsl:variable>
576
<xsl:variable name="arg.rep.repeat.str">...</xsl:variable>
577
<xsl:variable name="arg.rep.norepeat.str"></xsl:variable>
578
<xsl:variable name="arg.rep.def.str"></xsl:variable>
579
<xsl:variable name="arg.or.sep"> | </xsl:variable>
580
<xsl:variable name="cmdsynopsis.hanging.indent">4pi</xsl:variable>
582
<!-- ====================================================================== -->
585
<xsl:template name="xref.g.subst">
586
<xsl:param name="string"></xsl:param>
587
<xsl:param name="target" select="."/>
588
<xsl:variable name="subst">%g</xsl:variable>
591
<xsl:when test="contains($string, $subst)">
592
<xsl:value-of select="substring-before($string, $subst)"/>
593
<xsl:call-template name="gentext.element.name">
594
<xsl:with-param name="element.name" select="name($target)"/>
596
<xsl:call-template name="xref.g.subst">
597
<xsl:with-param name="string"
598
select="substring-after($string, $subst)"/>
599
<xsl:with-param name="target" select="$target"/>
603
<xsl:value-of select="$string"/>
608
<xsl:template name="xref.t.subst">
609
<xsl:param name="string"></xsl:param>
610
<xsl:param name="target" select="."/>
611
<xsl:variable name="subst">%t</xsl:variable>
614
<xsl:when test="contains($string, $subst)">
615
<xsl:call-template name="xref.g.subst">
616
<xsl:with-param name="string"
617
select="substring-before($string, $subst)"/>
618
<xsl:with-param name="target" select="$target"/>
620
<xsl:call-template name="title.xref">
621
<xsl:with-param name="target" select="$target"/>
623
<xsl:call-template name="xref.t.subst">
624
<xsl:with-param name="string"
625
select="substring-after($string, $subst)"/>
626
<xsl:with-param name="target" select="$target"/>
630
<xsl:call-template name="xref.g.subst">
631
<xsl:with-param name="string" select="$string"/>
632
<xsl:with-param name="target" select="$target"/>
638
<xsl:template name="xref.n.subst">
639
<xsl:param name="string"></xsl:param>
640
<xsl:param name="target" select="."/>
641
<xsl:variable name="subst">%n</xsl:variable>
644
<xsl:when test="contains($string, $subst)">
645
<xsl:call-template name="xref.t.subst">
646
<xsl:with-param name="string"
647
select="substring-before($string, $subst)"/>
648
<xsl:with-param name="target" select="$target"/>
650
<xsl:call-template name="number.xref">
651
<xsl:with-param name="target" select="$target"/>
653
<xsl:call-template name="xref.t.subst">
654
<xsl:with-param name="string"
655
select="substring-after($string, $subst)"/>
656
<xsl:with-param name="target" select="$target"/>
660
<xsl:call-template name="xref.t.subst">
661
<xsl:with-param name="string" select="$string"/>
662
<xsl:with-param name="target" select="$target"/>
668
<xsl:template name="subst.xref.text">
669
<xsl:param name="xref.text"></xsl:param>
670
<xsl:param name="target" select="."/>
672
<xsl:call-template name="xref.n.subst">
673
<xsl:with-param name="string" select="$xref.text"/>
674
<xsl:with-param name="target" select="$target"/>
679
<!-- ====================================================================== -->
681
<xsl:template name="filename-basename">
682
<!-- We assume all filenames are really URIs and use "/" -->
683
<xsl:param name="filename"></xsl:param>
684
<xsl:param name="recurse" select="false()"/>
687
<xsl:when test="substring-after($filename, '/') != ''">
688
<xsl:call-template name="filename-basename">
689
<xsl:with-param name="filename"
690
select="substring-after($filename, '/')"/>
691
<xsl:with-param name="recurse" select="true()"/>
695
<xsl:value-of select="$filename"/>
700
<xsl:template name="filename-extension">
701
<xsl:param name="filename"></xsl:param>
702
<xsl:param name="recurse" select="false()"/>
704
<!-- Make sure we only look at the base name... -->
705
<xsl:variable name="basefn">
707
<xsl:when test="$recurse">
708
<xsl:value-of select="$filename"/>
711
<xsl:call-template name="filename-basename">
712
<xsl:with-param name="filename" select="$filename"/>
719
<xsl:when test="substring-after($basefn, '.') != ''">
720
<xsl:call-template name="filename-extension">
721
<xsl:with-param name="filename"
722
select="substring-after($basefn, '.')"/>
723
<xsl:with-param name="recurse" select="true()"/>
726
<xsl:when test="$recurse">
727
<xsl:value-of select="$basefn"/>
729
<xsl:otherwise></xsl:otherwise>
733
<!-- ====================================================================== -->
735
<doc:template name="select.mediaobject" xmlns="">
736
<refpurpose>Selects and processes an appropriate media object from a list</refpurpose>
739
<para>This template takes a list of media objects (usually the
740
children of a mediaobject or inlinemediaobject) and processes
741
the "right" object.</para>
743
<para>This template relies on a template named
744
"select.mediaobject.index" to determine which object
745
in the list is appropriate.</para>
747
<para>If no acceptable object is located, nothing happens.</para>
752
<varlistentry><term>olist</term>
754
<para>The node list of potential objects to examine.</para>
761
<para>Calls <xsl:apply-templates> on the selected object.</para>
765
<xsl:template name="select.mediaobject">
766
<xsl:param name="olist"
767
select="imageobject|imageobjectco
768
|videoobject|audioobject|textobject"/>
770
<xsl:variable name="mediaobject.index">
771
<xsl:call-template name="select.mediaobject.index">
772
<xsl:with-param name="olist" select="$olist"/>
773
<xsl:with-param name="count" select="1"/>
777
<xsl:if test="$mediaobject.index != ''">
778
<xsl:apply-templates select="$olist[position() = $mediaobject.index]"/>
782
<!-- ====================================================================== -->
784
<doc:template name="select.mediaobject.index" xmlns="">
785
<refpurpose>Selects the position of the appropriate media object from a list</refpurpose>
788
<para>This template takes a list of media objects (usually the
789
children of a mediaobject or inlinemediaobject) and determines
790
the "right" object. It returns the position of that object
791
to be used by the calling template.</para>
793
<para>If the parameter <parameter>use.role.for.mediaobject</parameter>
794
is nonzero, then it first checks for an object with
795
a role attribute of the appropriate value. It takes the first
796
of those. Otherwise, it takes the first acceptable object
797
through a recursive pass through the list.</para>
799
<para>This template relies on a template named "is.acceptable.mediaobject"
800
to determine if a given object is an acceptable graphic. The semantics
801
of media objects is that the first acceptable graphic should be used.
804
<para>If no acceptable object is located, no index is returned.</para>
809
<varlistentry><term>olist</term>
811
<para>The node list of potential objects to examine.</para>
814
<varlistentry><term>count</term>
816
<para>The position in the list currently being considered by the
817
recursive process.</para>
824
<para>Returns the position in the original list of the selected object.</para>
828
<xsl:template name="select.mediaobject.index">
829
<xsl:param name="olist"
830
select="imageobject|imageobjectco
831
|videoobject|audioobject|textobject"/>
832
<xsl:param name="count">1</xsl:param>
835
<!-- Test for objects preferred by role -->
836
<xsl:when test="$use.role.for.mediaobject != 0
837
and $preferred.mediaobject.role != ''
838
and $olist[@role = $preferred.mediaobject.role]">
840
<!-- Get the first hit's position index -->
841
<xsl:for-each select="$olist">
842
<xsl:if test="@role = $preferred.mediaobject.role and
843
not(preceding-sibling::*[@role = $preferred.mediaobject.role])">
844
<xsl:value-of select="position()"/>
849
<xsl:when test="$use.role.for.mediaobject != 0
850
and $olist[@role = $stylesheet.result.type]">
851
<!-- Get the first hit's position index -->
852
<xsl:for-each select="$olist">
853
<xsl:if test="@role = $stylesheet.result.type and
854
not(preceding-sibling::*[@role = $stylesheet.result.type])">
855
<xsl:value-of select="position()"/>
859
<!-- Accept 'html' for $stylesheet.result.type = 'xhtml' -->
860
<xsl:when test="$use.role.for.mediaobject != 0
861
and $stylesheet.result.type = 'xhtml'
862
and $olist[@role = 'html']">
863
<!-- Get the first hit's position index -->
864
<xsl:for-each select="$olist">
865
<xsl:if test="@role = 'html' and
866
not(preceding-sibling::*[@role = 'html'])">
867
<xsl:value-of select="position()"/>
872
<!-- Otherwise select first acceptable object -->
873
<xsl:if test="$count <= count($olist)">
874
<xsl:variable name="object" select="$olist[position()=$count]"/>
876
<xsl:variable name="useobject">
878
<!-- The phrase is used only when contains TeX Math and output is FO -->
879
<xsl:when test="name($object)='textobject' and $object/phrase
880
and $object/@role='tex' and $stylesheet.result.type = 'fo'
881
and $tex.math.in.alt != ''">
882
<xsl:text>1</xsl:text>
884
<!-- The phrase is never used -->
885
<xsl:when test="name($object)='textobject' and $object/phrase">
886
<xsl:text>0</xsl:text>
888
<xsl:when test="name($object)='textobject'
889
and $object/ancestor::equation ">
890
<!-- The first textobject is not a reasonable fallback
891
for equation image -->
892
<xsl:text>0</xsl:text>
894
<!-- The first textobject is a reasonable fallback -->
895
<xsl:when test="name($object)='textobject'
896
and $object[not(@role) or @role!='tex']">
897
<xsl:text>1</xsl:text>
899
<!-- don't use graphic when output is FO, TeX Math is used
900
and there is math in alt element -->
901
<xsl:when test="$object/ancestor::equation and
902
$object/ancestor::equation/alt[@role='tex']
903
and $stylesheet.result.type = 'fo'
904
and $tex.math.in.alt != ''">
905
<xsl:text>0</xsl:text>
907
<!-- If there's only one object, use it -->
908
<xsl:when test="$count = 1 and count($olist) = 1">
909
<xsl:text>1</xsl:text>
911
<!-- Otherwise, see if this one is a useable graphic -->
914
<!-- peek inside imageobjectco to simplify the test -->
915
<xsl:when test="local-name($object) = 'imageobjectco'">
916
<xsl:call-template name="is.acceptable.mediaobject">
917
<xsl:with-param name="object" select="$object/imageobject"/>
921
<xsl:call-template name="is.acceptable.mediaobject">
922
<xsl:with-param name="object" select="$object"/>
931
<xsl:when test="$useobject='1'">
932
<xsl:value-of select="$count"/>
935
<xsl:call-template name="select.mediaobject.index">
936
<xsl:with-param name="olist" select="$olist"/>
937
<xsl:with-param name="count" select="$count + 1"/>
946
<doc:template name="is.acceptable.mediaobject" xmlns="">
947
<refpurpose>Returns '1' if the specified media object is recognized.</refpurpose>
950
<para>This template examines a media object and returns '1' if the
951
object is recognized as a graphic.</para>
956
<varlistentry><term>object</term>
958
<para>The media object to consider.</para>
969
<xsl:template name="is.acceptable.mediaobject">
970
<xsl:param name="object"></xsl:param>
972
<xsl:variable name="filename">
973
<xsl:call-template name="mediaobject.filename">
974
<xsl:with-param name="object" select="$object"/>
978
<xsl:variable name="ext">
979
<xsl:call-template name="filename-extension">
980
<xsl:with-param name="filename" select="$filename"/>
984
<!-- there will only be one -->
985
<xsl:variable name="data" select="$object/videodata
987
|$object/audiodata"/>
989
<xsl:variable name="format" select="$data/@format"/>
991
<xsl:variable name="graphic.format">
992
<xsl:if test="$format">
993
<xsl:call-template name="is.graphic.format">
994
<xsl:with-param name="format" select="$format"/>
999
<xsl:variable name="graphic.ext">
1000
<xsl:if test="$ext">
1001
<xsl:call-template name="is.graphic.extension">
1002
<xsl:with-param name="ext" select="$ext"/>
1003
</xsl:call-template>
1008
<xsl:when test="$use.svg = 0 and $format = 'SVG'">0</xsl:when>
1009
<xsl:when xmlns:svg="http://www.w3.org/2000/svg"
1010
test="$use.svg != 0 and $object/svg:*">1</xsl:when>
1011
<xsl:when test="$graphic.format = '1'">1</xsl:when>
1012
<xsl:when test="$graphic.ext = '1'">1</xsl:when>
1013
<xsl:otherwise>0</xsl:otherwise>
1017
<xsl:template name="mediaobject.filename">
1018
<xsl:param name="object"></xsl:param>
1020
<xsl:variable name="data" select="$object/videodata
1025
<xsl:variable name="filename">
1027
<xsl:when test="$data[@fileref]">
1028
<xsl:value-of select="$data/@fileref"/>
1030
<xsl:when test="$data[@entityref]">
1031
<xsl:value-of select="unparsed-entity-uri($data/@entityref)"/>
1033
<xsl:otherwise></xsl:otherwise>
1037
<xsl:variable name="real.ext">
1038
<xsl:call-template name="filename-extension">
1039
<xsl:with-param name="filename" select="$filename"/>
1040
</xsl:call-template>
1043
<xsl:variable name="ext">
1045
<xsl:when test="$real.ext != ''">
1046
<xsl:value-of select="$real.ext"/>
1049
<xsl:value-of select="$graphic.default.extension"/>
1054
<xsl:variable name="graphic.ext">
1055
<xsl:call-template name="is.graphic.extension">
1056
<xsl:with-param name="ext" select="$ext"/>
1057
</xsl:call-template>
1061
<xsl:when test="$real.ext = ''">
1063
<xsl:when test="$ext != ''">
1064
<xsl:value-of select="$filename"/>
1065
<xsl:text>.</xsl:text>
1066
<xsl:value-of select="$ext"/>
1069
<xsl:value-of select="$filename"/>
1073
<xsl:when test="not($graphic.ext)">
1075
<xsl:when test="$graphic.default.extension != ''">
1076
<xsl:value-of select="$filename"/>
1077
<xsl:text>.</xsl:text>
1078
<xsl:value-of select="$graphic.default.extension"/>
1081
<xsl:value-of select="$filename"/>
1086
<xsl:value-of select="$filename"/>
1091
<!-- ====================================================================== -->
1093
<doc:template name="check.id.unique" xmlns="">
1094
<refpurpose>Warn users about references to non-unique IDs</refpurpose>
1096
<para>If passed an ID in <varname>linkend</varname>,
1097
<function>check.id.unique</function> prints
1098
a warning message to the user if either the ID does not exist or
1099
the ID is not unique.</para>
1103
<xsl:template name="check.id.unique">
1104
<xsl:param name="linkend"></xsl:param>
1105
<xsl:if test="$linkend != ''">
1106
<xsl:variable name="targets" select="key('id',$linkend)"/>
1107
<xsl:variable name="target" select="$targets[1]"/>
1109
<xsl:if test="count($targets)=0">
1111
<xsl:text>Error: no ID for constraint linkend: </xsl:text>
1112
<xsl:value-of select="$linkend"/>
1113
<xsl:text>.</xsl:text>
1117
<xsl:text>If the ID exists in your document, did your </xsl:text>
1118
<xsl:text>XSLT Processor load the DTD?</xsl:text>
1123
<xsl:if test="count($targets)>1">
1125
<xsl:text>Warning: multiple "IDs" for constraint linkend: </xsl:text>
1126
<xsl:value-of select="$linkend"/>
1127
<xsl:text>.</xsl:text>
1133
<doc:template name="check.idref.targets" xmlns="">
1134
<refpurpose>Warn users about incorrectly typed references</refpurpose>
1136
<para>If passed an ID in <varname>linkend</varname>,
1137
<function>check.idref.targets</function> makes sure that the element
1138
pointed to by the link is one of the elements listed in
1139
<varname>element-list</varname> and warns the user otherwise.</para>
1143
<xsl:template name="check.idref.targets">
1144
<xsl:param name="linkend"></xsl:param>
1145
<xsl:param name="element-list"></xsl:param>
1146
<xsl:if test="$linkend != ''">
1147
<xsl:variable name="targets" select="key('id',$linkend)"/>
1148
<xsl:variable name="target" select="$targets[1]"/>
1150
<xsl:if test="count($target) > 0">
1151
<xsl:if test="not(contains(concat(' ', $element-list, ' '), name($target)))">
1153
<xsl:text>Error: linkend (</xsl:text>
1154
<xsl:value-of select="$linkend"/>
1155
<xsl:text>) points to "</xsl:text>
1156
<xsl:value-of select="name($target)"/>
1157
<xsl:text>" not (one of): </xsl:text>
1158
<xsl:value-of select="$element-list"/>
1165
<!-- ====================================================================== -->
1166
<!-- Procedure Step Numeration -->
1168
<xsl:param name="procedure.step.numeration.formats" select="'1aiAI'"/>
1170
<xsl:template name="procedure.step.numeration">
1171
<xsl:param name="context" select="."/>
1172
<xsl:variable name="format.length"
1173
select="string-length($procedure.step.numeration.formats)"/>
1175
<xsl:when test="local-name($context) = 'substeps'">
1176
<xsl:variable name="ssdepth"
1177
select="count($context/ancestor::substeps)"/>
1178
<xsl:variable name="sstype" select="($ssdepth mod $format.length)+2"/>
1180
<xsl:when test="$sstype > $format.length">
1181
<xsl:value-of select="substring($procedure.step.numeration.formats,1,1)"/>
1184
<xsl:value-of select="substring($procedure.step.numeration.formats,$sstype,1)"/>
1188
<xsl:when test="local-name($context) = 'step'">
1189
<xsl:variable name="sdepth"
1190
select="count($context/ancestor::substeps)"/>
1191
<xsl:variable name="stype" select="($sdepth mod $format.length)+1"/>
1192
<xsl:value-of select="substring($procedure.step.numeration.formats,$stype,1)"/>
1196
<xsl:text>Unexpected context in procedure.step.numeration: </xsl:text>
1197
<xsl:value-of select="local-name($context)"/>
1203
<xsl:template match="step" mode="number">
1204
<xsl:param name="rest" select="''"/>
1205
<xsl:param name="recursive" select="1"/>
1206
<xsl:variable name="format">
1207
<xsl:call-template name="procedure.step.numeration"/>
1209
<xsl:variable name="num">
1210
<xsl:number count="step" format="{$format}"/>
1213
<xsl:when test="$recursive != 0 and ancestor::step">
1214
<xsl:apply-templates select="ancestor::step[1]" mode="number">
1215
<xsl:with-param name="rest" select="concat('.', $num, $rest)"/>
1216
</xsl:apply-templates>
1219
<xsl:value-of select="concat($num, $rest)"/>
1224
<!-- ====================================================================== -->
1225
<!-- OrderedList Numeration -->
1227
<xsl:template name="orderedlist-starting-number">
1228
<xsl:param name="list" select="."/>
1230
<xsl:when test="not($list/@continuation = 'continues')">1</xsl:when>
1232
<xsl:variable name="prevlist"
1233
select="$list/preceding::orderedlist[1]"/>
1235
<xsl:when test="count($prevlist) = 0">2</xsl:when>
1237
<xsl:variable name="prevlength" select="count($prevlist/listitem)"/>
1238
<xsl:variable name="prevstart">
1239
<xsl:call-template name="orderedlist-starting-number">
1240
<xsl:with-param name="list" select="$prevlist"/>
1241
</xsl:call-template>
1243
<xsl:value-of select="$prevstart + $prevlength"/>
1250
<xsl:template name="orderedlist-item-number">
1251
<!-- context node must be a listitem in an orderedlist -->
1252
<xsl:param name="node" select="."/>
1255
<xsl:when test="$node/@override">
1256
<xsl:value-of select="$node/@override"/>
1258
<xsl:when test="$node/preceding-sibling::listitem">
1259
<xsl:variable name="pnum">
1260
<xsl:call-template name="orderedlist-item-number">
1261
<xsl:with-param name="node" select="$node/preceding-sibling::listitem[1]"/>
1262
</xsl:call-template>
1264
<xsl:value-of select="$pnum + 1"/>
1267
<xsl:call-template name="orderedlist-starting-number">
1268
<xsl:with-param name="list" select="parent::*"/>
1269
</xsl:call-template>
1274
<xsl:template name="next.numeration">
1275
<xsl:param name="numeration" select="'default'"/>
1277
<!-- Change this list if you want to change the order of numerations -->
1278
<xsl:when test="$numeration = 'arabic'">loweralpha</xsl:when>
1279
<xsl:when test="$numeration = 'loweralpha'">lowerroman</xsl:when>
1280
<xsl:when test="$numeration = 'lowerroman'">upperalpha</xsl:when>
1281
<xsl:when test="$numeration = 'upperalpha'">upperroman</xsl:when>
1282
<xsl:when test="$numeration = 'upperroman'">arabic</xsl:when>
1283
<xsl:otherwise>arabic</xsl:otherwise>
1287
<xsl:template name="list.numeration">
1288
<xsl:param name="node" select="."/>
1291
<xsl:when test="$node/@numeration">
1292
<xsl:value-of select="$node/@numeration"/>
1296
<xsl:when test="$node/ancestor::orderedlist">
1297
<xsl:call-template name="next.numeration">
1298
<xsl:with-param name="numeration">
1299
<xsl:call-template name="list.numeration">
1300
<xsl:with-param name="node" select="$node/ancestor::orderedlist[1]"/>
1301
</xsl:call-template>
1303
</xsl:call-template>
1306
<xsl:call-template name="next.numeration"/>
1313
<!-- ====================================================================== -->
1314
<!-- ItemizedList "Numeration" -->
1316
<xsl:template name="next.itemsymbol">
1317
<xsl:param name="itemsymbol" select="'default'"/>
1319
<!-- Change this list if you want to change the order of symbols -->
1320
<xsl:when test="$itemsymbol = 'disc'">circle</xsl:when>
1321
<xsl:when test="$itemsymbol = 'round'">square</xsl:when>
1322
<xsl:otherwise>disc</xsl:otherwise>
1326
<xsl:template name="list.itemsymbol">
1327
<xsl:param name="node" select="."/>
1330
<xsl:when test="$node/@mark">
1331
<xsl:value-of select="$node/@mark"/>
1335
<xsl:when test="$node/ancestor::itemizedlist">
1336
<xsl:call-template name="next.itemsymbol">
1337
<xsl:with-param name="itemsymbol">
1338
<xsl:call-template name="list.itemsymbol">
1339
<xsl:with-param name="node" select="$node/ancestor::itemizedlist[1]"/>
1340
</xsl:call-template>
1342
</xsl:call-template>
1345
<xsl:call-template name="next.itemsymbol"/>
1352
<!-- ====================================================================== -->
1354
<doc:template name="copyright.years" xmlns="">
1355
<refpurpose>Print a set of years with collapsed ranges</refpurpose>
1358
<para>This template prints a list of year elements with consecutive
1359
years printed as a range. In other words:</para>
1361
<screen><![CDATA[<year>1992</year>
1363
<year>1994</year>]]></screen>
1365
<para>is printed <quote>1992-1994</quote>, whereas:</para>
1367
<screen><![CDATA[<year>1992</year>
1368
<year>1994</year>]]></screen>
1370
<para>is printed <quote>1992, 1994</quote>.</para>
1372
<para>This template assumes that all the year elements contain only
1373
decimal year numbers, that the elements are sorted in increasing
1374
numerical order, that there are no duplicates, and that all the years
1375
are expressed in full <quote>century+year</quote>
1376
(<quote>1999</quote> not <quote>99</quote>) notation.</para>
1381
<varlistentry><term>years</term>
1383
<para>The initial set of year elements.</para>
1386
<varlistentry><term>print.ranges</term>
1388
<para>If non-zero, multi-year ranges are collapsed. If zero, all years
1389
are printed discretely.</para>
1392
<varlistentry><term>single.year.ranges</term>
1394
<para>If non-zero, two consecutive years will be printed as a range,
1395
otherwise, they will be printed discretely. In other words, a single
1396
year range is <quote>1991-1992</quote> but discretely it's
1397
<quote>1991, 1992</quote>.</para>
1404
<para>This template returns the formatted list of years.</para>
1408
<xsl:template name="copyright.years">
1409
<xsl:param name="years"/>
1410
<xsl:param name="print.ranges" select="1"/>
1411
<xsl:param name="single.year.ranges" select="0"/>
1412
<xsl:param name="firstyear" select="0"/>
1413
<xsl:param name="nextyear" select="0"/>
1416
<xsl:message terminate="no">
1417
<xsl:text>CY: </xsl:text>
1418
<xsl:value-of select="count($years)"/>
1419
<xsl:text>, </xsl:text>
1420
<xsl:value-of select="$firstyear"/>
1421
<xsl:text>, </xsl:text>
1422
<xsl:value-of select="$nextyear"/>
1423
<xsl:text>, </xsl:text>
1424
<xsl:value-of select="$print.ranges"/>
1425
<xsl:text>, </xsl:text>
1426
<xsl:value-of select="$single.year.ranges"/>
1427
<xsl:text> (</xsl:text>
1428
<xsl:value-of select="$years[1]"/>
1429
<xsl:text>)</xsl:text>
1434
<xsl:when test="$print.ranges = 0 and count($years) > 0">
1436
<xsl:when test="count($years) = 1">
1437
<xsl:apply-templates select="$years[1]" mode="titlepage.mode"/>
1440
<xsl:apply-templates select="$years[1]" mode="titlepage.mode"/>
1441
<xsl:text>, </xsl:text>
1442
<xsl:call-template name="copyright.years">
1443
<xsl:with-param name="years"
1444
select="$years[position() > 1]"/>
1445
<xsl:with-param name="print.ranges" select="$print.ranges"/>
1446
<xsl:with-param name="single.year.ranges"
1447
select="$single.year.ranges"/>
1448
</xsl:call-template>
1452
<xsl:when test="count($years) = 0">
1453
<xsl:variable name="lastyear" select="$nextyear - 1"/>
1455
<xsl:when test="$firstyear = 0">
1456
<!-- there weren't any years at all -->
1458
<xsl:when test="$firstyear = $lastyear">
1459
<xsl:value-of select="$firstyear"/>
1461
<xsl:when test="$single.year.ranges = 0
1462
and $lastyear = $firstyear + 1">
1463
<xsl:value-of select="$firstyear"/>
1464
<xsl:text>, </xsl:text>
1465
<xsl:value-of select="$lastyear"/>
1468
<xsl:value-of select="$firstyear"/>
1469
<xsl:text>-</xsl:text>
1470
<xsl:value-of select="$lastyear"/>
1474
<xsl:when test="$firstyear = 0">
1475
<xsl:call-template name="copyright.years">
1476
<xsl:with-param name="years"
1477
select="$years[position() > 1]"/>
1478
<xsl:with-param name="firstyear" select="$years[1]"/>
1479
<xsl:with-param name="nextyear" select="$years[1] + 1"/>
1480
<xsl:with-param name="print.ranges" select="$print.ranges"/>
1481
<xsl:with-param name="single.year.ranges"
1482
select="$single.year.ranges"/>
1483
</xsl:call-template>
1485
<xsl:when test="$nextyear = $years[1]">
1486
<xsl:call-template name="copyright.years">
1487
<xsl:with-param name="years"
1488
select="$years[position() > 1]"/>
1489
<xsl:with-param name="firstyear" select="$firstyear"/>
1490
<xsl:with-param name="nextyear" select="$nextyear + 1"/>
1491
<xsl:with-param name="print.ranges" select="$print.ranges"/>
1492
<xsl:with-param name="single.year.ranges"
1493
select="$single.year.ranges"/>
1494
</xsl:call-template>
1497
<!-- we have years left, but they aren't in the current range -->
1499
<xsl:when test="$nextyear = $firstyear + 1">
1500
<xsl:value-of select="$firstyear"/>
1501
<xsl:text>, </xsl:text>
1503
<xsl:when test="$single.year.ranges = 0
1504
and $nextyear = $firstyear + 2">
1505
<xsl:value-of select="$firstyear"/>
1506
<xsl:text>, </xsl:text>
1507
<xsl:value-of select="$nextyear - 1"/>
1508
<xsl:text>, </xsl:text>
1511
<xsl:value-of select="$firstyear"/>
1512
<xsl:text>-</xsl:text>
1513
<xsl:value-of select="$nextyear - 1"/>
1514
<xsl:text>, </xsl:text>
1517
<xsl:call-template name="copyright.years">
1518
<xsl:with-param name="years"
1519
select="$years[position() > 1]"/>
1520
<xsl:with-param name="firstyear" select="$years[1]"/>
1521
<xsl:with-param name="nextyear" select="$years[1] + 1"/>
1522
<xsl:with-param name="print.ranges" select="$print.ranges"/>
1523
<xsl:with-param name="single.year.ranges"
1524
select="$single.year.ranges"/>
1525
</xsl:call-template>
1530
<!-- ====================================================================== -->
1532
<doc:template name="find.path.params" xmlns="">
1533
<refpurpose>Search in a table for the "best" match for the node</refpurpose>
1536
<para>This template searches in a table for the value that most-closely
1537
(in the typical best-match sense of XSLT) matches the current (element)
1538
node location.</para>
1542
<xsl:template name="find.path.params">
1543
<xsl:param name="node" select="."/>
1544
<xsl:param name="table" select="''"/>
1545
<xsl:param name="location">
1546
<xsl:call-template name="xpath.location">
1547
<xsl:with-param name="node" select="$node"/>
1548
</xsl:call-template>
1551
<xsl:variable name="value">
1552
<xsl:call-template name="lookup.key">
1553
<xsl:with-param name="key" select="$location"/>
1554
<xsl:with-param name="table" select="$table"/>
1555
</xsl:call-template>
1559
<xsl:when test="$value != ''">
1560
<xsl:value-of select="$value"/>
1562
<xsl:when test="contains($location, '/')">
1563
<xsl:call-template name="find.path.params">
1564
<xsl:with-param name="node" select="$node"/>
1565
<xsl:with-param name="table" select="$table"/>
1566
<xsl:with-param name="location" select="substring-after($location, '/')"/>
1567
</xsl:call-template>