7da64de2385318a29d1c0d1769b7efe300860a3f
[samba.git] / docs / docbook / xslt / db2latex / common / common.xsl
1 <?xml version='1.0'?>
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"
5                 version='1.0'>
6
7 <!-- ********************************************************************
8      $Id: common.xsl,v 1.1.2.1 2003/05/01 14:14:13 jelmer Exp $
9      ********************************************************************
10
11      Derived from the official DocBook XSL Stylesheets 
12      See http://nwalsh.com/docbook/xsl/ for copyright and other information.
13
14      This file contains general templates common to both the HTML and FO
15      versions of the DocBook stylesheets.
16      ******************************************************************** -->
17
18 <doc:reference xmlns="">
19 <referenceinfo>
20 <releaseinfo role="meta"> $Id: common.xsl,v 1.1.2.1 2003/05/01 14:14:13 jelmer Exp $ </releaseinfo>
21 <author>
22         <surname>Ramon</surname>
23         <firstname>Casellas</firstname>
24 </author>
25 <copyright>
26         <year>1999</year><year>2000</year>
27         <holder>Norman Walsh</holder>
28 </copyright>
29 </referenceinfo>
30 <title>Common Template Reference</title>
31
32 <partintro>
33 <section><title>Introduction</title>
34
35 <para>This is technical reference documentation for the DocBook XSL
36 Stylesheets; it documents (some of) the parameters, templates, and
37 other elements of the stylesheets.</para>
38
39 <para>This is not intended to be <quote>user</quote> documentation.
40 It is provided for developers writing customization layers for the
41 stylesheets, and for anyone who's interested in <quote>how it
42 works</quote>.</para>
43
44 <para>Although I am trying to be thorough, this documentation is known
45 to be incomplete. Don't forget to read the source, too :-)</para>
46 </section>
47 </partintro>
48
49 </doc:reference>
50
51 <!-- ==================================================================== -->
52 <!-- Establish strip/preserve whitespace rules -->
53
54 <xsl:preserve-space elements="*"/>
55
56 <xsl:strip-space elements="
57 abstract affiliation anchor answer appendix area areaset areaspec
58 artheader article audiodata audioobject author authorblurb authorgroup
59 beginpage bibliodiv biblioentry bibliography biblioset blockquote book
60 bookbiblio bookinfo callout calloutlist caption caution chapter
61 citerefentry cmdsynopsis co collab colophon colspec confgroup
62 copyright dedication docinfo editor entry entrytbl epigraph equation
63 example figure footnote footnoteref formalpara funcprototype
64 funcsynopsis glossary glossdef glossdiv glossentry glosslist graphicco
65 group highlights imagedata imageobject imageobjectco important index
66 indexdiv indexentry indexterm informalequation informalexample
67 informalfigure informaltable inlineequation inlinemediaobject
68 itemizedlist itermset keycombo keywordset legalnotice listitem lot
69 mediaobject mediaobjectco menuchoice msg msgentry msgexplan msginfo
70 msgmain msgrel msgset msgsub msgtext note objectinfo
71 orderedlist othercredit part partintro preface printhistory procedure
72 programlistingco publisher qandadiv qandaentry qandaset question
73 refentry reference refmeta refnamediv refsect1 refsect1info refsect2
74 refsect2info refsect3 refsect3info refsynopsisdiv refsynopsisdivinfo
75 revhistory revision row sbr screenco screenshot sect1 sect1info sect2
76 sect2info sect3 sect3info sect4 sect4info sect5 sect5info section
77 sectioninfo seglistitem segmentedlist seriesinfo set setindex setinfo
78 shortcut sidebar simplelist simplesect spanspec step subject
79 subjectset substeps synopfragment table tbody textobject tfoot tgroup
80 thead tip toc tocchap toclevel1 toclevel2 toclevel3 toclevel4
81 toclevel5 tocpart varargs variablelist varlistentry videodata
82 videoobject void warning subjectset
83
84 classsynopsis
85 constructorsynopsis
86 destructorsynopsis
87 fieldsynopsis
88 methodparam
89 methodsynopsis
90 ooclass
91 ooexception
92 oointerface
93 simplemsgentry
94 "/>
95
96 <!-- ====================================================================== -->
97
98 <doc:template name="is.component" xmlns="">
99 <refpurpose>Tests if a given node is a component-level element</refpurpose>
100
101 <refdescription>
102 <para>This template returns '1' if the specified node is a component
103 (Chapter, Appendix, etc.), and '0' otherwise.</para>
104 </refdescription>
105
106 <refparameter>
107 <variablelist>
108 <varlistentry><term>node</term>
109 <listitem>
110 <para>The node which is to be tested.</para>
111 </listitem>
112 </varlistentry>
113 </variablelist>
114 </refparameter>
115
116 <refreturn>
117 <para>This template returns '1' if the specified node is a component
118 (Chapter, Appendix, etc.), and '0' otherwise.</para>
119 </refreturn>
120 </doc:template>
121
122 <xsl:template name="is.component">
123   <xsl:param name="node" select="."/>
124   <xsl:choose>
125     <xsl:when test="local-name($node) = 'appendix'
126                     or local-name($node) = 'article'
127                     or local-name($node) = 'chapter'
128                     or local-name($node) = 'preface'
129                     or local-name($node) = 'bibliography'
130                     or local-name($node) = 'glossary'
131                     or local-name($node) = 'index'">1</xsl:when>
132     <xsl:otherwise>0</xsl:otherwise>
133   </xsl:choose>
134 </xsl:template>
135
136 <!-- ====================================================================== -->
137
138 <doc:template name="is.section" xmlns="">
139 <refpurpose>Tests if a given node is a section-level element</refpurpose>
140
141 <refdescription>
142 <para>This template returns '1' if the specified node is a section
143 (Section, Sect1, Sect2, etc.), and '0' otherwise.</para>
144 </refdescription>
145
146 <refparameter>
147 <variablelist>
148 <varlistentry><term>node</term>
149 <listitem>
150 <para>The node which is to be tested.</para>
151 </listitem>
152 </varlistentry>
153 </variablelist>
154 </refparameter>
155
156 <refreturn>
157 <para>This template returns '1' if the specified node is a section
158 (Section, Sect1, Sect2, etc.), and '0' otherwise.</para>
159 </refreturn>
160 </doc:template>
161
162 <xsl:template name="is.section">
163   <xsl:param name="node" select="."/>
164   <xsl:choose>
165     <xsl:when test="local-name($node) = 'section'
166                     or local-name($node) = 'sect1'
167                     or local-name($node) = 'sect2'
168                     or local-name($node) = 'sect3'
169                     or local-name($node) = 'sect4'
170                     or local-name($node) = 'sect5'
171                     or local-name($node) = 'refsect1'
172                     or local-name($node) = 'refsect2'
173                     or local-name($node) = 'refsect3'
174                     or local-name($node) = 'simplesect'">1</xsl:when>
175     <xsl:otherwise>0</xsl:otherwise>
176   </xsl:choose>
177 </xsl:template>
178
179 <!-- ====================================================================== -->
180
181 <doc:template name="section.level" xmlns="">
182 <refpurpose>Returns the hierarchical level of a section.</refpurpose>
183
184 <refdescription>
185 <para>This template calculates the hierarchical level of a section.
186 Hierarchically, components are <quote>top level</quote>, so a
187 <sgmltag>sect1</sgmltag> is at level 2, <sgmltag>sect3</sgmltag> is
188 at level 3, etc.</para>
189
190 <para>Recursive sections are calculated down to the sixth level.</para>
191 </refdescription>
192
193 <refparameter>
194 <variablelist>
195 <varlistentry><term>node</term>
196 <listitem>
197 <para>The section node for which the level should be calculated.
198 Defaults to the context node.</para>
199 </listitem>
200 </varlistentry>
201 </variablelist>
202 </refparameter>
203
204 <refreturn>
205 <para>The section level, <quote>2</quote>, <quote>3</quote>, etc.
206 </para>
207 </refreturn>
208 </doc:template>
209
210 <xsl:template name="section.level">
211   <xsl:param name="node" select="."/>
212   <xsl:choose>
213     <xsl:when test="name($node)='sect1'">2</xsl:when>
214     <xsl:when test="name($node)='sect2'">3</xsl:when>
215     <xsl:when test="name($node)='sect3'">4</xsl:when>
216     <xsl:when test="name($node)='sect4'">5</xsl:when>
217     <xsl:when test="name($node)='sect5'">6</xsl:when>
218     <xsl:when test="name($node)='section'">
219       <xsl:choose>
220         <xsl:when test="$node/../../../../../section">6</xsl:when>
221         <xsl:when test="$node/../../../../section">5</xsl:when>
222         <xsl:when test="$node/../../../section">4</xsl:when>
223         <xsl:when test="$node/../../section">3</xsl:when>
224         <xsl:otherwise>2</xsl:otherwise>
225       </xsl:choose>
226     </xsl:when>
227     <xsl:when test="name($node)='simplesect'">
228       <xsl:choose>
229         <xsl:when test="$node/../../sect1">3</xsl:when>
230         <xsl:when test="$node/../../sect2">4</xsl:when>
231         <xsl:when test="$node/../../sect3">5</xsl:when>
232         <xsl:when test="$node/../../sect4">6</xsl:when>
233         <xsl:when test="$node/../../sect5">6</xsl:when>
234         <xsl:when test="$node/../../section">
235           <xsl:choose>
236             <xsl:when test="$node/../../../../../section">6</xsl:when>
237             <xsl:when test="$node/../../../../section">5</xsl:when>
238             <xsl:when test="$node/../../../section">4</xsl:when>
239             <xsl:otherwise>3</xsl:otherwise>
240           </xsl:choose>
241         </xsl:when>
242         <xsl:otherwise>2</xsl:otherwise>
243       </xsl:choose>
244     </xsl:when>
245     <xsl:otherwise>2</xsl:otherwise>
246   </xsl:choose>
247 </xsl:template><!-- section.level -->
248
249 <doc:template name="qanda.section.level" xmlns="">
250 <refpurpose>Returns the hierarchical level of a QandASet.</refpurpose>
251
252 <refdescription>
253 <para>This template calculates the hierarchical level of a QandASet.
254 </para>
255 </refdescription>
256
257 <refreturn>
258 <para>The level, <quote>1</quote>, <quote>2</quote>, etc.
259 </para>
260 </refreturn>
261 </doc:template>
262
263 <xsl:template name="qanda.section.level">
264   <xsl:variable name="section"
265                 select="(ancestor::section
266                          |ancestor::simplesect
267                          |ancestor::sect5
268                          |ancestor::sect4
269                          |ancestor::sect3
270                          |ancestor::sect2
271                          |ancestor::sect1
272                          |ancestor::refsect3
273                          |ancestor::refsect2
274                          |ancestor::refsect1)[last()]"/>
275   <xsl:choose>
276     <xsl:when test="count($section) = '0'">1</xsl:when>
277     <xsl:otherwise>
278       <xsl:call-template name="section.level">
279         <xsl:with-param name="node" select="$section"/>
280       </xsl:call-template>
281     </xsl:otherwise>
282   </xsl:choose>
283 </xsl:template>
284
285 <xsl:template name="qandadiv.section.level">
286   <xsl:variable name="section.level">
287     <xsl:call-template name="qanda.section.level"/>
288   </xsl:variable>
289   <xsl:variable name="anc.divs" select="ancestor::qandadiv"/>
290
291   <xsl:value-of select="count($anc.divs) + number($section.level)"/>
292 </xsl:template>
293
294 <!-- ====================================================================== -->
295
296 <xsl:template name="object.id">
297   <xsl:param name="object" select="."/>
298   <xsl:choose>
299     <xsl:when test="$object/@id">
300       <xsl:value-of select="$object/@id"/>
301     </xsl:when>
302     <xsl:otherwise>
303       <xsl:value-of select="generate-id($object)"/>
304     </xsl:otherwise>
305   </xsl:choose>
306 </xsl:template>
307
308 <xsl:template name="person.name">
309   <!-- Return a formatted string representation of the contents of
310        the specified node (by default, the current element).
311        Handles Honorific, FirstName, SurName, and Lineage.
312        If %author-othername-in-middle% is #t, also OtherName
313        Handles *only* the first of each.
314        Format is "Honorific. FirstName [OtherName] SurName, Lineage"
315   -->
316   <xsl:param name="node" select="."/>
317
318   <xsl:choose>
319     <!-- handle corpauthor as a special case...-->
320     <xsl:when test="name($node)='corpauthor'">
321       <xsl:apply-templates select="$node"/>
322     </xsl:when>
323     <xsl:otherwise>
324       <xsl:variable name="h_nl" select="$node//honorific[1]"/>
325       <xsl:variable name="f_nl" select="$node//firstname[1]"/>
326       <xsl:variable name="o_nl" select="$node//othername[1]"/>
327       <xsl:variable name="s_nl" select="$node//surname[1]"/>
328       <xsl:variable name="l_nl" select="$node//lineage[1]"/>
329
330       <xsl:variable name="has_h" select="$h_nl"/>
331       <xsl:variable name="has_f" select="$f_nl"/>
332       <xsl:variable name="has_o"
333                     select="$o_nl and ($author.othername.in.middle != 0)"/>
334       <xsl:variable name="has_s" select="$s_nl"/>
335       <xsl:variable name="has_l" select="$l_nl"/>
336
337       <xsl:if test="$has_h">
338         <xsl:value-of select="$h_nl"/>.
339       </xsl:if>
340
341       <xsl:if test="$has_f">
342         <xsl:if test="$has_h"><xsl:text> </xsl:text></xsl:if>
343         <xsl:value-of select="$f_nl"/>
344       </xsl:if>
345
346       <xsl:if test="$has_o">
347         <xsl:if test="$has_h or $has_f"><xsl:text> </xsl:text></xsl:if>
348         <xsl:value-of select="$o_nl"/>
349       </xsl:if>
350
351       <xsl:if test="$has_s">
352         <xsl:if test="$has_h or $has_f or $has_o">
353           <xsl:text> </xsl:text>
354         </xsl:if>
355         <xsl:value-of select="$s_nl"/>
356       </xsl:if>
357
358       <xsl:if test="$has_l">
359         <xsl:text>, </xsl:text>
360         <xsl:value-of select="$l_nl"/>
361       </xsl:if>
362     </xsl:otherwise>
363   </xsl:choose>
364 </xsl:template> <!-- person.name -->
365
366 <xsl:template name="person.name.list">
367   <!-- Return a formatted string representation of the contents of
368        the current element. The current element must contain one or
369        more AUTHORs, CORPAUTHORs, OTHERCREDITs, and/or EDITORs.
370
371        John Doe
372      or
373        John Doe and Jane Doe
374      or
375        John Doe, Jane Doe, and A. Nonymous
376   -->
377   <xsl:param name="person.list" select="./author|./corpauthor|./othercredit|./editor"/>
378   <xsl:param name="person.count" select="count($person.list)"/>
379   <xsl:param name="count" select="1"/>
380
381   <xsl:choose>
382     <xsl:when test="$count>$person.count"></xsl:when>
383     <xsl:otherwise>
384       <xsl:call-template name="person.name">
385         <xsl:with-param name="node" select="$person.list[position()=$count]"/>
386       </xsl:call-template>
387       <xsl:if test="$count&lt;$person.count">
388         <xsl:if test="$person.count>2">,</xsl:if>
389         <xsl:text> </xsl:text>
390       </xsl:if>
391       <xsl:if test="$count+1=$person.count">and </xsl:if>
392       <xsl:call-template name="person.name.list">
393         <xsl:with-param name="person.list" select="$person.list"/>
394         <xsl:with-param name="person.count" select="$person.count"/>
395         <xsl:with-param name="count" select="$count+1"/>
396       </xsl:call-template>
397     </xsl:otherwise>
398   </xsl:choose>
399 </xsl:template><!-- person.name.list -->
400
401 <!-- === synopsis ======================================================= -->
402 <!-- The following definitions match those given in the reference
403      documentation for DocBook V3.0
404 -->
405
406 <xsl:variable name="arg.choice.opt.open.str">[</xsl:variable>
407 <xsl:variable name="arg.choice.opt.close.str">]</xsl:variable>
408 <xsl:variable name="arg.choice.req.open.str">{</xsl:variable>
409 <xsl:variable name="arg.choice.req.close.str">}</xsl:variable>
410 <xsl:variable name="arg.choice.plain.open.str"><xsl:text> </xsl:text></xsl:variable>
411 <xsl:variable name="arg.choice.plain.close.str"><xsl:text> </xsl:text></xsl:variable>
412 <xsl:variable name="arg.choice.def.open.str">[</xsl:variable>
413 <xsl:variable name="arg.choice.def.close.str">]</xsl:variable>
414 <xsl:variable name="arg.rep.repeat.str">...</xsl:variable>
415 <xsl:variable name="arg.rep.norepeat.str"></xsl:variable>
416 <xsl:variable name="arg.rep.def.str"></xsl:variable>
417 <xsl:variable name="arg.or.sep"> | </xsl:variable>
418 <xsl:variable name="cmdsynopsis.hanging.indent">4pi</xsl:variable>
419
420 <!-- ====================================================================== -->
421 <!-- label content -->
422
423 <doc:mode mode="label.content" xmlns="">
424 <refpurpose>Provides access to element labels</refpurpose>
425 <refdescription>
426 <para>Processing an element in the
427 <literal role="mode">label.content</literal> mode produces the
428 element label.</para>
429 <para>If the label is non-null, either because the
430 <sgmltag class="attribute">label</sgmltag> attribute was present on the
431 element or the stylesheet automatically generated a label, trailing
432 punctuation is automatically added.</para>
433 </refdescription>
434 </doc:mode>
435
436 <xsl:template match="*" mode="label.content">
437   <xsl:message>
438     <xsl:text>Request for label of unexpected element: </xsl:text>
439     <xsl:value-of select="name(.)"/>
440   </xsl:message>
441 </xsl:template>
442
443 <xsl:template match="set|book" mode="label.content">
444   <xsl:param name="punct">.</xsl:param>
445   <xsl:if test="@label">
446     <xsl:value-of select="@label"/>
447     <xsl:value-of select="$punct"/>
448   </xsl:if>
449 </xsl:template>
450
451 <xsl:template match="part" mode="label.content">
452   <xsl:param name="punct">.</xsl:param>
453   <xsl:choose>
454     <xsl:when test="@label">
455       <xsl:value-of select="@label"/>
456       <xsl:value-of select="$punct"/>
457     </xsl:when>
458     <xsl:when test="$part.autolabel != 0">
459       <xsl:number from="book" count="part" format="I"/>
460       <xsl:value-of select="$punct"/>
461     </xsl:when>
462   </xsl:choose>
463 </xsl:template>
464
465 <xsl:template match="preface" mode="label.content">
466   <xsl:param name="punct">.</xsl:param>
467   <xsl:choose>
468     <xsl:when test="@label">
469       <xsl:value-of select="@label"/>
470       <xsl:value-of select="$punct"/>
471     </xsl:when>
472     <xsl:when test="$preface.autolabel != 0">
473       <xsl:number from="book" count="preface" format="1" level="any"/>
474       <xsl:value-of select="$punct"/>
475     </xsl:when>
476   </xsl:choose>
477 </xsl:template>
478
479 <xsl:template match="chapter" mode="label.content">
480   <xsl:param name="punct">.</xsl:param>
481   <xsl:choose>
482     <xsl:when test="@label">
483       <xsl:value-of select="@label"/>
484       <xsl:value-of select="$punct"/>
485     </xsl:when>
486     <xsl:when test="$chapter.autolabel != 0">
487       <xsl:number from="book" count="chapter" format="1" level="any"/>
488       <xsl:value-of select="$punct"/>
489     </xsl:when>
490   </xsl:choose>
491 </xsl:template>
492
493 <xsl:template match="appendix" mode="label.content">
494   <xsl:param name="punct">.</xsl:param>
495   <xsl:choose>
496     <xsl:when test="@label">
497       <xsl:value-of select="@label"/>
498       <xsl:value-of select="$punct"/>
499     </xsl:when>
500     <xsl:when test="$chapter.autolabel != 0">
501       <xsl:number from="book" count="appendix" format="A" level="any"/>
502       <xsl:value-of select="$punct"/>
503     </xsl:when>
504   </xsl:choose>
505 </xsl:template>
506
507 <xsl:template match="article" mode="label.content">
508   <xsl:param name="punct">.</xsl:param>
509   <xsl:if test="@label">
510     <xsl:value-of select="@label"/>
511     <xsl:value-of select="$punct"/>
512   </xsl:if>
513 </xsl:template>
514
515 <xsl:template match="dedication|colophon" mode="label.content">
516   <xsl:param name="punct">.</xsl:param>
517   <xsl:if test="@label">
518     <xsl:value-of select="@label"/>
519     <xsl:value-of select="$punct"/>
520   </xsl:if>
521 </xsl:template>
522
523 <xsl:template match="reference" mode="label.content">
524   <xsl:param name="punct">.</xsl:param>
525   <xsl:choose>
526     <xsl:when test="@label">
527       <xsl:value-of select="@label"/>
528       <xsl:value-of select="$punct"/>
529     </xsl:when>
530     <xsl:when test="$part.autolabel != 0">
531       <xsl:number from="book" count="reference" format="I" level="any"/>
532       <xsl:value-of select="$punct"/>
533     </xsl:when>
534   </xsl:choose>
535 </xsl:template>
536
537 <xsl:template match="refentry" mode="label.content">
538   <xsl:param name="punct">.</xsl:param>
539   <xsl:if test="@label">
540     <xsl:value-of select="@label"/>
541     <xsl:value-of select="$punct"/>
542   </xsl:if>
543 </xsl:template>
544
545 <xsl:template match="section" mode="label.content">
546   <xsl:param name="punct">.</xsl:param>
547
548   <!-- if this is a nested section, label the parent -->
549   <xsl:if test="local-name(..) = 'section'">
550     <xsl:apply-templates select=".." mode="label.content">
551       <xsl:with-param name="punct">.</xsl:with-param>
552     </xsl:apply-templates>
553   </xsl:if>
554
555   <!-- if the parent is a component, maybe label that too -->
556   <xsl:variable name="parent.is.component">
557     <xsl:call-template name="is.component">
558       <xsl:with-param name="node" select=".."/>
559     </xsl:call-template>
560   </xsl:variable>
561
562   <!-- does this section get labelled? -->
563   <xsl:variable name="label">
564     <xsl:call-template name="label.this.section">
565       <xsl:with-param name="section" select="."/>
566     </xsl:call-template>
567   </xsl:variable>
568
569   <xsl:if test="$section.label.includes.component.label != 0
570                 and $parent.is.component != 0">
571     <xsl:apply-templates select=".." mode="label.content">
572       <xsl:with-param name="punct">.</xsl:with-param>
573     </xsl:apply-templates>
574   </xsl:if>
575
576   <xsl:choose>
577     <xsl:when test="@label">
578       <xsl:value-of select="@label"/>
579       <xsl:value-of select="$punct"/>
580     </xsl:when>
581     <xsl:when test="$label != 0">
582       <xsl:number count="section"/>
583       <xsl:value-of select="$punct"/>
584     </xsl:when>
585   </xsl:choose>
586 </xsl:template>
587
588 <xsl:template match="sect1" mode="label.content">
589   <xsl:param name="punct">.</xsl:param>
590
591   <!-- if the parent is a component, maybe label that too -->
592   <xsl:variable name="parent.is.component">
593     <xsl:call-template name="is.component">
594       <xsl:with-param name="node" select=".."/>
595     </xsl:call-template>
596   </xsl:variable>
597   <xsl:if test="$section.label.includes.component.label != 0
598                 and $parent.is.component">
599     <xsl:apply-templates select=".." mode="label.content">
600       <xsl:with-param name="punct">.</xsl:with-param>
601     </xsl:apply-templates>
602   </xsl:if>
603
604   <xsl:choose>
605     <xsl:when test="@label">
606       <xsl:value-of select="@label"/>
607       <xsl:value-of select="$punct"/>
608     </xsl:when>
609     <xsl:when test="$section.autolabel != 0">
610       <xsl:number count="sect1"/>
611       <xsl:value-of select="$punct"/>
612     </xsl:when>
613   </xsl:choose>
614 </xsl:template>
615
616 <xsl:template match="sect2|sect3|sect4|sect5" mode="label.content">
617   <xsl:param name="punct">.</xsl:param>
618
619   <!-- label the parent -->
620   <xsl:apply-templates select=".." mode="label.content">
621     <xsl:with-param name="punct">.</xsl:with-param>
622   </xsl:apply-templates>
623
624   <xsl:choose>
625     <xsl:when test="@label">
626       <xsl:value-of select="@label"/>
627       <xsl:value-of select="$punct"/>
628     </xsl:when>
629     <xsl:when test="$section.autolabel != 0">
630       <xsl:choose>
631         <xsl:when test="local-name(.) = 'sect2'">
632           <xsl:number count="sect2"/>
633         </xsl:when>
634         <xsl:when test="local-name(.) = 'sect3'">
635           <xsl:number count="sect3"/>
636         </xsl:when>
637         <xsl:when test="local-name(.) = 'sect4'">
638           <xsl:number count="sect4"/>
639         </xsl:when>
640         <xsl:when test="local-name(.) = 'sect5'">
641           <xsl:number count="sect5"/>
642         </xsl:when>
643         <xsl:otherwise>
644           <xsl:message>label.content: this can't happen!</xsl:message>
645         </xsl:otherwise>
646       </xsl:choose>
647       <xsl:value-of select="$punct"/>
648     </xsl:when>
649   </xsl:choose>
650 </xsl:template>
651
652 <xsl:template match="refsect1|refsect2|refsect3" mode="label.content">
653   <xsl:param name="punct">.</xsl:param>
654   <xsl:choose>
655     <xsl:when test="@label">
656       <xsl:value-of select="@label"/>
657       <xsl:value-of select="$punct"/>
658     </xsl:when>
659     <xsl:when test="$section.autolabel != 0">
660       <xsl:number level="multiple" count="refsect1|refsect2|refsect3"/>
661       <xsl:value-of select="$punct"/>
662     </xsl:when>
663   </xsl:choose>
664 </xsl:template>
665
666 <xsl:template match="simplesect" mode="label.content">
667   <xsl:param name="punct">.</xsl:param>
668   <xsl:choose>
669     <xsl:when test="@label">
670       <xsl:value-of select="@label"/>
671       <xsl:value-of select="$punct"/>
672     </xsl:when>
673     <xsl:when test="$section.autolabel != 0">
674       <xsl:number level="multiple" count="section
675                                           |sect1|sect2|sect3|sect4|sect5
676                                           |refsect1|refsect2|refsect3
677                                           |simplesect"/>
678       <xsl:value-of select="$punct"/>
679     </xsl:when>
680   </xsl:choose>
681 </xsl:template>
682
683 <xsl:template match="qandadiv" mode="label.content">
684   <xsl:param name="punct">.</xsl:param>
685   <xsl:variable name="prefix">
686     <xsl:if test="$qanda.inherit.numeration != 0">
687       <xsl:variable name="lparent" select="(ancestor::set
688                                             |ancestor::book
689                                             |ancestor::chapter
690                                             |ancestor::appendix
691                                             |ancestor::preface
692                                             |ancestor::section
693                                             |ancestor::simplesect
694                                             |ancestor::sect1
695                                             |ancestor::sect2
696                                             |ancestor::sect3
697                                             |ancestor::sect4
698                                             |ancestor::sect5
699                                             |ancestor::refsect1
700                                             |ancestor::refsect2
701                                             |ancestor::refsect3)[last()]"/>
702       <xsl:if test="count($lparent)>0">
703         <xsl:apply-templates select="$lparent" mode="label.content"/>
704       </xsl:if>
705     </xsl:if>
706   </xsl:variable>
707   <xsl:choose>
708     <xsl:when test="@label">
709       <xsl:value-of select="$prefix"/>
710       <xsl:value-of select="@label"/>
711       <xsl:value-of select="$punct"/>
712     </xsl:when>
713     <xsl:when test="$qandadiv.autolabel != 0">
714       <xsl:value-of select="$prefix"/>
715       <xsl:number level="multiple" count="qandadiv" format="1"/>
716       <xsl:value-of select="$punct"/>
717     </xsl:when>
718   </xsl:choose>
719 </xsl:template>
720
721 <xsl:template match="question|answer" mode="label.content">
722   <xsl:param name="punct">.</xsl:param>
723   <xsl:variable name="prefix">
724     <xsl:if test="$qanda.inherit.numeration != 0">
725       <xsl:variable name="lparent" select="(ancestor::set
726                                             |ancestor::book
727                                             |ancestor::chapter
728                                             |ancestor::appendix
729                                             |ancestor::preface
730                                             |ancestor::section
731                                             |ancestor::simplesect
732                                             |ancestor::sect1
733                                             |ancestor::sect2
734                                             |ancestor::sect3
735                                             |ancestor::sect4
736                                             |ancestor::sect5
737                                             |ancestor::refsect1
738                                             |ancestor::refsect2
739                                             |ancestor::refsect3
740                                             |ancestor::qandadiv)[last()]"/>
741       <xsl:if test="count($lparent)>0">
742         <xsl:apply-templates select="$lparent" mode="label.content"/>
743       </xsl:if>
744     </xsl:if>
745   </xsl:variable>
746
747   <xsl:variable name="inhlabel"
748                 select="ancestor-or-self::qandaset/@defaultlabel[1]"/>
749
750   <xsl:variable name="deflabel">
751     <xsl:choose>
752       <xsl:when test="$inhlabel != ''">
753         <xsl:value-of select="$inhlabel"/>
754       </xsl:when>
755       <xsl:otherwise>
756         <xsl:value-of select="$qanda.defaultlabel"/>
757       </xsl:otherwise>
758     </xsl:choose>
759   </xsl:variable>
760
761   <xsl:variable name="label" select="label"/>
762
763   <xsl:choose>
764     <xsl:when test="count($label)>0">
765       <xsl:value-of select="$prefix"/>
766       <xsl:apply-templates select="$label"/>
767       <xsl:value-of select="$punct"/>
768     </xsl:when>
769
770     <xsl:when test="$deflabel = 'qanda'">
771       <xsl:call-template name="gentext.element.name"/>
772     </xsl:when>
773
774     <xsl:when test="$deflabel = 'number'">
775       <xsl:if test="name(.) = 'question'">
776         <xsl:value-of select="$prefix"/>
777         <xsl:number level="multiple" count="qandaentry" format="1"/>
778         <xsl:value-of select="$punct"/>
779       </xsl:if>
780     </xsl:when>
781   </xsl:choose>
782 </xsl:template>
783
784 <xsl:template match="bibliography|glossary|index" mode="label.content">
785   <xsl:param name="punct">.</xsl:param>
786   <xsl:if test="@label">
787     <xsl:value-of select="@label"/>
788     <xsl:value-of select="$punct"/>
789   </xsl:if>
790 </xsl:template>
791
792 <xsl:template match="figure|table|example|equation" mode="label.content">
793   <xsl:param name="punct">.</xsl:param>
794   <xsl:choose>
795     <xsl:when test="@label">
796       <xsl:value-of select="@label"/>
797       <xsl:value-of select="$punct"/>
798     </xsl:when>
799     <xsl:otherwise>
800       <xsl:variable name="pchap"
801                     select="ancestor::chapter|ancestor::appendix"/>
802       <xsl:choose>
803         <xsl:when test="count($pchap)>0">
804           <xsl:apply-templates select="$pchap" mode="label.content">
805             <xsl:with-param name="punct">.</xsl:with-param>
806           </xsl:apply-templates>
807           <xsl:number format="1" from="chapter|appendix" level="any"/>
808           <xsl:value-of select="$punct"/>
809         </xsl:when>
810         <xsl:otherwise>
811           <xsl:number format="1" from="book|article" level="any"/>
812           <xsl:value-of select="$punct"/>
813         </xsl:otherwise>
814       </xsl:choose>
815     </xsl:otherwise>
816   </xsl:choose>
817 </xsl:template>
818
819 <xsl:template match="abstract" mode="label.content">
820   <xsl:param name="punct">.</xsl:param>
821 </xsl:template>
822
823 <!-- ====================================================================== -->
824
825 <xsl:template name="label.this.section">
826   <xsl:param name="section" select="."/>
827   <xsl:value-of select="$section.autolabel"/>
828 </xsl:template>
829
830 <doc:template name="label.this.section" xmlns="">
831 <refpurpose>Returns true if $section should be labelled</refpurpose>
832 <refdescription>
833 <para>Returns true if the specified section should be labelled.
834 By default, this template simply returns $section.autolabel, but
835 custom stylesheets may override it to get more selective behavior.</para>
836 </refdescription>
837 </doc:template>
838
839 <!-- ====================================================================== -->
840 <!-- title content -->
841
842 <doc:mode mode="title.content" xmlns="">
843 <refpurpose>Provides access to element titles</refpurpose>
844 <refdescription>
845 <para>Processing an element in the
846 <literal role="mode">title.content</literal> mode produces the
847 title of the element. This does not include the label. If
848 <parameter>text-only</parameter> is true, the text of the title
849 is returned, without inline markup, otherwise inline markup is processed
850 (in the default mode). By default, <parameter>text-only</parameter>
851 is false.
852 </para>
853 </refdescription>
854 </doc:mode>
855
856 <xsl:template match="*" mode="title.content">
857   <xsl:param name="text-only" select="'0'"/>
858   <xsl:param name="allow-anchors" select="'0'"/>
859   <xsl:choose>
860     <xsl:when test="title">
861       <xsl:apply-templates select="title[1]" mode="title.content">
862         <xsl:with-param name="text-only" select="$text-only"/>
863         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
864       </xsl:apply-templates>
865     </xsl:when>
866     <xsl:otherwise>
867       <xsl:message>
868         <xsl:text>Request for title of unexpected element: </xsl:text>
869         <xsl:value-of select="name(.)"/>
870       </xsl:message>
871       <xsl:text>???TITLE???</xsl:text>
872     </xsl:otherwise>
873   </xsl:choose>
874 </xsl:template>
875
876 <xsl:template match="*" mode="no.anchor.mode">
877   <xsl:apply-templates select="."/>
878 </xsl:template>
879
880 <xsl:template match="anchor" mode="no.anchor.mode">
881   <!-- nop, suppressed -->
882 </xsl:template>
883
884 <xsl:template match="title" mode="title.content">
885   <xsl:param name="text-only" select="'0'"/>
886   <xsl:param name="allow-anchors" select="'0'"/>
887   <xsl:choose>
888     <xsl:when test="$text-only != 0">
889       <xsl:value-of select="."/>
890     </xsl:when>
891     <xsl:otherwise>
892       <xsl:choose>
893         <xsl:when test="$allow-anchors != 0">
894           <xsl:apply-templates/>
895         </xsl:when>
896         <xsl:otherwise>
897           <xsl:apply-templates mode="no.anchor.mode"/>
898         </xsl:otherwise>
899       </xsl:choose>
900     </xsl:otherwise>
901   </xsl:choose>
902 </xsl:template>
903
904 <xsl:template match="set" mode="title.content">
905   <xsl:param name="text-only" select="'0'"/>
906   <xsl:param name="allow-anchors" select="'0'"/>
907   <xsl:apply-templates select="(setinfo/title|title)[1]"
908                        mode="title.content">
909     <xsl:with-param name="text-only" select="$text-only"/>
910     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
911   </xsl:apply-templates>
912 </xsl:template>
913
914 <xsl:template match="book" mode="title.content">
915   <xsl:param name="text-only" select="'0'"/>
916   <xsl:param name="allow-anchors" select="'0'"/>
917   <xsl:apply-templates select="(bookinfo/title|title)[1]"
918                        mode="title.content">
919     <xsl:with-param name="text-only" select="$text-only"/>
920     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
921   </xsl:apply-templates>
922 </xsl:template>
923
924 <xsl:template match="part" mode="title.content">
925   <xsl:param name="text-only" select="'0'"/>
926   <xsl:param name="allow-anchors" select="'0'"/>
927   <xsl:apply-templates select="(partinfo/title|docinfo/title|title)[1]"
928                        mode="title.content">
929     <xsl:with-param name="text-only" select="$text-only"/>
930     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
931   </xsl:apply-templates>
932 </xsl:template>
933
934 <xsl:template match="preface|chapter|appendix" mode="title.content">
935   <xsl:param name="text-only" select="'0'"/>
936   <xsl:param name="allow-anchors" select="'0'"/>
937   <xsl:variable name="title" select="(docinfo/title
938                                       |prefaceinfo/title
939                                       |chapterinfo/title
940                                       |appendixinfo/title
941                                       |title)[1]"/>
942   <xsl:choose>
943     <xsl:when test="$title">
944       <xsl:apply-templates select="$title" mode="title.content">
945         <xsl:with-param name="text-only" select="$text-only"/>
946         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
947       </xsl:apply-templates>
948     </xsl:when>
949     <xsl:otherwise>
950       <xsl:call-template name="gentext.element.name">
951         <xsl:with-param name="element.name" select="name(.)"/>
952       </xsl:call-template>
953     </xsl:otherwise>
954   </xsl:choose>
955 </xsl:template>
956
957 <xsl:template match="dedication|colophon" mode="title.content">
958   <xsl:param name="text-only" select="'0'"/>
959   <xsl:param name="allow-anchors" select="'0'"/>
960   <xsl:choose>
961     <xsl:when test="title">
962       <xsl:apply-templates select="title" mode="title.content">
963         <xsl:with-param name="text-only" select="$text-only"/>
964         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
965       </xsl:apply-templates>
966     </xsl:when>
967     <xsl:otherwise>
968       <xsl:call-template name="gentext.element.name">
969         <xsl:with-param name="element.name" select="name(.)"/>
970       </xsl:call-template>
971     </xsl:otherwise>
972   </xsl:choose>
973 </xsl:template>
974
975 <xsl:template match="article" mode="title.content">
976   <xsl:param name="text-only" select="'0'"/>
977   <xsl:param name="allow-anchors" select="'0'"/>
978   <xsl:variable name="title" select="(artheader/title
979                                       |articleinfo/title
980                                       |title)[1]"/>
981
982   <xsl:apply-templates select="$title" mode="title.content">
983     <xsl:with-param name="text-only" select="$text-only"/>
984     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
985   </xsl:apply-templates>
986 </xsl:template>
987
988 <xsl:template match="reference" mode="title.content">
989   <xsl:param name="text-only" select="'0'"/>
990   <xsl:param name="allow-anchors" select="'0'"/>
991   <xsl:apply-templates select="(referenceinfo/title|docinfo/title|title)[1]"
992                        mode="title.content">
993     <xsl:with-param name="text-only" select="$text-only"/>
994     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
995   </xsl:apply-templates>
996 </xsl:template>
997
998 <xsl:template match="refentry" mode="title.content">
999   <xsl:param name="text-only" select="'0'"/>
1000   <xsl:param name="allow-anchors" select="'0'"/>
1001   <xsl:variable name="refmeta" select=".//refmeta"/>
1002   <xsl:variable name="refentrytitle" select="$refmeta//refentrytitle"/>
1003   <xsl:variable name="refnamediv" select=".//refnamediv"/>
1004   <xsl:variable name="refname" select="$refnamediv//refname"/>
1005
1006   <xsl:variable name="title">
1007     <xsl:choose>
1008       <xsl:when test="$refentrytitle">
1009         <xsl:apply-templates select="$refentrytitle[1]" mode="title.content"/>
1010       </xsl:when>
1011       <xsl:when test="$refname">
1012         <xsl:apply-templates select="$refname[1]" mode="title.content"/>
1013       </xsl:when>
1014       <xsl:otherwise>REFENTRY WITHOUT TITLE???</xsl:otherwise>
1015     </xsl:choose>
1016   </xsl:variable>
1017
1018   <xsl:choose>
1019     <xsl:when test="$text-only != 0">
1020       <xsl:value-of select="$title"/>
1021     </xsl:when>
1022     <xsl:otherwise><xsl:copy-of select="$title"/></xsl:otherwise>
1023   </xsl:choose>
1024 </xsl:template>
1025
1026 <xsl:template match="refentrytitle|refname" mode="title.content">
1027   <xsl:apply-templates/>
1028 </xsl:template>
1029
1030 <xsl:template match="section
1031                      |sect1|sect2|sect3|sect4|sect5
1032                      |refsect1|refsect2|refsect3
1033                      |simplesect"
1034               mode="title.content">
1035   <xsl:param name="text-only" select="'0'"/>
1036   <xsl:param name="allow-anchors" select="'0'"/>
1037   <xsl:variable name="title" select="(sectioninfo/title
1038                                       |sect1info/title
1039                                       |sect2info/title
1040                                       |sect3info/title
1041                                       |sect4info/title
1042                                       |sect5info/title
1043                                       |refsect1info/title
1044                                       |refsect2info/title
1045                                       |refsect3info/title
1046                                       |title)[1]"/>
1047
1048   <xsl:apply-templates select="$title" mode="title.content">
1049     <xsl:with-param name="text-only" select="$text-only"/>
1050     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
1051   </xsl:apply-templates>
1052 </xsl:template>
1053
1054 <xsl:template match="bibliography|glossary|index" mode="title.content">
1055   <xsl:param name="text-only" select="'0'"/>
1056   <xsl:param name="allow-anchors" select="'0'"/>
1057   <xsl:choose>
1058     <xsl:when test="title">
1059       <xsl:apply-templates select="title" mode="title.content">
1060         <xsl:with-param name="text-only" select="$text-only"/>
1061         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
1062       </xsl:apply-templates>
1063     </xsl:when>
1064     <xsl:otherwise>
1065       <xsl:call-template name="gentext.element.name">
1066         <xsl:with-param name="element.name" select="name(.)"/>
1067       </xsl:call-template>
1068     </xsl:otherwise>
1069   </xsl:choose>
1070 </xsl:template>
1071
1072 <xsl:template match="figure|table|example|equation" mode="title.content">
1073   <xsl:param name="text-only" select="'0'"/>
1074   <xsl:param name="allow-anchors" select="'0'"/>
1075   <xsl:apply-templates select="title" mode="title.content">
1076     <xsl:with-param name="text-only" select="$text-only"/>
1077     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
1078   </xsl:apply-templates>
1079 </xsl:template>
1080
1081 <xsl:template match="abstract" mode="title.content">
1082   <xsl:param name="text-only" select="'0'"/>
1083   <xsl:param name="allow-anchors" select="'0'"/>
1084   <xsl:choose>
1085     <xsl:when test="title">
1086       <xsl:apply-templates select="title" mode="title.content">
1087         <xsl:with-param name="text-only" select="$text-only"/>
1088         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
1089       </xsl:apply-templates>
1090     </xsl:when>
1091     <xsl:otherwise>
1092       <xsl:call-template name="gentext.element.name">
1093         <xsl:with-param name="element.name" select="name(.)"/>
1094       </xsl:call-template>
1095     </xsl:otherwise>
1096   </xsl:choose>
1097 </xsl:template>
1098
1099 <!-- ====================================================================== -->
1100 <!-- subtitle content -->
1101
1102 <doc:mode mode="subtitle.content" xmlns="">
1103 <refpurpose>Provides access to element subtitles</refpurpose>
1104 <refdescription>
1105 <para>Processing an element in the
1106 <literal role="mode">subtitle.content</literal> mode produces the
1107 subtitle of the element. If
1108 <parameter>text-only</parameter> is true, the text of the title
1109 is returned, without inline markup, otherwise inline markup is processed
1110 (in the default mode). By default, <parameter>text-only</parameter>
1111 is false.
1112 </para>
1113 </refdescription>
1114 </doc:mode>
1115
1116 <xsl:template match="*" mode="subtitle.content">
1117   <xsl:message>
1118     <xsl:text>Request for subtitle of unexpected element: </xsl:text>
1119     <xsl:value-of select="name(.)"/>
1120   </xsl:message>
1121   <xsl:text>???SUBTITLE???</xsl:text>
1122 </xsl:template>
1123
1124 <xsl:template match="subtitle" mode="subtitle.content">
1125   <xsl:param name="text-only" select="'0'"/>
1126   <xsl:param name="allow-anchors" select="'0'"/>
1127   <xsl:choose>
1128     <xsl:when test="$text-only != 0">
1129       <xsl:value-of select="."/>
1130     </xsl:when>
1131     <xsl:otherwise>
1132       <xsl:apply-templates/>
1133     </xsl:otherwise>
1134   </xsl:choose>
1135 </xsl:template>
1136
1137 <xsl:template match="set" mode="subtitle.content">
1138   <xsl:param name="text-only" select="'0'"/>
1139   <xsl:param name="allow-anchors" select="'0'"/>
1140   <xsl:apply-templates select="(setinfo/subtitle|subtitle)[1]"
1141                        mode="subtitle.content">
1142     <xsl:with-param name="text-only" select="$text-only"/>
1143     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
1144   </xsl:apply-templates>
1145 </xsl:template>
1146
1147 <xsl:template match="book" mode="subtitle.content">
1148   <xsl:param name="text-only" select="'0'"/>
1149   <xsl:param name="allow-anchors" select="'0'"/>
1150   <xsl:apply-templates select="(bookinfo/subtitle|subtitle)[1]"
1151                        mode="subtitle.content">
1152     <xsl:with-param name="text-only" select="$text-only"/>
1153     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
1154   </xsl:apply-templates>
1155 </xsl:template>
1156
1157 <xsl:template match="part" mode="subtitle.content">
1158   <xsl:param name="text-only" select="'0'"/>
1159   <xsl:param name="allow-anchors" select="'0'"/>
1160   <xsl:apply-templates select="(partinfo/subtitle
1161                                 |docinfo/subtitle
1162                                 |subtitle)[1]"
1163                        mode="subtitle.content">
1164     <xsl:with-param name="text-only" select="$text-only"/>
1165     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
1166   </xsl:apply-templates>
1167 </xsl:template>
1168
1169 <xsl:template match="preface|chapter|appendix" mode="subtitle.content">
1170   <xsl:param name="text-only" select="'0'"/>
1171   <xsl:param name="allow-anchors" select="'0'"/>
1172   <xsl:apply-templates select="(docinfo/subtitle
1173                                 |prefaceinfo/subtitle
1174                                 |chapterinfo/subtitle
1175                                 |appendixinfo/subtitle
1176                                 |subtitle)[1]"
1177                        mode="subtitle.content">
1178     <xsl:with-param name="text-only" select="$text-only"/>
1179     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
1180   </xsl:apply-templates>
1181 </xsl:template>
1182
1183 <xsl:template match="dedication|colophon" mode="subtitle.content">
1184   <xsl:param name="text-only" select="'0'"/>
1185   <xsl:param name="allow-anchors" select="'0'"/>
1186   <xsl:apply-templates select="subtitle"
1187                        mode="subtitle.content">
1188     <xsl:with-param name="text-only" select="$text-only"/>
1189     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
1190   </xsl:apply-templates>
1191 </xsl:template>
1192
1193 <xsl:template match="reference" mode="subtitle.content">
1194   <xsl:param name="text-only" select="'0'"/>
1195   <xsl:param name="allow-anchors" select="'0'"/>
1196   <xsl:apply-templates select="(referenceinfo/subtitle
1197                                 |docinfo/subtitle
1198                                 |subtitle)[1]"
1199                        mode="subtitle.content">
1200     <xsl:with-param name="text-only" select="$text-only"/>
1201     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
1202   </xsl:apply-templates>
1203 </xsl:template>
1204
1205 <xsl:template match="refentry" mode="subtitle.content">
1206   <xsl:param name="text-only" select="'0'"/>
1207   <xsl:param name="allow-anchors" select="'0'"/>
1208   <xsl:apply-templates select="(refentryinfo/subtitle
1209                                 |docinfo/subtitle)[1]"
1210                        mode="subtitle.content">
1211     <xsl:with-param name="text-only" select="$text-only"/>
1212     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
1213   </xsl:apply-templates>
1214 </xsl:template>
1215
1216 <xsl:template match="section
1217                      |sect1|sect2|sect3|sect4|sect5
1218                      |refsect1|refsect2|refsect3
1219                      |simplesect"
1220               mode="subtitle.content">
1221   <xsl:param name="text-only" select="'0'"/>
1222   <xsl:param name="allow-anchors" select="'0'"/>
1223   <xsl:apply-templates select="(sectioninfo/subtitle
1224                                 |sect1info/subtitle
1225                                 |sect2info/subtitle
1226                                 |sect3info/subtitle
1227                                 |sect4info/subtitle
1228                                 |sect5info/subtitle
1229                                 |refsect1info/subtitle
1230                                 |refsect2info/subtitle
1231                                 |refsect3info/subtitle
1232                                 |subtitle)[1]"
1233                        mode="subtitle.content">
1234     <xsl:with-param name="text-only" select="$text-only"/>
1235     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
1236   </xsl:apply-templates>
1237 </xsl:template>
1238
1239 <!-- ====================================================================== -->
1240 <!-- title reference (label + title) -->
1241
1242 <doc:mode mode="title.ref" xmlns="">
1243 <refpurpose>Provides reference text for an element</refpurpose>
1244 <refdescription>
1245 <para>Processing an element in the
1246 <literal role="mode">title.ref</literal> mode produces the
1247 label and title of the element.
1248 </para>
1249 </refdescription>
1250 <refparameter>
1251 <variablelist>
1252 <varlistentry><term>text-only</term>
1253 <listitem>
1254 <para> If
1255 <parameter>text-only</parameter> is true, the text of the title
1256 is returned, without inline markup, otherwise inline markup is processed
1257 (in the default mode). By default, <parameter>text-only</parameter>
1258 is false.</para>
1259 </listitem>
1260 </varlistentry>
1261 <varlistentry><term>label-wrapper</term>
1262 <listitem>
1263 <para>If <parameter>label-wrapper</parameter> is not the emtpy string,
1264 it must be the name of an element. The element so named will be wrapped
1265 around labels on output.</para>
1266 </listitem>
1267 </varlistentry>
1268 <varlistentry><term>title-wrapper</term>
1269 <listitem>
1270 <para>If <parameter>title.wrapper</parameter> is not the emtpy string,
1271 it must be the name of an element. The element so named will be wrapped
1272 around titles on output.</para>
1273 </listitem>
1274 </varlistentry>
1275 <varlistentry><term>label-wrapper-class</term>
1276 <listitem>
1277 <para>If a <parameter>label-wrapper</parameter> is provided and
1278 <parameter>label-wrapper-class</parameter> is not the emtpy string,
1279 it be used as the value for a <sgmltag class="attribute">class</sgmltag>
1280 attribute on the <parameter>label-wrapper</parameter> element.</para>
1281 <para>This is a dirty hack because it only makes sense for the HTML
1282 stylesheet (there's no <sgmltag class="attribute">class</sgmltag> attribute
1283 on the FO elements). What I'd really like to do is pass an attribute
1284 set as a parameter, but I can't.</para>
1285 </listitem>
1286 </varlistentry>
1287 <varlistentry><term>title-wrapper-class</term>
1288 <listitem>
1289 <para>If a <parameter>title-wrapper</parameter> is provided and
1290 <parameter>title-wrapper-class</parameter> is not the emtpy string,
1291 it be used as the value for a <sgmltag class="attribute">class</sgmltag>
1292 attribute on the <parameter>title-wrapper</parameter> element.</para>
1293 <para>This is a dirty hack because it only makes sense for the HTML
1294 stylesheet (there's no <sgmltag class="attribute">class</sgmltag> attribute
1295 on the FO elements). What I'd really like to do is pass an attribute
1296 set as a parameter, but I can't.</para>
1297 </listitem>
1298 </varlistentry>
1299 </variablelist>
1300 </refparameter>
1301 </doc:mode>
1302
1303 <xsl:template match="*" mode="title.ref">
1304   <xsl:param name="text-only" select="'0'"/>
1305   <xsl:param name="allow-anchors" select="'0'"/>
1306   <xsl:param name="label-wrapper" select="''"/>
1307   <xsl:param name="title-wrapper" select="''"/>
1308   <!-- Dirty hack -->
1309   <xsl:param name="label-wrapper-class" select="''"/>
1310   <xsl:param name="title-wrapper-class" select="''"/>
1311
1312   <xsl:variable name="label">
1313     <xsl:apply-templates select="." mode="label.content"/>
1314   </xsl:variable>
1315
1316   <xsl:if test="$label != ''">
1317     <xsl:choose>
1318       <xsl:when test="$text-only = 0">
1319         <xsl:choose>
1320           <xsl:when test="$label-wrapper != ''">
1321             <xsl:element name="{$label-wrapper}">
1322               <xsl:if test="$label-wrapper-class != ''">
1323                 <xsl:attribute name="class">
1324                   <xsl:value-of select="$label-wrapper-class"/>
1325                 </xsl:attribute>
1326               </xsl:if>
1327               <xsl:copy-of select="$label"/>
1328             </xsl:element>
1329           </xsl:when>
1330           <xsl:otherwise>
1331             <xsl:copy-of select="$label"/>
1332           </xsl:otherwise>
1333         </xsl:choose>
1334         <xsl:text> </xsl:text>
1335       </xsl:when>
1336       <xsl:otherwise>
1337         <xsl:value-of select="$label"/>
1338         <xsl:text> </xsl:text>
1339       </xsl:otherwise>
1340     </xsl:choose>
1341   </xsl:if>
1342
1343   <xsl:choose>
1344     <xsl:when test="$text-only = 0">
1345       <xsl:choose>
1346         <xsl:when test="$title-wrapper != ''">
1347           <xsl:element name="{$title-wrapper}">
1348             <xsl:if test="$title-wrapper-class != ''">
1349               <xsl:attribute name="class">
1350                 <xsl:value-of select="$title-wrapper-class"/>
1351               </xsl:attribute>
1352             </xsl:if>
1353             <xsl:apply-templates select="." mode="title.content">
1354               <xsl:with-param name="text-only" select="$text-only"/>
1355               <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
1356             </xsl:apply-templates>
1357           </xsl:element>
1358         </xsl:when>
1359         <xsl:otherwise>
1360           <xsl:apply-templates select="." mode="title.content">
1361             <xsl:with-param name="text-only" select="$text-only"/>
1362             <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
1363           </xsl:apply-templates>
1364         </xsl:otherwise>
1365       </xsl:choose>
1366     </xsl:when>
1367     <xsl:otherwise>
1368       <xsl:apply-templates select="." mode="title.content">
1369         <xsl:with-param name="text-only" select="$text-only"/>
1370         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
1371       </xsl:apply-templates>
1372     </xsl:otherwise>
1373   </xsl:choose>
1374 </xsl:template>
1375
1376 <xsl:template match="figure|table|example|equation
1377                      |chapter|appendix" mode="title.ref">
1378   <xsl:param name="text-only" select="'0'"/>
1379   <xsl:param name="allow-anchors" select="'0'"/>
1380   <xsl:param name="label-wrapper" select="''"/>
1381   <xsl:param name="title-wrapper" select="''"/>
1382   <!-- Dirty hack -->
1383   <xsl:param name="label-wrapper-class" select="''"/>
1384   <xsl:param name="title-wrapper-class" select="''"/>
1385
1386   <xsl:variable name="label">
1387     <xsl:call-template name="gentext.element.name">
1388       <xsl:with-param name="element.name">
1389         <xsl:value-of select="name(.)"/>
1390       </xsl:with-param>
1391     </xsl:call-template>
1392     <xsl:call-template name="gentext.space"/>
1393     <xsl:apply-templates select="." mode="label.content"/>
1394   </xsl:variable>
1395
1396   <xsl:if test="$label != ''">
1397     <xsl:choose>
1398       <xsl:when test="$text-only = 0">
1399         <xsl:choose>
1400           <xsl:when test="$label-wrapper != ''">
1401             <xsl:element name="{$label-wrapper}">
1402               <xsl:if test="$label-wrapper-class != ''">
1403                 <xsl:attribute name="class">
1404                   <xsl:value-of select="$label-wrapper-class"/>
1405                 </xsl:attribute>
1406               </xsl:if>
1407               <xsl:copy-of select="$label"/>
1408             </xsl:element>
1409           </xsl:when>
1410           <xsl:otherwise>
1411             <xsl:copy-of select="$label"/>
1412           </xsl:otherwise>
1413         </xsl:choose>
1414         <xsl:text> </xsl:text>
1415       </xsl:when>
1416       <xsl:otherwise>
1417         <xsl:value-of select="$label"/>
1418         <xsl:text> </xsl:text>
1419       </xsl:otherwise>
1420     </xsl:choose>
1421   </xsl:if>
1422
1423   <xsl:choose>
1424     <xsl:when test="$text-only = 0">
1425       <xsl:choose>
1426         <xsl:when test="$title-wrapper != ''">
1427           <xsl:element name="{$title-wrapper}">
1428             <xsl:if test="$title-wrapper-class != ''">
1429               <xsl:attribute name="class">
1430                 <xsl:value-of select="$title-wrapper-class"/>
1431               </xsl:attribute>
1432             </xsl:if>
1433             <xsl:apply-templates select="." mode="title.content">
1434               <xsl:with-param name="text-only" select="$text-only"/>
1435               <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
1436             </xsl:apply-templates>
1437           </xsl:element>
1438         </xsl:when>
1439         <xsl:otherwise>
1440           <xsl:apply-templates select="." mode="title.content">
1441             <xsl:with-param name="text-only" select="$text-only"/>
1442             <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
1443           </xsl:apply-templates>
1444         </xsl:otherwise>
1445       </xsl:choose>
1446     </xsl:when>
1447     <xsl:otherwise>
1448       <xsl:apply-templates select="." mode="title.content">
1449         <xsl:with-param name="text-only" select="$text-only"/>
1450         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
1451       </xsl:apply-templates>
1452     </xsl:otherwise>
1453   </xsl:choose>
1454 </xsl:template>
1455
1456 <!-- ====================================================================== -->
1457
1458 <xsl:template name="xref.g.subst">
1459   <xsl:param name="string"></xsl:param>
1460   <xsl:param name="target" select="."/>
1461   <xsl:variable name="subst">%g</xsl:variable>
1462
1463   <xsl:choose>
1464     <xsl:when test="contains($string, $subst)">
1465       <xsl:value-of select="substring-before($string, $subst)"/>
1466       <xsl:call-template name="gentext.element.name">
1467         <xsl:with-param name="element.name" select="name($target)"/>
1468       </xsl:call-template>
1469       <xsl:call-template name="xref.g.subst">
1470         <xsl:with-param name="string"
1471                         select="substring-after($string, $subst)"/>
1472         <xsl:with-param name="target" select="$target"/>
1473       </xsl:call-template>
1474     </xsl:when>
1475     <xsl:otherwise>
1476       <xsl:value-of select="$string"/>
1477     </xsl:otherwise>
1478   </xsl:choose>
1479 </xsl:template>
1480
1481 <xsl:template name="xref.t.subst">
1482   <xsl:param name="string"></xsl:param>
1483   <xsl:param name="target" select="."/>
1484   <xsl:variable name="subst">%t</xsl:variable>
1485
1486   <xsl:choose>
1487     <xsl:when test="contains($string, $subst)">
1488       <xsl:call-template name="xref.g.subst">
1489         <xsl:with-param name="string"
1490                         select="substring-before($string, $subst)"/>
1491         <xsl:with-param name="target" select="$target"/>
1492       </xsl:call-template>
1493       <xsl:call-template name="title.xref">
1494         <xsl:with-param name="target" select="$target"/>
1495       </xsl:call-template>
1496       <xsl:call-template name="xref.t.subst">
1497         <xsl:with-param name="string"
1498                         select="substring-after($string, $subst)"/>
1499         <xsl:with-param name="target" select="$target"/>
1500       </xsl:call-template>
1501     </xsl:when>
1502     <xsl:otherwise>
1503       <xsl:call-template name="xref.g.subst">
1504         <xsl:with-param name="string" select="$string"/>
1505         <xsl:with-param name="target" select="$target"/>
1506       </xsl:call-template>
1507     </xsl:otherwise>
1508   </xsl:choose>
1509 </xsl:template>
1510
1511 <xsl:template name="xref.n.subst">
1512   <xsl:param name="string"></xsl:param>
1513   <xsl:param name="target" select="."/>
1514   <xsl:variable name="subst">%n</xsl:variable>
1515
1516   <xsl:choose>
1517     <xsl:when test="contains($string, $subst)">
1518       <xsl:call-template name="xref.t.subst">
1519         <xsl:with-param name="string"
1520                         select="substring-before($string, $subst)"/>
1521         <xsl:with-param name="target" select="$target"/>
1522       </xsl:call-template>
1523       <xsl:call-template name="number.xref">
1524         <xsl:with-param name="target" select="$target"/>
1525       </xsl:call-template>
1526       <xsl:call-template name="xref.t.subst">
1527         <xsl:with-param name="string"
1528                         select="substring-after($string, $subst)"/>
1529         <xsl:with-param name="target" select="$target"/>
1530       </xsl:call-template>
1531     </xsl:when>
1532     <xsl:otherwise>
1533       <xsl:call-template name="xref.t.subst">
1534         <xsl:with-param name="string" select="$string"/>
1535         <xsl:with-param name="target" select="$target"/>
1536       </xsl:call-template>
1537     </xsl:otherwise>
1538   </xsl:choose>
1539 </xsl:template>
1540
1541 <xsl:template name="subst.xref.text">
1542   <xsl:param name="xref.text"></xsl:param>
1543   <xsl:param name="target" select="."/>
1544
1545   <xsl:call-template name="xref.n.subst">
1546     <xsl:with-param name="string" select="$xref.text"/>
1547     <xsl:with-param name="target" select="$target"/>
1548   </xsl:call-template>
1549 </xsl:template>
1550
1551 <!-- ====================================================================== -->
1552
1553 <xsl:template name="filename-basename">
1554   <!-- We assume all filenames are really URIs and use "/" -->
1555   <xsl:param name="filename"></xsl:param>
1556   <xsl:param name="recurse" select="false()"/>
1557
1558   <xsl:choose>
1559     <xsl:when test="substring-after($filename, '/') != ''">
1560       <xsl:call-template name="filename-basename">
1561         <xsl:with-param name="filename"
1562                         select="substring-after($filename, '/')"/>
1563         <xsl:with-param name="recurse" select="true()"/>
1564       </xsl:call-template>
1565     </xsl:when>
1566     <xsl:otherwise>
1567       <xsl:value-of select="$filename"/>
1568     </xsl:otherwise>
1569   </xsl:choose>
1570 </xsl:template>
1571
1572 <xsl:template name="filename-extension">
1573   <xsl:param name="filename"></xsl:param>
1574   <xsl:param name="recurse" select="false()"/>
1575
1576   <!-- Make sure we only look at the base name... -->
1577   <xsl:variable name="basefn">
1578     <xsl:choose>
1579       <xsl:when test="$recurse">
1580         <xsl:value-of select="$filename"/>
1581       </xsl:when>
1582       <xsl:otherwise>
1583         <xsl:call-template name="filename-basename">
1584           <xsl:with-param name="filename" select="$filename"/>
1585         </xsl:call-template>
1586       </xsl:otherwise>
1587     </xsl:choose>
1588   </xsl:variable>
1589
1590   <xsl:choose>
1591     <xsl:when test="substring-after($basefn, '.') != ''">
1592       <xsl:call-template name="filename-extension">
1593         <xsl:with-param name="filename"
1594                         select="substring-after($basefn, '.')"/>
1595         <xsl:with-param name="recurse" select="true()"/>
1596       </xsl:call-template>
1597     </xsl:when>
1598     <xsl:when test="$recurse">
1599       <xsl:value-of select="$basefn"/>
1600     </xsl:when>
1601     <xsl:otherwise></xsl:otherwise>
1602   </xsl:choose>
1603 </xsl:template>
1604
1605 <!-- ====================================================================== -->
1606
1607 <doc:template name="select.mediaobject" xmlns="">
1608 <refpurpose>Selects an appropriate media object from a list</refpurpose>
1609
1610 <refdescription>
1611 <para>This template examines a list of media objects (usually the
1612 children of a mediaobject or inlinemediaobject) and processes
1613 the "right" object.</para>
1614
1615 <para>This template relies on a template named "is.acceptable.mediaobject"
1616 to determine if a given object is an acceptable graphic. The semantics
1617 of media objects is that the first acceptable graphic should be used.
1618 </para>
1619
1620 <para>If no acceptable object is located, nothing happens.</para>
1621 </refdescription>
1622
1623 <refparameter>
1624 <variablelist>
1625 <varlistentry><term>olist</term>
1626 <listitem>
1627 <para>The node list of potential objects to examine.</para>
1628 </listitem>
1629 </varlistentry>
1630 </variablelist>
1631 </refparameter>
1632
1633 <refreturn>
1634 <para>Calls &lt;xsl:apply-templates&gt; on the selected object.</para>
1635 </refreturn>
1636 </doc:template>
1637
1638 <xsl:template name="select.mediaobject">
1639   <xsl:param name="olist"
1640              select="imageobject|imageobjectco
1641                      |videoobject|audioobject|textobject"/>
1642   <xsl:param name="count">1</xsl:param>
1643
1644   <xsl:if test="$count &lt;= count($olist)">
1645     <xsl:variable name="object" select="$olist[position()=$count]"/>
1646
1647     <xsl:variable name="useobject">
1648       <xsl:choose>
1649         <!-- The phrase is never used -->
1650         <xsl:when test="name($object)='textobject' and $object/phrase">
1651           <xsl:text>0</xsl:text>
1652         </xsl:when>
1653         <!-- The first textobject is a reasonable fallback -->
1654         <xsl:when test="name($object)='textobject'">
1655           <xsl:text>1</xsl:text>
1656         </xsl:when>
1657         <!-- If there's only one object, use it -->
1658         <xsl:when test="$count = 1 and count($olist) = 1">
1659           <xsl:text>1</xsl:text>
1660         </xsl:when>
1661         <!-- Otherwise, see if this one is a useable graphic -->
1662         <xsl:otherwise>
1663           <xsl:choose>
1664             <!-- peek inside imageobjectco to simplify the test -->
1665             <xsl:when test="local-name($object) = 'imageobjectco'">
1666               <xsl:call-template name="is.acceptable.mediaobject">
1667                 <xsl:with-param name="object" select="$object/imageobject"/>
1668               </xsl:call-template>
1669             </xsl:when>
1670             <xsl:otherwise>
1671               <xsl:call-template name="is.acceptable.mediaobject">
1672                 <xsl:with-param name="object" select="$object"/>
1673               </xsl:call-template>
1674             </xsl:otherwise>
1675           </xsl:choose>
1676         </xsl:otherwise>
1677       </xsl:choose>
1678     </xsl:variable>
1679
1680     <xsl:choose>
1681       <xsl:when test="$useobject='1'">
1682         <xsl:apply-templates select="$object"/>
1683       </xsl:when>
1684       <xsl:otherwise>
1685         <xsl:call-template name="select.mediaobject">
1686           <xsl:with-param name="olist" select="$olist"/>
1687           <xsl:with-param name="count" select="$count + 1"/>
1688         </xsl:call-template>
1689       </xsl:otherwise>
1690     </xsl:choose>
1691   </xsl:if>
1692 </xsl:template>
1693
1694 <doc:template name="is.acceptable.mediaobject" xmlns="">
1695 <refpurpose>Returns '1' if the specified media object is recognized.</refpurpose>
1696
1697 <refdescription>
1698 <para>This template examines a media object and returns '1' if the
1699 object is recognized as a graphic.</para>
1700 </refdescription>
1701
1702 <refparameter>
1703 <variablelist>
1704 <varlistentry><term>object</term>
1705 <listitem>
1706 <para>The media object to consider.</para>
1707 </listitem>
1708 </varlistentry>
1709 </variablelist>
1710 </refparameter>
1711
1712 <refreturn>
1713 <para>0 or 1</para>
1714 </refreturn>
1715 </doc:template>
1716
1717 <xsl:template name="is.acceptable.mediaobject">
1718   <xsl:param name="object"></xsl:param>
1719
1720   <xsl:variable name="filename">
1721     <xsl:call-template name="mediaobject.filename">
1722       <xsl:with-param name="object" select="$object"/>
1723     </xsl:call-template>
1724   </xsl:variable>
1725
1726   <xsl:variable name="ext">
1727     <xsl:call-template name="filename-extension">
1728       <xsl:with-param name="filename" select="$filename"/>
1729     </xsl:call-template>
1730   </xsl:variable>
1731
1732   <!-- there will only be one -->
1733   <xsl:variable name="data" select="$object/videodata
1734                                     |$object/imagedata
1735                                     |$object/audiodata"/>
1736
1737   <xsl:variable name="format" select="$data/@format"/>
1738
1739   <xsl:variable name="graphic.format">
1740     <xsl:if test="$format">
1741       <xsl:call-template name="is.graphic.format">
1742         <xsl:with-param name="format" select="$format"/>
1743       </xsl:call-template>
1744     </xsl:if>
1745   </xsl:variable>
1746
1747   <xsl:variable name="graphic.ext">
1748     <xsl:if test="$ext">
1749       <xsl:call-template name="is.graphic.extension">
1750         <xsl:with-param name="ext" select="$ext"/>
1751       </xsl:call-template>
1752     </xsl:if>
1753   </xsl:variable>
1754
1755   <xsl:choose>
1756     <xsl:when test="$graphic.format = '1'">1</xsl:when>
1757     <xsl:when test="$graphic.ext = '1'">1</xsl:when>
1758     <xsl:otherwise>0</xsl:otherwise>
1759   </xsl:choose>
1760 </xsl:template>
1761
1762 <xsl:template name="is.graphic.format">
1763   <xsl:param name="format"></xsl:param>
1764   <xsl:if test="$format = 'PNG'
1765                 or $format = 'JPG'
1766                 or $format = 'JPEG'
1767                 or $format = 'linespecific'
1768                 or $format = 'GIF'
1769                 or $format = 'GIF87a'
1770                 or $format = 'GIF89a'
1771                 or $format = 'BMP'">1</xsl:if>
1772 </xsl:template>
1773
1774 <xsl:template name="is.graphic.extension">
1775   <xsl:param name="ext"></xsl:param>
1776   <xsl:if test="$ext = 'png'
1777                 or $ext = 'jpeg'
1778                 or $ext = 'jpg'
1779                 or $ext = 'avi'
1780                 or $ext = 'mpg'
1781                 or $ext = 'mpeg'
1782                 or $ext = 'qt'
1783                 or $ext = 'gif'
1784                 or $ext = 'bmp'">1</xsl:if>
1785 </xsl:template>
1786
1787 <xsl:template name="mediaobject.filename">
1788   <xsl:param name="object"></xsl:param>
1789
1790   <xsl:variable name="data" select="$object/videodata
1791                                     |$object/imagedata
1792                                     |$object/audiodata"/>
1793
1794   <xsl:variable name="filename">
1795     <xsl:choose>
1796       <xsl:when test="$data[@fileref]">
1797         <xsl:value-of select="$data/@fileref"/>
1798       </xsl:when>
1799       <xsl:when test="$data[@entityref]">
1800         <xsl:value-of select="unparsed-entity-uri($data/@entityref)"/>
1801       </xsl:when>
1802       <xsl:otherwise></xsl:otherwise>
1803     </xsl:choose>
1804   </xsl:variable>
1805
1806   <xsl:variable name="has.ext" select="contains($filename, '.') != ''"/>
1807
1808   <xsl:variable name="ext">
1809     <xsl:choose>
1810       <xsl:when test="contains($filename, '.')">
1811         <xsl:call-template name="filename-extension">
1812           <xsl:with-param name="filename" select="$filename"/>
1813         </xsl:call-template>
1814       </xsl:when>
1815       <xsl:otherwise>
1816         <xsl:value-of select="$graphic.default.extension"/>
1817       </xsl:otherwise>
1818     </xsl:choose>
1819   </xsl:variable>
1820
1821   <xsl:variable name="graphic.ext">
1822     <xsl:call-template name="is.graphic.extension">
1823       <xsl:with-param name="ext" select="$ext"/>
1824     </xsl:call-template>
1825   </xsl:variable>
1826
1827   <xsl:choose>
1828     <xsl:when test="not($has.ext)">
1829       <xsl:choose>
1830         <xsl:when test="$ext != ''">
1831           <xsl:value-of select="$filename"/>
1832           <xsl:text>.</xsl:text>
1833           <xsl:value-of select="$ext"/>
1834         </xsl:when>
1835         <xsl:otherwise>
1836           <xsl:value-of select="$filename"/>
1837         </xsl:otherwise>
1838       </xsl:choose>
1839     </xsl:when>
1840     <xsl:when test="not($graphic.ext)">
1841       <xsl:choose>
1842         <xsl:when test="$graphic.default.extension != ''">
1843           <xsl:value-of select="$filename"/>
1844           <xsl:text>.</xsl:text>
1845           <xsl:value-of select="$graphic.default.extension"/>
1846         </xsl:when>
1847         <xsl:otherwise>
1848           <xsl:value-of select="$filename"/>
1849         </xsl:otherwise>
1850       </xsl:choose>
1851     </xsl:when>
1852     <xsl:otherwise>
1853       <xsl:value-of select="$filename"/>
1854     </xsl:otherwise>
1855   </xsl:choose>
1856 </xsl:template>
1857
1858 <!-- ====================================================================== -->
1859
1860 <doc:template name="check.id.unique" xmlns="">
1861 <refpurpose>Warn users about references to non-unique IDs</refpurpose>
1862 <refdescription>
1863 <para>If passed an ID in <varname>linkend</varname>,
1864 <function>check.id.unique</function> prints
1865 a warning message to the user if either the ID does not exist or
1866 the ID is not unique.</para>
1867 </refdescription>
1868 </doc:template>
1869
1870 <xsl:template name="check.id.unique">
1871   <xsl:param name="linkend"></xsl:param>
1872   <xsl:if test="$linkend != ''">
1873     <xsl:variable name="targets" select="id($linkend)"/>
1874     <xsl:variable name="target" select="$targets[1]"/>
1875
1876     <xsl:if test="count($targets)=0">
1877       <xsl:message>
1878         <xsl:text>Error: no ID for constraint linkend: </xsl:text>
1879         <xsl:value-of select="$linkend"/>
1880         <xsl:text>.</xsl:text>
1881       </xsl:message>
1882     </xsl:if>
1883
1884     <xsl:if test="count($targets)>1">
1885       <xsl:message>
1886         <xsl:text>Warning: multiple "IDs" for constraint linkend: </xsl:text>
1887         <xsl:value-of select="$linkend"/>
1888         <xsl:text>.</xsl:text>
1889       </xsl:message>
1890     </xsl:if>
1891   </xsl:if>
1892 </xsl:template>
1893
1894 <doc:template name="check.idref.targets" xmlns="">
1895 <refpurpose>Warn users about incorrectly typed references</refpurpose>
1896 <refdescription>
1897 <para>If passed an ID in <varname>linkend</varname>,
1898 <function>check.idref.targets</function> makes sure that the element
1899 pointed to by the link is one of the elements listed in
1900 <varname>element-list</varname> and warns the user otherwise.</para>
1901 </refdescription>
1902 </doc:template>
1903
1904 <xsl:template name="check.idref.targets">
1905   <xsl:param name="linkend"></xsl:param>
1906   <xsl:param name="element-list"></xsl:param>
1907   <xsl:if test="$linkend != ''">
1908     <xsl:variable name="targets" select="id($linkend)"/>
1909     <xsl:variable name="target" select="$targets[1]"/>
1910
1911     <xsl:if test="count($target) &gt; 0">
1912       <xsl:if test="not(contains(concat(' ', $element-list, ' '), name($target)))">
1913         <xsl:message>
1914           <xsl:text>Error: linkend (</xsl:text>
1915           <xsl:value-of select="$linkend"/>
1916           <xsl:text>) points to "</xsl:text>
1917           <xsl:value-of select="name($target)"/>
1918           <xsl:text>" not (one of): </xsl:text>
1919           <xsl:value-of select="$element-list"/>
1920         </xsl:message>
1921       </xsl:if>
1922     </xsl:if>
1923   </xsl:if>
1924 </xsl:template>
1925
1926 <!-- ====================================================================== -->
1927
1928 </xsl:stylesheet>
1929