2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
4 xmlns:dyn="http://exslt.org/dynamic"
5 xmlns:saxon="http://icl.com/saxon"
6 exclude-result-prefixes="doc dyn saxon"
9 <!-- ********************************************************************
10 $Id: common.xsl 8784 2010-07-28 12:32:54Z mzjn $
11 ********************************************************************
13 This file is part of the XSL DocBook Stylesheet distribution.
14 See ../README or http://docbook.sf.net/release/xsl/current/ for
15 copyright and other information.
17 ******************************************************************** -->
19 <doc:reference xmlns="" xml:id="base">
21 <title>Common » Base Template Reference</title>
22 <releaseinfo role="meta">
23 $Id: common.xsl 8784 2010-07-28 12:32:54Z mzjn $
26 <!-- * yes, partintro is a valid child of a reference... -->
27 <partintro xml:id="partintro">
28 <title>Introduction</title>
29 <para>This is technical reference documentation for the “base”
30 set of common templates in the DocBook XSL Stylesheets.</para>
31 <para>This is not intended to be user documentation. It is
32 provided for developers writing customization layers for the
37 <!-- ==================================================================== -->
38 <!-- Establish strip/preserve whitespace rules -->
40 <xsl:preserve-space elements="*"/>
42 <xsl:strip-space elements="
43 abstract affiliation anchor answer appendix area areaset areaspec
44 artheader article audiodata audioobject author authorblurb authorgroup
45 beginpage bibliodiv biblioentry bibliography biblioset blockquote book
46 bookbiblio bookinfo callout calloutlist caption caution chapter
47 citerefentry cmdsynopsis co collab colophon colspec confgroup
48 copyright dedication docinfo editor entrytbl epigraph equation
49 example figure footnote footnoteref formalpara funcprototype
50 funcsynopsis glossary glossdef glossdiv glossentry glosslist graphicco
51 group highlights imagedata imageobject imageobjectco important index
52 indexdiv indexentry indexterm info informalequation informalexample
53 informalfigure informaltable inlineequation inlinemediaobject
54 itemizedlist itermset keycombo keywordset legalnotice listitem lot
55 mediaobject mediaobjectco menuchoice msg msgentry msgexplan msginfo
56 msgmain msgrel msgset msgsub msgtext note objectinfo
57 orderedlist othercredit part partintro preface printhistory procedure
58 programlistingco publisher qandadiv qandaentry qandaset question
59 refentry reference refmeta refnamediv refsection refsect1 refsect1info refsect2
60 refsect2info refsect3 refsect3info refsynopsisdiv refsynopsisdivinfo
61 revhistory revision row sbr screenco screenshot sect1 sect1info sect2
62 sect2info sect3 sect3info sect4 sect4info sect5 sect5info section
63 sectioninfo seglistitem segmentedlist seriesinfo set setindex setinfo
64 shortcut sidebar simplelist simplesect spanspec step subject
65 subjectset substeps synopfragment table tbody textobject tfoot tgroup
66 thead tip toc tocchap toclevel1 toclevel2 toclevel3 toclevel4
67 toclevel5 tocpart varargs variablelist varlistentry videodata
68 videoobject void warning subjectset
82 <!-- ====================================================================== -->
84 <doc:template name="is.component" xmlns="">
85 <refpurpose>Tests if a given node is a component-level element</refpurpose>
87 <refdescription id="is.component-desc">
88 <para>This template returns '1' if the specified node is a component
89 (Chapter, Appendix, etc.), and '0' otherwise.</para>
92 <refparameter id="is.component-params">
94 <varlistentry><term>node</term>
96 <para>The node which is to be tested.</para>
102 <refreturn id="is.component-returns">
103 <para>This template returns '1' if the specified node is a component
104 (Chapter, Appendix, etc.), and '0' otherwise.</para>
108 <xsl:template name="is.component">
109 <xsl:param name="node" select="."/>
111 <xsl:when test="local-name($node) = 'appendix'
112 or local-name($node) = 'article'
113 or local-name($node) = 'chapter'
114 or local-name($node) = 'preface'
115 or local-name($node) = 'bibliography'
116 or local-name($node) = 'glossary'
117 or local-name($node) = 'index'">1</xsl:when>
118 <xsl:otherwise>0</xsl:otherwise>
122 <!-- ====================================================================== -->
124 <doc:template name="is.section" xmlns="">
125 <refpurpose>Tests if a given node is a section-level element</refpurpose>
127 <refdescription id="is.section-desc">
128 <para>This template returns '1' if the specified node is a section
129 (Section, Sect1, Sect2, etc.), and '0' otherwise.</para>
132 <refparameter id="is.section-params">
134 <varlistentry><term>node</term>
136 <para>The node which is to be tested.</para>
142 <refreturn id="is.section-returns">
143 <para>This template returns '1' if the specified node is a section
144 (Section, Sect1, Sect2, etc.), and '0' otherwise.</para>
148 <xsl:template name="is.section">
149 <xsl:param name="node" select="."/>
151 <xsl:when test="local-name($node) = 'section'
152 or local-name($node) = 'sect1'
153 or local-name($node) = 'sect2'
154 or local-name($node) = 'sect3'
155 or local-name($node) = 'sect4'
156 or local-name($node) = 'sect5'
157 or local-name($node) = 'refsect1'
158 or local-name($node) = 'refsect2'
159 or local-name($node) = 'refsect3'
160 or local-name($node) = 'simplesect'">1</xsl:when>
161 <xsl:otherwise>0</xsl:otherwise>
165 <!-- ====================================================================== -->
167 <doc:template name="section.level" xmlns="">
168 <refpurpose>Returns the hierarchical level of a section</refpurpose>
170 <refdescription id="section.level-desc">
171 <para>This template calculates the hierarchical level of a section.
172 The element <tag>sect1</tag> is at level 1, <tag>sect2</tag> is
173 at level 2, etc.</para>
175 <para>Recursive sections are calculated down to the fifth level.</para>
178 <refparameter id="section.level-params">
180 <varlistentry><term>node</term>
182 <para>The section node for which the level should be calculated.
183 Defaults to the context node.</para>
189 <refreturn id="section.level-returns">
190 <para>The section level, <quote>1</quote>, <quote>2</quote>, etc.
195 <xsl:template name="section.level">
196 <xsl:param name="node" select="."/>
198 <xsl:when test="local-name($node)='sect1'">1</xsl:when>
199 <xsl:when test="local-name($node)='sect2'">2</xsl:when>
200 <xsl:when test="local-name($node)='sect3'">3</xsl:when>
201 <xsl:when test="local-name($node)='sect4'">4</xsl:when>
202 <xsl:when test="local-name($node)='sect5'">5</xsl:when>
203 <xsl:when test="local-name($node)='section'">
205 <xsl:when test="$node/../../../../../../section">6</xsl:when>
206 <xsl:when test="$node/../../../../../section">5</xsl:when>
207 <xsl:when test="$node/../../../../section">4</xsl:when>
208 <xsl:when test="$node/../../../section">3</xsl:when>
209 <xsl:when test="$node/../../section">2</xsl:when>
210 <xsl:otherwise>1</xsl:otherwise>
213 <xsl:when test="local-name($node)='refsect1' or
214 local-name($node)='refsect2' or
215 local-name($node)='refsect3' or
216 local-name($node)='refsection' or
217 local-name($node)='refsynopsisdiv'">
218 <xsl:call-template name="refentry.section.level">
219 <xsl:with-param name="node" select="$node"/>
222 <xsl:when test="local-name($node)='simplesect'">
224 <xsl:when test="$node/../../sect1">2</xsl:when>
225 <xsl:when test="$node/../../sect2">3</xsl:when>
226 <xsl:when test="$node/../../sect3">4</xsl:when>
227 <xsl:when test="$node/../../sect4">5</xsl:when>
228 <xsl:when test="$node/../../sect5">5</xsl:when>
229 <xsl:when test="$node/../../section">
231 <xsl:when test="$node/../../../../../section">5</xsl:when>
232 <xsl:when test="$node/../../../../section">4</xsl:when>
233 <xsl:when test="$node/../../../section">3</xsl:when>
234 <xsl:otherwise>2</xsl:otherwise>
237 <xsl:otherwise>1</xsl:otherwise>
240 <xsl:otherwise>1</xsl:otherwise>
242 </xsl:template><!-- section.level -->
244 <doc:template name="qanda.section.level" xmlns="">
245 <refpurpose>Returns the hierarchical level of a QandASet</refpurpose>
247 <refdescription id="qanda.section.level-desc">
248 <para>This template calculates the hierarchical level of a QandASet.
252 <refreturn id="qanda.section.level-returns">
253 <para>The level, <quote>1</quote>, <quote>2</quote>, etc.
258 <xsl:template name="qanda.section.level">
259 <xsl:variable name="section"
260 select="(ancestor::section
261 |ancestor::simplesect
269 |ancestor::refsect1)[last()]"/>
272 <xsl:when test="count($section) = '0'">1</xsl:when>
274 <xsl:variable name="slevel">
275 <xsl:call-template name="section.level">
276 <xsl:with-param name="node" select="$section"/>
279 <xsl:value-of select="$slevel + 1"/>
284 <!-- Finds the total section depth of a section in a refentry -->
285 <xsl:template name="refentry.section.level">
286 <xsl:param name="node" select="."/>
288 <xsl:variable name="RElevel">
289 <xsl:call-template name="refentry.level">
290 <xsl:with-param name="node" select="$node/ancestor::refentry[1]"/>
294 <xsl:variable name="levelinRE">
296 <xsl:when test="local-name($node)='refsynopsisdiv'">1</xsl:when>
297 <xsl:when test="local-name($node)='refsect1'">1</xsl:when>
298 <xsl:when test="local-name($node)='refsect2'">2</xsl:when>
299 <xsl:when test="local-name($node)='refsect3'">3</xsl:when>
300 <xsl:when test="local-name($node)='refsection'">
302 <xsl:when test="$node/../../../../../refsection">5</xsl:when>
303 <xsl:when test="$node/../../../../refsection">4</xsl:when>
304 <xsl:when test="$node/../../../refsection">3</xsl:when>
305 <xsl:when test="$node/../../refsection">2</xsl:when>
306 <xsl:otherwise>1</xsl:otherwise>
312 <xsl:value-of select="$levelinRE + $RElevel"/>
315 <!-- Finds the section depth of a refentry -->
316 <xsl:template name="refentry.level">
317 <xsl:param name="node" select="."/>
318 <xsl:variable name="container"
319 select="($node/ancestor::section |
320 $node/ancestor::sect1 |
321 $node/ancestor::sect2 |
322 $node/ancestor::sect3 |
323 $node/ancestor::sect4 |
324 $node/ancestor::sect5)[last()]"/>
327 <xsl:when test="$container">
328 <xsl:variable name="slevel">
329 <xsl:call-template name="section.level">
330 <xsl:with-param name="node" select="$container"/>
333 <xsl:value-of select="$slevel + 1"/>
335 <xsl:otherwise>1</xsl:otherwise>
339 <xsl:template name="qandadiv.section.level">
340 <xsl:variable name="section.level">
341 <xsl:call-template name="qanda.section.level"/>
343 <xsl:variable name="anc.divs" select="ancestor::qandadiv"/>
345 <xsl:value-of select="count($anc.divs) + number($section.level)"/>
348 <xsl:template name="question.answer.label">
349 <xsl:variable name="deflabel">
351 <xsl:when test="ancestor-or-self::*[@defaultlabel]">
352 <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
356 <xsl:value-of select="$qanda.defaultlabel"/>
361 <xsl:variable name="label" select="@label"/>
364 (hnr (hierarchical-number-recursive (normalize "qandadiv") node))
366 (parsect (ancestor-member node (section-element-list)))
368 (defnum (if (and %qanda-inherit-numeration%
370 (if (node-list-empty? parsect)
371 (section-autolabel-prefix node)
372 (section-autolabel parsect))
375 (hnumber (let loop ((numlist hnr) (number defnum)
376 (sep (if (equal? defnum "") "" ".")))
380 (string-append number
382 (number->string (car numlist)))
384 (cnumber (child-number (parent node)))
385 (number (string-append hnumber
386 (if (equal? hnumber "")
389 (number->string cnumber))))
393 <xsl:when test="$deflabel = 'qanda'">
394 <xsl:call-template name="gentext">
395 <xsl:with-param name="key">
397 <xsl:when test="local-name(.) = 'question'">question</xsl:when>
398 <xsl:when test="local-name(.) = 'answer'">answer</xsl:when>
399 <xsl:when test="local-name(.) = 'qandadiv'">qandadiv</xsl:when>
400 <xsl:otherwise>qandaset</xsl:otherwise>
405 <xsl:when test="$deflabel = 'label'">
406 <xsl:value-of select="$label"/>
408 <xsl:when test="$deflabel = 'number'
409 and local-name(.) = 'question'">
410 <xsl:apply-templates select="ancestor::qandaset[1]"
413 <xsl:when test="ancestor::qandadiv">
414 <xsl:apply-templates select="ancestor::qandadiv[1]"
416 <xsl:apply-templates select="ancestor::qandaentry"
420 <xsl:apply-templates select="ancestor::qandaentry"
431 <xsl:template match="qandaset" mode="number">
435 <xsl:template match="qandadiv" mode="number">
436 <xsl:number level="multiple" from="qandaset" format="1."/>
439 <xsl:template match="qandaentry" mode="number">
441 <xsl:when test="ancestor::qandadiv">
442 <xsl:number level="single" from="qandadiv" format="1."/>
445 <xsl:number level="single" from="qandaset" format="1."/>
450 <!-- ====================================================================== -->
452 <xsl:template name="object.id">
453 <xsl:param name="object" select="."/>
455 <xsl:when test="$object/@id">
456 <xsl:value-of select="$object/@id"/>
458 <xsl:when test="$object/@xml:id">
459 <xsl:value-of select="$object/@xml:id"/>
462 <xsl:value-of select="generate-id($object)"/>
467 <xsl:template name="person.name">
468 <!-- Formats a personal name. Handles corpauthor as a special case. -->
469 <xsl:param name="node" select="."/>
471 <xsl:variable name="style">
473 <xsl:when test="$node/@role">
474 <xsl:value-of select="$node/@role"/>
477 <xsl:call-template name="gentext.template">
478 <xsl:with-param name="context" select="'styles'"/>
479 <xsl:with-param name="name" select="'person-name'"/>
486 <!-- the personname element is a specialcase -->
487 <xsl:when test="$node/personname">
488 <xsl:call-template name="person.name">
489 <xsl:with-param name="node" select="$node/personname"/>
493 <!-- handle corpauthor as a special case...-->
494 <!-- * MikeSmith 2007-06: I'm wondering if the person.name template -->
495 <!-- * actually ever gets called to handle corpauthor.. maybe -->
496 <!-- * we don't actually need to check for corpauthor here. -->
497 <xsl:when test="local-name($node)='corpauthor'">
498 <xsl:apply-templates select="$node"/>
503 <!-- Handle case when personname contains only general markup (DocBook 5.0) -->
504 <xsl:when test="$node/self::personname and not($node/firstname or $node/honorific or $node/lineage or $node/othername or $node/surname)">
505 <xsl:apply-templates select="$node/node()"/>
507 <xsl:when test="$style = 'family-given'">
508 <xsl:call-template name="person.name.family-given">
509 <xsl:with-param name="node" select="$node"/>
512 <xsl:when test="$style = 'last-first'">
513 <xsl:call-template name="person.name.last-first">
514 <xsl:with-param name="node" select="$node"/>
518 <xsl:call-template name="person.name.first-last">
519 <xsl:with-param name="node" select="$node"/>
527 <xsl:template name="person.name.family-given">
528 <xsl:param name="node" select="."/>
530 <!-- The family-given style applies a convention for identifying given -->
531 <!-- and family names in locales where it may be ambiguous -->
532 <xsl:apply-templates select="$node//surname[1]"/>
534 <xsl:if test="$node//surname and $node//firstname">
535 <xsl:text> </xsl:text>
538 <xsl:apply-templates select="$node//firstname[1]"/>
540 <xsl:text> [FAMILY Given]</xsl:text>
543 <xsl:template name="person.name.last-first">
544 <xsl:param name="node" select="."/>
546 <xsl:apply-templates select="$node//surname[1]"/>
548 <xsl:if test="$node//surname and $node//firstname">
549 <xsl:text>, </xsl:text>
552 <xsl:apply-templates select="$node//firstname[1]"/>
555 <xsl:template name="person.name.first-last">
556 <xsl:param name="node" select="."/>
558 <xsl:if test="$node//honorific">
559 <xsl:apply-templates select="$node//honorific[1]"/>
560 <xsl:value-of select="$punct.honorific"/>
563 <xsl:if test="$node//firstname">
564 <xsl:if test="$node//honorific">
565 <xsl:text> </xsl:text>
567 <xsl:apply-templates select="$node//firstname[1]"/>
570 <xsl:if test="$node//othername and $author.othername.in.middle != 0">
571 <xsl:if test="$node//honorific or $node//firstname">
572 <xsl:text> </xsl:text>
574 <xsl:apply-templates select="$node//othername[1]"/>
577 <xsl:if test="$node//surname">
578 <xsl:if test="$node//honorific or $node//firstname
579 or ($node//othername and $author.othername.in.middle != 0)">
580 <xsl:text> </xsl:text>
582 <xsl:apply-templates select="$node//surname[1]"/>
585 <xsl:if test="$node//lineage">
586 <xsl:text>, </xsl:text>
587 <xsl:apply-templates select="$node//lineage[1]"/>
591 <xsl:template name="person.name.list">
592 <!-- Return a formatted string representation of the contents of
593 the current element. The current element must contain one or
594 more AUTHORs, CORPAUTHORs, OTHERCREDITs, and/or EDITORs.
598 John Doe and Jane Doe
600 John Doe, Jane Doe, and A. Nonymous
602 <xsl:param name="person.list"
603 select="author|corpauthor|othercredit|editor"/>
604 <xsl:param name="person.count" select="count($person.list)"/>
605 <xsl:param name="count" select="1"/>
608 <xsl:when test="$count > $person.count"></xsl:when>
610 <xsl:call-template name="person.name">
611 <xsl:with-param name="node" select="$person.list[position()=$count]"/>
615 <xsl:when test="$person.count = 2 and $count = 1">
616 <xsl:call-template name="gentext.template">
617 <xsl:with-param name="context" select="'authorgroup'"/>
618 <xsl:with-param name="name" select="'sep2'"/>
621 <xsl:when test="$person.count > 2 and $count+1 = $person.count">
622 <xsl:call-template name="gentext.template">
623 <xsl:with-param name="context" select="'authorgroup'"/>
624 <xsl:with-param name="name" select="'seplast'"/>
627 <xsl:when test="$count < $person.count">
628 <xsl:call-template name="gentext.template">
629 <xsl:with-param name="context" select="'authorgroup'"/>
630 <xsl:with-param name="name" select="'sep'"/>
635 <xsl:call-template name="person.name.list">
636 <xsl:with-param name="person.list" select="$person.list"/>
637 <xsl:with-param name="person.count" select="$person.count"/>
638 <xsl:with-param name="count" select="$count+1"/>
642 </xsl:template><!-- person.name.list -->
644 <!-- === synopsis ======================================================= -->
645 <!-- The following definitions match those given in the reference
646 documentation for DocBook V3.0
649 <xsl:variable name="arg.choice.opt.open.str">[</xsl:variable>
650 <xsl:variable name="arg.choice.opt.close.str">]</xsl:variable>
651 <xsl:variable name="arg.choice.req.open.str">{</xsl:variable>
652 <xsl:variable name="arg.choice.req.close.str">}</xsl:variable>
653 <xsl:variable name="arg.choice.plain.open.str"><xsl:text> </xsl:text></xsl:variable>
654 <xsl:variable name="arg.choice.plain.close.str"><xsl:text> </xsl:text></xsl:variable>
655 <xsl:variable name="arg.choice.def.open.str">[</xsl:variable>
656 <xsl:variable name="arg.choice.def.close.str">]</xsl:variable>
657 <xsl:variable name="arg.rep.repeat.str">...</xsl:variable>
658 <xsl:variable name="arg.rep.norepeat.str"></xsl:variable>
659 <xsl:variable name="arg.rep.def.str"></xsl:variable>
660 <xsl:variable name="arg.or.sep"> | </xsl:variable>
661 <xsl:variable name="cmdsynopsis.hanging.indent">4pi</xsl:variable>
663 <!-- ====================================================================== -->
666 <xsl:template name="xref.g.subst">
667 <xsl:param name="string"></xsl:param>
668 <xsl:param name="target" select="."/>
669 <xsl:variable name="subst">%g</xsl:variable>
672 <xsl:when test="contains($string, $subst)">
673 <xsl:value-of select="substring-before($string, $subst)"/>
674 <xsl:call-template name="gentext.element.name">
675 <xsl:with-param name="element.name" select="local-name($target)"/>
677 <xsl:call-template name="xref.g.subst">
678 <xsl:with-param name="string"
679 select="substring-after($string, $subst)"/>
680 <xsl:with-param name="target" select="$target"/>
684 <xsl:value-of select="$string"/>
689 <xsl:template name="xref.t.subst">
690 <xsl:param name="string"></xsl:param>
691 <xsl:param name="target" select="."/>
692 <xsl:variable name="subst">%t</xsl:variable>
695 <xsl:when test="contains($string, $subst)">
696 <xsl:call-template name="xref.g.subst">
697 <xsl:with-param name="string"
698 select="substring-before($string, $subst)"/>
699 <xsl:with-param name="target" select="$target"/>
701 <xsl:call-template name="title.xref">
702 <xsl:with-param name="target" select="$target"/>
704 <xsl:call-template name="xref.t.subst">
705 <xsl:with-param name="string"
706 select="substring-after($string, $subst)"/>
707 <xsl:with-param name="target" select="$target"/>
711 <xsl:call-template name="xref.g.subst">
712 <xsl:with-param name="string" select="$string"/>
713 <xsl:with-param name="target" select="$target"/>
719 <xsl:template name="xref.n.subst">
720 <xsl:param name="string"></xsl:param>
721 <xsl:param name="target" select="."/>
722 <xsl:variable name="subst">%n</xsl:variable>
725 <xsl:when test="contains($string, $subst)">
726 <xsl:call-template name="xref.t.subst">
727 <xsl:with-param name="string"
728 select="substring-before($string, $subst)"/>
729 <xsl:with-param name="target" select="$target"/>
731 <xsl:call-template name="number.xref">
732 <xsl:with-param name="target" select="$target"/>
734 <xsl:call-template name="xref.t.subst">
735 <xsl:with-param name="string"
736 select="substring-after($string, $subst)"/>
737 <xsl:with-param name="target" select="$target"/>
741 <xsl:call-template name="xref.t.subst">
742 <xsl:with-param name="string" select="$string"/>
743 <xsl:with-param name="target" select="$target"/>
749 <xsl:template name="subst.xref.text">
750 <xsl:param name="xref.text"></xsl:param>
751 <xsl:param name="target" select="."/>
753 <xsl:call-template name="xref.n.subst">
754 <xsl:with-param name="string" select="$xref.text"/>
755 <xsl:with-param name="target" select="$target"/>
760 <!-- ====================================================================== -->
762 <xsl:template name="filename-basename">
763 <!-- We assume all filenames are really URIs and use "/" -->
764 <xsl:param name="filename"></xsl:param>
765 <xsl:param name="recurse" select="false()"/>
768 <xsl:when test="substring-after($filename, '/') != ''">
769 <xsl:call-template name="filename-basename">
770 <xsl:with-param name="filename"
771 select="substring-after($filename, '/')"/>
772 <xsl:with-param name="recurse" select="true()"/>
776 <xsl:value-of select="$filename"/>
781 <xsl:template name="filename-extension">
782 <xsl:param name="filename"></xsl:param>
783 <xsl:param name="recurse" select="false()"/>
785 <!-- Make sure we only look at the base name... -->
786 <xsl:variable name="basefn">
788 <xsl:when test="$recurse">
789 <xsl:value-of select="$filename"/>
792 <xsl:call-template name="filename-basename">
793 <xsl:with-param name="filename" select="$filename"/>
800 <xsl:when test="substring-after($basefn, '.') != ''">
801 <xsl:call-template name="filename-extension">
802 <xsl:with-param name="filename"
803 select="substring-after($basefn, '.')"/>
804 <xsl:with-param name="recurse" select="true()"/>
807 <xsl:when test="$recurse">
808 <xsl:value-of select="$basefn"/>
810 <xsl:otherwise></xsl:otherwise>
814 <!-- ====================================================================== -->
816 <doc:template name="select.mediaobject" xmlns="">
817 <refpurpose>Selects and processes an appropriate media object from a list</refpurpose>
819 <refdescription id="select.mediaobject-desc">
820 <para>This template takes a list of media objects (usually the
821 children of a mediaobject or inlinemediaobject) and processes
822 the "right" object.</para>
824 <para>This template relies on a template named
825 "select.mediaobject.index" to determine which object
826 in the list is appropriate.</para>
828 <para>If no acceptable object is located, nothing happens.</para>
831 <refparameter id="select.mediaobject-params">
833 <varlistentry><term>olist</term>
835 <para>The node list of potential objects to examine.</para>
841 <refreturn id="select.mediaobject-returns">
842 <para>Calls <xsl:apply-templates> on the selected object.</para>
846 <xsl:template name="select.mediaobject">
847 <xsl:param name="olist"
848 select="imageobject|imageobjectco
849 |videoobject|audioobject|textobject"/>
851 <xsl:variable name="mediaobject.index">
852 <xsl:call-template name="select.mediaobject.index">
853 <xsl:with-param name="olist" select="$olist"/>
854 <xsl:with-param name="count" select="1"/>
858 <xsl:if test="$mediaobject.index != ''">
859 <xsl:apply-templates select="$olist[position() = $mediaobject.index]"/>
863 <!-- ====================================================================== -->
865 <doc:template name="select.mediaobject.index" xmlns="">
866 <refpurpose>Selects the position of the appropriate media object from a list</refpurpose>
868 <refdescription id="select.mediaobject.index-desc">
869 <para>This template takes a list of media objects (usually the
870 children of a mediaobject or inlinemediaobject) and determines
871 the "right" object. It returns the position of that object
872 to be used by the calling template.</para>
874 <para>If the parameter <parameter>use.role.for.mediaobject</parameter>
875 is nonzero, then it first checks for an object with
876 a role attribute of the appropriate value. It takes the first
877 of those. Otherwise, it takes the first acceptable object
878 through a recursive pass through the list.</para>
880 <para>This template relies on a template named "is.acceptable.mediaobject"
881 to determine if a given object is an acceptable graphic. The semantics
882 of media objects is that the first acceptable graphic should be used.
885 <para>If no acceptable object is located, no index is returned.</para>
888 <refparameter id="select.mediaobject.index-params">
890 <varlistentry><term>olist</term>
892 <para>The node list of potential objects to examine.</para>
895 <varlistentry><term>count</term>
897 <para>The position in the list currently being considered by the
898 recursive process.</para>
904 <refreturn id="select.mediaobject.index-returns">
905 <para>Returns the position in the original list of the selected object.</para>
909 <xsl:template name="select.mediaobject.index">
910 <xsl:param name="olist"
911 select="imageobject|imageobjectco
912 |videoobject|audioobject|textobject"/>
913 <xsl:param name="count">1</xsl:param>
916 <!-- Test for objects preferred by role -->
917 <xsl:when test="$use.role.for.mediaobject != 0
918 and $preferred.mediaobject.role != ''
919 and $olist[@role = $preferred.mediaobject.role]">
921 <!-- Get the first hit's position index -->
922 <xsl:for-each select="$olist">
923 <xsl:if test="@role = $preferred.mediaobject.role and
924 not(preceding-sibling::*[@role = $preferred.mediaobject.role])">
925 <xsl:value-of select="position()"/>
930 <xsl:when test="$use.role.for.mediaobject != 0
931 and $olist[@role = $stylesheet.result.type]">
932 <!-- Get the first hit's position index -->
933 <xsl:for-each select="$olist">
934 <xsl:if test="@role = $stylesheet.result.type and
935 not(preceding-sibling::*[@role = $stylesheet.result.type])">
936 <xsl:value-of select="position()"/>
940 <!-- Accept 'html' for $stylesheet.result.type = 'xhtml' -->
941 <xsl:when test="$use.role.for.mediaobject != 0
942 and $stylesheet.result.type = 'xhtml'
943 and $olist[@role = 'html']">
944 <!-- Get the first hit's position index -->
945 <xsl:for-each select="$olist">
946 <xsl:if test="@role = 'html' and
947 not(preceding-sibling::*[@role = 'html'])">
948 <xsl:value-of select="position()"/>
953 <!-- If no selection by role, and there is only one object, use it -->
954 <xsl:when test="count($olist) = 1 and $count = 1">
955 <xsl:value-of select="$count"/>
959 <!-- Otherwise select first acceptable object -->
960 <xsl:if test="$count <= count($olist)">
961 <xsl:variable name="object" select="$olist[position()=$count]"/>
963 <xsl:variable name="useobject">
965 <!-- The phrase is used only when contains TeX Math and output is FO -->
966 <xsl:when test="local-name($object)='textobject' and $object/phrase
967 and $object/@role='tex' and $stylesheet.result.type = 'fo'
968 and $tex.math.in.alt != ''">
969 <xsl:text>1</xsl:text>
971 <!-- The phrase is never used -->
972 <xsl:when test="local-name($object)='textobject' and $object/phrase">
973 <xsl:text>0</xsl:text>
975 <xsl:when test="local-name($object)='textobject'
976 and $object/ancestor::equation ">
977 <!-- The first textobject is not a reasonable fallback
978 for equation image -->
979 <xsl:text>0</xsl:text>
981 <!-- The first textobject is a reasonable fallback -->
982 <xsl:when test="local-name($object)='textobject'
983 and $object[not(@role) or @role!='tex']">
984 <xsl:text>1</xsl:text>
986 <!-- don't use graphic when output is FO, TeX Math is used
987 and there is math in alt element -->
988 <xsl:when test="$object/ancestor::equation and
989 $object/ancestor::equation/alt[@role='tex']
990 and $stylesheet.result.type = 'fo'
991 and $tex.math.in.alt != ''">
992 <xsl:text>0</xsl:text>
994 <!-- If there's only one object, use it -->
995 <xsl:when test="$count = 1 and count($olist) = 1">
996 <xsl:text>1</xsl:text>
998 <!-- Otherwise, see if this one is a useable graphic -->
1001 <!-- peek inside imageobjectco to simplify the test -->
1002 <xsl:when test="local-name($object) = 'imageobjectco'">
1003 <xsl:call-template name="is.acceptable.mediaobject">
1004 <xsl:with-param name="object" select="$object/imageobject"/>
1005 </xsl:call-template>
1008 <xsl:call-template name="is.acceptable.mediaobject">
1009 <xsl:with-param name="object" select="$object"/>
1010 </xsl:call-template>
1018 <xsl:when test="$useobject='1'">
1019 <xsl:value-of select="$count"/>
1022 <xsl:call-template name="select.mediaobject.index">
1023 <xsl:with-param name="olist" select="$olist"/>
1024 <xsl:with-param name="count" select="$count + 1"/>
1025 </xsl:call-template>
1033 <doc:template name="is.acceptable.mediaobject" xmlns="">
1034 <refpurpose>Returns '1' if the specified media object is recognized</refpurpose>
1036 <refdescription id="is.acceptable.mediaobject-desc">
1037 <para>This template examines a media object and returns '1' if the
1038 object is recognized as a graphic.</para>
1041 <refparameter id="is.acceptable.mediaobject-params">
1043 <varlistentry><term>object</term>
1045 <para>The media object to consider.</para>
1051 <refreturn id="is.acceptable.mediaobject-returns">
1056 <xsl:template name="is.acceptable.mediaobject">
1057 <xsl:param name="object"></xsl:param>
1059 <xsl:variable name="filename">
1060 <xsl:call-template name="mediaobject.filename">
1061 <xsl:with-param name="object" select="$object"/>
1062 </xsl:call-template>
1065 <xsl:variable name="ext">
1066 <xsl:call-template name="filename-extension">
1067 <xsl:with-param name="filename" select="$filename"/>
1068 </xsl:call-template>
1071 <!-- there will only be one -->
1072 <xsl:variable name="data" select="$object/videodata
1074 |$object/audiodata"/>
1076 <xsl:variable name="format" select="$data/@format"/>
1078 <xsl:variable name="graphic.format">
1079 <xsl:if test="$format">
1080 <xsl:call-template name="is.graphic.format">
1081 <xsl:with-param name="format" select="$format"/>
1082 </xsl:call-template>
1086 <xsl:variable name="graphic.ext">
1087 <xsl:if test="$ext">
1088 <xsl:call-template name="is.graphic.extension">
1089 <xsl:with-param name="ext" select="$ext"/>
1090 </xsl:call-template>
1095 <xsl:when test="$use.svg = 0 and $format = 'SVG'">0</xsl:when>
1096 <xsl:when xmlns:svg="http://www.w3.org/2000/svg"
1097 test="$use.svg != 0 and $object/svg:*">1</xsl:when>
1098 <xsl:when test="$graphic.format = '1'">1</xsl:when>
1099 <xsl:when test="$graphic.ext = '1'">1</xsl:when>
1100 <xsl:otherwise>0</xsl:otherwise>
1104 <xsl:template name="mediaobject.filename">
1105 <xsl:param name="object"></xsl:param>
1107 <xsl:variable name="data" select="$object/videodata
1112 <xsl:variable name="filename">
1114 <xsl:when test="$data[@fileref]">
1115 <xsl:apply-templates select="$data/@fileref"/>
1117 <xsl:when test="$data[@entityref]">
1118 <xsl:value-of select="unparsed-entity-uri($data/@entityref)"/>
1120 <xsl:otherwise></xsl:otherwise>
1124 <xsl:variable name="real.ext">
1125 <xsl:call-template name="filename-extension">
1126 <xsl:with-param name="filename" select="$filename"/>
1127 </xsl:call-template>
1130 <xsl:variable name="ext">
1132 <xsl:when test="$real.ext != ''">
1133 <xsl:value-of select="$real.ext"/>
1136 <xsl:value-of select="$graphic.default.extension"/>
1141 <xsl:variable name="graphic.ext">
1142 <xsl:call-template name="is.graphic.extension">
1143 <xsl:with-param name="ext" select="$ext"/>
1144 </xsl:call-template>
1148 <xsl:when test="$real.ext = ''">
1150 <xsl:when test="$ext != ''">
1151 <xsl:value-of select="$filename"/>
1152 <xsl:text>.</xsl:text>
1153 <xsl:value-of select="$ext"/>
1156 <xsl:value-of select="$filename"/>
1160 <xsl:when test="not($graphic.ext)">
1162 <xsl:when test="$graphic.default.extension != ''">
1163 <xsl:value-of select="$filename"/>
1164 <xsl:text>.</xsl:text>
1165 <xsl:value-of select="$graphic.default.extension"/>
1168 <xsl:value-of select="$filename"/>
1173 <xsl:value-of select="$filename"/>
1178 <!-- ====================================================================== -->
1180 <doc:template name="check.id.unique" xmlns="">
1181 <refpurpose>Warn users about references to non-unique IDs</refpurpose>
1182 <refdescription id="check.id.unique-desc">
1183 <para>If passed an ID in <varname>linkend</varname>,
1184 <function>check.id.unique</function> prints
1185 a warning message to the user if either the ID does not exist or
1186 the ID is not unique.</para>
1190 <xsl:template name="check.id.unique">
1191 <xsl:param name="linkend"></xsl:param>
1192 <xsl:if test="$linkend != ''">
1193 <xsl:variable name="targets" select="key('id',$linkend)"/>
1194 <xsl:variable name="target" select="$targets[1]"/>
1196 <xsl:if test="count($targets)=0">
1198 <xsl:text>Error: no ID for constraint linkend: </xsl:text>
1199 <xsl:value-of select="$linkend"/>
1200 <xsl:text>.</xsl:text>
1204 <xsl:text>If the ID exists in your document, did your </xsl:text>
1205 <xsl:text>XSLT Processor load the DTD?</xsl:text>
1210 <xsl:if test="count($targets)>1">
1212 <xsl:text>Warning: multiple "IDs" for constraint linkend: </xsl:text>
1213 <xsl:value-of select="$linkend"/>
1214 <xsl:text>.</xsl:text>
1220 <doc:template name="check.idref.targets" xmlns="">
1221 <refpurpose>Warn users about incorrectly typed references</refpurpose>
1222 <refdescription id="check.idref.targets-desc">
1223 <para>If passed an ID in <varname>linkend</varname>,
1224 <function>check.idref.targets</function> makes sure that the element
1225 pointed to by the link is one of the elements listed in
1226 <varname>element-list</varname> and warns the user otherwise.</para>
1230 <xsl:template name="check.idref.targets">
1231 <xsl:param name="linkend"></xsl:param>
1232 <xsl:param name="element-list"></xsl:param>
1233 <xsl:if test="$linkend != ''">
1234 <xsl:variable name="targets" select="key('id',$linkend)"/>
1235 <xsl:variable name="target" select="$targets[1]"/>
1237 <xsl:if test="count($target) > 0">
1238 <xsl:if test="not(contains(concat(' ', $element-list, ' '), local-name($target)))">
1240 <xsl:text>Error: linkend (</xsl:text>
1241 <xsl:value-of select="$linkend"/>
1242 <xsl:text>) points to "</xsl:text>
1243 <xsl:value-of select="local-name($target)"/>
1244 <xsl:text>" not (one of): </xsl:text>
1245 <xsl:value-of select="$element-list"/>
1252 <!-- ====================================================================== -->
1253 <!-- Procedure Step Numeration -->
1255 <xsl:param name="procedure.step.numeration.formats" select="'1aiAI'"/>
1257 <xsl:template name="procedure.step.numeration">
1258 <xsl:param name="context" select="."/>
1259 <xsl:variable name="format.length"
1260 select="string-length($procedure.step.numeration.formats)"/>
1262 <xsl:when test="local-name($context) = 'substeps'">
1263 <xsl:variable name="ssdepth"
1264 select="count($context/ancestor::substeps)"/>
1265 <xsl:variable name="sstype" select="($ssdepth mod $format.length)+2"/>
1267 <xsl:when test="$sstype > $format.length">
1268 <xsl:value-of select="substring($procedure.step.numeration.formats,1,1)"/>
1271 <xsl:value-of select="substring($procedure.step.numeration.formats,$sstype,1)"/>
1275 <xsl:when test="local-name($context) = 'step'">
1276 <xsl:variable name="sdepth"
1277 select="count($context/ancestor::substeps)"/>
1278 <xsl:variable name="stype" select="($sdepth mod $format.length)+1"/>
1279 <xsl:value-of select="substring($procedure.step.numeration.formats,$stype,1)"/>
1283 <xsl:text>Unexpected context in procedure.step.numeration: </xsl:text>
1284 <xsl:value-of select="local-name($context)"/>
1290 <xsl:template match="step" mode="number">
1291 <xsl:param name="rest" select="''"/>
1292 <xsl:param name="recursive" select="1"/>
1293 <xsl:variable name="format">
1294 <xsl:call-template name="procedure.step.numeration"/>
1296 <xsl:variable name="num">
1297 <xsl:number count="step" format="{$format}"/>
1300 <xsl:when test="$recursive != 0 and ancestor::step">
1301 <xsl:apply-templates select="ancestor::step[1]" mode="number">
1302 <xsl:with-param name="rest" select="concat('.', $num, $rest)"/>
1303 </xsl:apply-templates>
1306 <xsl:value-of select="concat($num, $rest)"/>
1311 <!-- ====================================================================== -->
1312 <!-- OrderedList Numeration -->
1313 <xsl:template name="output-orderedlist-starting-number">
1314 <xsl:param name="list"/>
1315 <xsl:param name="pi-start"/>
1317 <xsl:when test="not($list/@continuation = 'continues')">
1319 <xsl:when test="$list/@startingnumber">
1320 <xsl:value-of select="$list/@startingnumber"/>
1322 <xsl:when test="$pi-start != ''">
1323 <xsl:value-of select="$pi-start"/>
1325 <xsl:otherwise>1</xsl:otherwise>
1329 <xsl:variable name="prevlist"
1330 select="$list/preceding::orderedlist[1]"/>
1332 <xsl:when test="count($prevlist) = 0">2</xsl:when>
1334 <xsl:variable name="prevlength" select="count($prevlist/listitem)"/>
1335 <xsl:variable name="prevstart">
1336 <xsl:call-template name="orderedlist-starting-number">
1337 <xsl:with-param name="list" select="$prevlist"/>
1338 </xsl:call-template>
1340 <xsl:value-of select="$prevstart + $prevlength"/>
1347 <xsl:template name="orderedlist-item-number">
1348 <!-- context node must be a listitem in an orderedlist -->
1349 <xsl:param name="node" select="."/>
1351 <xsl:when test="$node/@override">
1352 <xsl:value-of select="$node/@override"/>
1354 <xsl:when test="$node/preceding-sibling::listitem">
1355 <xsl:variable name="pnum">
1356 <xsl:call-template name="orderedlist-item-number">
1357 <xsl:with-param name="node" select="$node/preceding-sibling::listitem[1]"/>
1358 </xsl:call-template>
1360 <xsl:value-of select="$pnum + 1"/>
1363 <xsl:call-template name="orderedlist-starting-number">
1364 <xsl:with-param name="list" select="parent::*"/>
1365 </xsl:call-template>
1370 <xsl:template name="next.numeration">
1371 <xsl:param name="numeration" select="'default'"/>
1373 <!-- Change this list if you want to change the order of numerations -->
1374 <xsl:when test="$numeration = 'arabic'">loweralpha</xsl:when>
1375 <xsl:when test="$numeration = 'loweralpha'">lowerroman</xsl:when>
1376 <xsl:when test="$numeration = 'lowerroman'">upperalpha</xsl:when>
1377 <xsl:when test="$numeration = 'upperalpha'">upperroman</xsl:when>
1378 <xsl:when test="$numeration = 'upperroman'">arabic</xsl:when>
1379 <xsl:otherwise>arabic</xsl:otherwise>
1383 <xsl:template name="list.numeration">
1384 <xsl:param name="node" select="."/>
1387 <xsl:when test="$node/@numeration">
1388 <xsl:value-of select="$node/@numeration"/>
1392 <xsl:when test="$node/ancestor::orderedlist">
1393 <xsl:call-template name="next.numeration">
1394 <xsl:with-param name="numeration">
1395 <xsl:call-template name="list.numeration">
1396 <xsl:with-param name="node" select="$node/ancestor::orderedlist[1]"/>
1397 </xsl:call-template>
1399 </xsl:call-template>
1402 <xsl:call-template name="next.numeration"/>
1409 <xsl:template match="orderedlist/listitem" mode="item-number">
1410 <xsl:variable name="numeration">
1411 <xsl:call-template name="list.numeration">
1412 <xsl:with-param name="node" select="parent::orderedlist"/>
1413 </xsl:call-template>
1416 <xsl:variable name="type">
1418 <xsl:when test="$numeration='arabic'">1.</xsl:when>
1419 <xsl:when test="$numeration='loweralpha'">a.</xsl:when>
1420 <xsl:when test="$numeration='lowerroman'">i.</xsl:when>
1421 <xsl:when test="$numeration='upperalpha'">A.</xsl:when>
1422 <xsl:when test="$numeration='upperroman'">I.</xsl:when>
1423 <!-- What!? This should never happen -->
1426 <xsl:text>Unexpected numeration: </xsl:text>
1427 <xsl:value-of select="$numeration"/>
1429 <xsl:value-of select="1."/>
1434 <xsl:variable name="item-number">
1435 <xsl:call-template name="orderedlist-item-number"/>
1438 <xsl:if test="parent::orderedlist/@inheritnum='inherit'
1439 and ancestor::listitem[parent::orderedlist]">
1440 <xsl:apply-templates select="ancestor::listitem[parent::orderedlist][1]"
1441 mode="item-number"/>
1444 <xsl:number value="$item-number" format="{$type}"/>
1447 <!-- ====================================================================== -->
1448 <!-- ItemizedList "Numeration" -->
1450 <xsl:template name="next.itemsymbol">
1451 <xsl:param name="itemsymbol" select="'default'"/>
1453 <!-- Change this list if you want to change the order of symbols -->
1454 <xsl:when test="$itemsymbol = 'disc'">circle</xsl:when>
1455 <xsl:when test="$itemsymbol = 'circle'">square</xsl:when>
1456 <xsl:otherwise>disc</xsl:otherwise>
1460 <xsl:template name="list.itemsymbol">
1461 <xsl:param name="node" select="."/>
1464 <xsl:when test="@override">
1465 <xsl:value-of select="@override"/>
1467 <xsl:when test="$node/@mark">
1468 <xsl:value-of select="$node/@mark"/>
1472 <xsl:when test="$node/ancestor::itemizedlist">
1473 <xsl:call-template name="next.itemsymbol">
1474 <xsl:with-param name="itemsymbol">
1475 <xsl:call-template name="list.itemsymbol">
1476 <xsl:with-param name="node" select="$node/ancestor::itemizedlist[1]"/>
1477 </xsl:call-template>
1479 </xsl:call-template>
1482 <xsl:call-template name="next.itemsymbol"/>
1489 <!-- ====================================================================== -->
1491 <doc:template name="copyright.years" xmlns="">
1492 <refpurpose>Print a set of years with collapsed ranges</refpurpose>
1494 <refdescription id="copyright.years-desc">
1495 <para>This template prints a list of year elements with consecutive
1496 years printed as a range. In other words:</para>
1498 <screen><![CDATA[<year>1992</year>
1500 <year>1994</year>]]></screen>
1502 <para>is printed <quote>1992-1994</quote>, whereas:</para>
1504 <screen><![CDATA[<year>1992</year>
1505 <year>1994</year>]]></screen>
1507 <para>is printed <quote>1992, 1994</quote>.</para>
1509 <para>This template assumes that all the year elements contain only
1510 decimal year numbers, that the elements are sorted in increasing
1511 numerical order, that there are no duplicates, and that all the years
1512 are expressed in full <quote>century+year</quote>
1513 (<quote>1999</quote> not <quote>99</quote>) notation.</para>
1516 <refparameter id="copyright.years-params">
1518 <varlistentry><term>years</term>
1520 <para>The initial set of year elements.</para>
1523 <varlistentry><term>print.ranges</term>
1525 <para>If non-zero, multi-year ranges are collapsed. If zero, all years
1526 are printed discretely.</para>
1529 <varlistentry><term>single.year.ranges</term>
1531 <para>If non-zero, two consecutive years will be printed as a range,
1532 otherwise, they will be printed discretely. In other words, a single
1533 year range is <quote>1991-1992</quote> but discretely it's
1534 <quote>1991, 1992</quote>.</para>
1540 <refreturn id="copyright.years-returns">
1541 <para>This template returns the formatted list of years.</para>
1545 <xsl:template name="copyright.years">
1546 <xsl:param name="years"/>
1547 <xsl:param name="print.ranges" select="1"/>
1548 <xsl:param name="single.year.ranges" select="0"/>
1549 <xsl:param name="firstyear" select="0"/>
1550 <xsl:param name="nextyear" select="0"/>
1553 <xsl:message terminate="no">
1554 <xsl:text>CY: </xsl:text>
1555 <xsl:value-of select="count($years)"/>
1556 <xsl:text>, </xsl:text>
1557 <xsl:value-of select="$firstyear"/>
1558 <xsl:text>, </xsl:text>
1559 <xsl:value-of select="$nextyear"/>
1560 <xsl:text>, </xsl:text>
1561 <xsl:value-of select="$print.ranges"/>
1562 <xsl:text>, </xsl:text>
1563 <xsl:value-of select="$single.year.ranges"/>
1564 <xsl:text> (</xsl:text>
1565 <xsl:value-of select="$years[1]"/>
1566 <xsl:text>)</xsl:text>
1571 <xsl:when test="$print.ranges = 0 and count($years) > 0">
1573 <xsl:when test="count($years) = 1">
1574 <xsl:apply-templates select="$years[1]" mode="titlepage.mode"/>
1577 <xsl:apply-templates select="$years[1]" mode="titlepage.mode"/>
1578 <xsl:text>, </xsl:text>
1579 <xsl:call-template name="copyright.years">
1580 <xsl:with-param name="years"
1581 select="$years[position() > 1]"/>
1582 <xsl:with-param name="print.ranges" select="$print.ranges"/>
1583 <xsl:with-param name="single.year.ranges"
1584 select="$single.year.ranges"/>
1585 </xsl:call-template>
1589 <xsl:when test="count($years) = 0">
1590 <xsl:variable name="lastyear" select="$nextyear - 1"/>
1592 <xsl:when test="$firstyear = 0">
1593 <!-- there weren't any years at all -->
1595 <!-- Just output a year with range in its text -->
1596 <xsl:when test="contains($firstyear, '-') or contains($firstyear, ',')">
1597 <xsl:value-of select="$firstyear"/>
1599 <xsl:when test="$firstyear = $lastyear">
1600 <xsl:value-of select="$firstyear"/>
1602 <xsl:when test="$single.year.ranges = 0
1603 and $lastyear = $firstyear + 1">
1604 <xsl:value-of select="$firstyear"/>
1605 <xsl:text>, </xsl:text>
1606 <xsl:value-of select="$lastyear"/>
1609 <xsl:value-of select="$firstyear"/>
1610 <xsl:text>-</xsl:text>
1611 <xsl:value-of select="$lastyear"/>
1615 <xsl:when test="contains($firstyear, '-') or contains($firstyear, ',')">
1616 <!-- Just output a year with range in its text -->
1617 <xsl:value-of select="$firstyear"/>
1618 <xsl:if test="count($years) != 0">
1619 <xsl:text>, </xsl:text>
1621 <xsl:call-template name="copyright.years">
1622 <xsl:with-param name="years"
1623 select="$years[position() > 1]"/>
1624 <xsl:with-param name="firstyear" select="$years[1]"/>
1625 <xsl:with-param name="nextyear" select="$years[1] + 1"/>
1626 <xsl:with-param name="print.ranges" select="$print.ranges"/>
1627 <xsl:with-param name="single.year.ranges"
1628 select="$single.year.ranges"/>
1629 </xsl:call-template>
1631 <xsl:when test="$firstyear = 0">
1632 <xsl:call-template name="copyright.years">
1633 <xsl:with-param name="years"
1634 select="$years[position() > 1]"/>
1635 <xsl:with-param name="firstyear" select="$years[1]"/>
1636 <xsl:with-param name="nextyear" select="$years[1] + 1"/>
1637 <xsl:with-param name="print.ranges" select="$print.ranges"/>
1638 <xsl:with-param name="single.year.ranges"
1639 select="$single.year.ranges"/>
1640 </xsl:call-template>
1642 <xsl:when test="$nextyear = $years[1]">
1643 <xsl:call-template name="copyright.years">
1644 <xsl:with-param name="years"
1645 select="$years[position() > 1]"/>
1646 <xsl:with-param name="firstyear" select="$firstyear"/>
1647 <xsl:with-param name="nextyear" select="$nextyear + 1"/>
1648 <xsl:with-param name="print.ranges" select="$print.ranges"/>
1649 <xsl:with-param name="single.year.ranges"
1650 select="$single.year.ranges"/>
1651 </xsl:call-template>
1654 <!-- we have years left, but they aren't in the current range -->
1656 <xsl:when test="$nextyear = $firstyear + 1">
1657 <xsl:value-of select="$firstyear"/>
1658 <xsl:text>, </xsl:text>
1660 <xsl:when test="$single.year.ranges = 0
1661 and $nextyear = $firstyear + 2">
1662 <xsl:value-of select="$firstyear"/>
1663 <xsl:text>, </xsl:text>
1664 <xsl:value-of select="$nextyear - 1"/>
1665 <xsl:text>, </xsl:text>
1668 <xsl:value-of select="$firstyear"/>
1669 <xsl:text>-</xsl:text>
1670 <xsl:value-of select="$nextyear - 1"/>
1671 <xsl:text>, </xsl:text>
1674 <xsl:call-template name="copyright.years">
1675 <xsl:with-param name="years"
1676 select="$years[position() > 1]"/>
1677 <xsl:with-param name="firstyear" select="$years[1]"/>
1678 <xsl:with-param name="nextyear" select="$years[1] + 1"/>
1679 <xsl:with-param name="print.ranges" select="$print.ranges"/>
1680 <xsl:with-param name="single.year.ranges"
1681 select="$single.year.ranges"/>
1682 </xsl:call-template>
1687 <!-- ====================================================================== -->
1689 <doc:template name="find.path.params" xmlns="">
1690 <refpurpose>Search in a table for the "best" match for the node</refpurpose>
1692 <refdescription id="find.path.params-desc">
1693 <para>This template searches in a table for the value that most-closely
1694 (in the typical best-match sense of XSLT) matches the current (element)
1695 node location.</para>
1699 <xsl:template name="find.path.params">
1700 <xsl:param name="node" select="."/>
1701 <xsl:param name="table" select="''"/>
1702 <xsl:param name="location">
1703 <xsl:call-template name="xpath.location">
1704 <xsl:with-param name="node" select="$node"/>
1705 </xsl:call-template>
1708 <xsl:variable name="value">
1709 <xsl:call-template name="lookup.key">
1710 <xsl:with-param name="key" select="$location"/>
1711 <xsl:with-param name="table" select="$table"/>
1712 </xsl:call-template>
1716 <xsl:when test="$value != ''">
1717 <xsl:value-of select="$value"/>
1719 <xsl:when test="contains($location, '/')">
1720 <xsl:call-template name="find.path.params">
1721 <xsl:with-param name="node" select="$node"/>
1722 <xsl:with-param name="table" select="$table"/>
1723 <xsl:with-param name="location" select="substring-after($location, '/')"/>
1724 </xsl:call-template>
1729 <xsl:template name="relative-uri">
1730 <xsl:param name="filename" select="."/>
1731 <xsl:param name="destdir" select="''"/>
1733 <xsl:variable name="srcurl">
1734 <xsl:call-template name="strippath">
1735 <xsl:with-param name="filename">
1736 <xsl:call-template name="xml.base.dirs">
1737 <xsl:with-param name="base.elem"
1738 select="$filename/ancestor-or-self::*
1739 [@xml:base != ''][1]"/>
1740 </xsl:call-template>
1741 <xsl:value-of select="$filename"/>
1743 </xsl:call-template>
1746 <xsl:variable name="srcurl.trimmed">
1747 <xsl:call-template name="trim.common.uri.paths">
1748 <xsl:with-param name="uriA" select="$srcurl"/>
1749 <xsl:with-param name="uriB" select="$destdir"/>
1750 <xsl:with-param name="return" select="'A'"/>
1751 </xsl:call-template>
1754 <xsl:variable name="destdir.trimmed">
1755 <xsl:call-template name="trim.common.uri.paths">
1756 <xsl:with-param name="uriA" select="$srcurl"/>
1757 <xsl:with-param name="uriB" select="$destdir"/>
1758 <xsl:with-param name="return" select="'B'"/>
1759 </xsl:call-template>
1762 <xsl:variable name="depth">
1763 <xsl:call-template name="count.uri.path.depth">
1764 <xsl:with-param name="filename" select="$destdir.trimmed"/>
1765 </xsl:call-template>
1768 <xsl:call-template name="copy-string">
1769 <xsl:with-param name="string" select="'../'"/>
1770 <xsl:with-param name="count" select="$depth"/>
1771 </xsl:call-template>
1772 <xsl:value-of select="$srcurl.trimmed"/>
1776 <!-- ===================================== -->
1778 <xsl:template name="xml.base.dirs">
1779 <xsl:param name="base.elem" select="NONODE"/>
1781 <!-- Recursively resolve xml:base attributes, up to a
1782 full path with : in uri -->
1783 <xsl:if test="$base.elem/ancestor::*[@xml:base != ''] and
1784 not(contains($base.elem/@xml:base, ':'))">
1785 <xsl:call-template name="xml.base.dirs">
1786 <xsl:with-param name="base.elem"
1787 select="$base.elem/ancestor::*[@xml:base != ''][1]"/>
1788 </xsl:call-template>
1790 <xsl:call-template name="getdir">
1791 <xsl:with-param name="filename" select="$base.elem/@xml:base"/>
1792 </xsl:call-template>
1796 <!-- ===================================== -->
1798 <xsl:template name="strippath">
1799 <xsl:param name="filename" select="''"/>
1801 <!-- Leading .. are not eliminated -->
1802 <xsl:when test="starts-with($filename, '../')">
1803 <xsl:value-of select="'../'"/>
1804 <xsl:call-template name="strippath">
1805 <xsl:with-param name="filename" select="substring-after($filename, '../')"/>
1806 </xsl:call-template>
1808 <xsl:when test="contains($filename, '/../')">
1809 <xsl:call-template name="strippath">
1810 <xsl:with-param name="filename">
1811 <xsl:call-template name="getdir">
1812 <xsl:with-param name="filename" select="substring-before($filename, '/../')"/>
1813 </xsl:call-template>
1814 <xsl:value-of select="substring-after($filename, '/../')"/>
1816 </xsl:call-template>
1819 <xsl:value-of select="$filename"/>
1824 <!-- ===================================== -->
1826 <xsl:template name="getdir">
1827 <xsl:param name="filename" select="''"/>
1828 <xsl:if test="contains($filename, '/')">
1829 <xsl:value-of select="substring-before($filename, '/')"/>
1830 <xsl:text>/</xsl:text>
1831 <xsl:call-template name="getdir">
1832 <xsl:with-param name="filename" select="substring-after($filename, '/')"/>
1833 </xsl:call-template>
1837 <!-- ===================================== -->
1839 <doc:template name="string.upper" xmlns="">
1840 <refpurpose>Converts a string to all uppercase letters</refpurpose>
1842 <refdescription id="string.upper-desc">
1843 <para>Given a string, this template does a language-aware conversion
1844 of that string to all uppercase letters, based on the values of the
1845 <literal>lowercase.alpha</literal> and
1846 <literal>uppercase.alpha</literal> gentext keys for the current
1847 locale. It affects only those characters found in the values of
1848 <literal>lowercase.alpha</literal> and
1849 <literal>uppercase.alpha</literal>. All other characters are left
1853 <refparameter id="string.upper-params">
1855 <varlistentry><term>string</term>
1857 <para>The string to convert to uppercase.</para>
1863 <xsl:template name="string.upper">
1864 <xsl:param name="string" select="''"/>
1865 <xsl:variable name="lowercase.alpha">
1866 <xsl:call-template name="gentext">
1867 <xsl:with-param name="key" select="'lowercase.alpha'"/>
1868 </xsl:call-template>
1870 <xsl:variable name="uppercase.alpha">
1871 <xsl:call-template name="gentext">
1872 <xsl:with-param name="key" select="'uppercase.alpha'"/>
1873 </xsl:call-template>
1875 <xsl:value-of select="translate($string,$lowercase.alpha,$uppercase.alpha)"/>
1878 <!-- ===================================== -->
1880 <doc:template name="string.lower" xmlns="">
1881 <refpurpose>Converts a string to all lowercase letters</refpurpose>
1883 <refdescription id="string.lower-desc">
1884 <para>Given a string, this template does a language-aware conversion
1885 of that string to all lowercase letters, based on the values of the
1886 <literal>uppercase.alpha</literal> and
1887 <literal>lowercase.alpha</literal> gentext keys for the current
1888 locale. It affects only those characters found in the values of
1889 <literal>uppercase.alpha</literal> and
1890 <literal>lowercase.alpha</literal>. All other characters are left
1894 <refparameter id="string.lower-params">
1896 <varlistentry><term>string</term>
1898 <para>The string to convert to lowercase.</para>
1904 <xsl:template name="string.lower">
1905 <xsl:param name="string" select="''"/>
1906 <xsl:variable name="uppercase.alpha">
1907 <xsl:call-template name="gentext">
1908 <xsl:with-param name="key" select="'uppercase.alpha'"/>
1909 </xsl:call-template>
1911 <xsl:variable name="lowercase.alpha">
1912 <xsl:call-template name="gentext">
1913 <xsl:with-param name="key" select="'lowercase.alpha'"/>
1914 </xsl:call-template>
1916 <xsl:value-of select="translate($string,$uppercase.alpha,$lowercase.alpha)"/>
1919 <!-- ===================================== -->
1921 <doc:template name="select.choice.separator" xmlns="">
1922 <refpurpose>Returns localized choice separator</refpurpose>
1923 <refdescription id="select.choice.separator-desc">
1924 <para>This template enables auto-generation of an appropriate
1925 localized "choice" separator (for example, "and" or "or") before
1926 the final item in an inline list (though it could also be useful
1927 for generating choice separators for non-inline lists).</para>
1928 <para>It currently works by evaluating a processing instruction
1929 (PI) of the form <?dbchoice choice="foo"?> :
1932 <simpara>if the value of the <tag>choice</tag>
1933 pseudo-attribute is "and" or "or", returns a localized "and"
1937 <simpara>otherwise returns the literal value of the
1938 <tag>choice</tag> pseudo-attribute</simpara>
1941 The latter is provided only as a temporary workaround because the
1942 locale files do not currently have translations for the word
1943 <wordasword>or</wordasword>. So if you want to generate a a
1944 logical "or" separator in French (for example), you currently need
1946 <literallayout><?dbchoice choice="ou"?></literallayout>
1949 <para>The <tag>dbchoice</tag> processing instruction is
1950 an unfortunate hack; support for it may disappear in the future
1951 (particularly if and when a more appropriate means for marking
1952 up "choice" lists becomes available in DocBook).</para>
1956 <xsl:template name="select.choice.separator">
1957 <xsl:variable name="choice">
1958 <xsl:call-template name="pi.dbchoice_choice"/>
1961 <!-- if value of $choice is "and" or "or", translate to equivalent in -->
1962 <!-- current locale -->
1963 <xsl:when test="$choice = 'and' or $choice = 'or'">
1964 <xsl:call-template name="gentext">
1965 <xsl:with-param name="key" select="$choice"/>
1966 </xsl:call-template>
1968 <!-- otherwise, just output value of $choice, whatever it is -->
1970 <xsl:value-of select="$choice"/>
1975 <!-- ===================================== -->
1977 <doc:template name="evaluate.info.profile" xmlns="">
1978 <refpurpose>Evaluates an info profile</refpurpose>
1979 <refdescription id="evaluate.info.profile-desc">
1980 <para>This template evaluates an "info profile" matching the XPath
1981 expression given by the <parameter>profile</parameter>
1982 parameter. It relies on the XSLT <function>evaluate()</function>
1983 extension function.</para>
1985 <para>The value of the <parameter>profile</parameter> parameter
1986 can include the literal string <literal>$info</literal>. If found
1987 in the value of the <parameter>profile</parameter> parameter, the
1988 literal string <literal>$info</literal> string is replaced with
1989 the value of the <parameter>info</parameter> parameter, which
1990 should be a set of <replaceable>*info</replaceable> nodes; the
1991 expression is then evaluated using the XSLT
1992 <function>evaluate()</function> extension function.</para>
1994 <refparameter id="evaluate.info.profile-params">
1997 <term>profile</term>
1999 <para>A string representing an XPath expression </para>
2005 <para>A set of *info nodes</para>
2011 <refreturn id="evaluate.info.profile-returns">
2012 <para>Returns a node (the result of evaluating the
2013 <parameter>profile</parameter> parameter)</para>
2016 <xsl:template name="evaluate.info.profile">
2017 <xsl:param name="profile"/>
2018 <xsl:param name="info"/>
2020 <!-- * xsltproc and Xalan both support dyn:evaluate() -->
2021 <xsl:when test="function-available('dyn:evaluate')">
2022 <xsl:apply-templates
2023 select="dyn:evaluate($profile)" mode="get.refentry.metadata"/>
2025 <!-- * Saxon has its own evaluate() & doesn't support dyn:evaluate() -->
2026 <xsl:when test="function-available('saxon:evaluate')">
2027 <xsl:apply-templates
2028 select="saxon:evaluate($profile)" mode="get.refentry.metadata"/>
2031 <xsl:message terminate="yes">
2032 Error: The "info profiling" mechanism currently requires an XSLT
2033 engine that supports the evaluate() XSLT extension function. Your XSLT
2034 engine does not support it.