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$
9     ********************************************************************
10
11     This file is part of the XSL DocBook Stylesheet distribution.
12     See /README or http://nwalsh.com/docbook/xsl/ for copyright
13     and other information.
14
15     This file contains general templates common to both the HTML and FO
16     versions of the DocBook stylesheets.
17     ******************************************************************** -->
18
19<doc:reference xmlns="">
20<referenceinfo>
21<releaseinfo role="meta">
22$Id$
23</releaseinfo>
24<author><surname>Walsh</surname>
25<firstname>Norman</firstname></author>
26<copyright><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
36Stylesheets; it documents (some of) the parameters, templates, and
37other elements of the stylesheets.</para>
38
39<para>This is not intended to be <quote>user</quote> documentation.
40It is provided for developers writing customization layers for the
41stylesheets, and for anyone who's interested in <quote>how it
42works</quote>.</para>
43
44<para>Although I am trying to be thorough, this documentation is known
45to 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="
57abstract affiliation anchor answer appendix area areaset areaspec
58artheader article audiodata audioobject author authorblurb authorgroup
59beginpage bibliodiv biblioentry bibliography biblioset blockquote book
60bookbiblio bookinfo callout calloutlist caption caution chapter
61citerefentry cmdsynopsis co collab colophon colspec confgroup
62copyright dedication docinfo editor entry entrytbl epigraph equation
63example figure footnote footnoteref formalpara funcprototype
64funcsynopsis glossary glossdef glossdiv glossentry glosslist graphicco
65group highlights imagedata imageobject imageobjectco important index
66indexdiv indexentry indexterm informalequation informalexample
67informalfigure informaltable inlineequation inlinemediaobject
68itemizedlist itermset keycombo keywordset legalnotice listitem lot
69mediaobject mediaobjectco menuchoice msg msgentry msgexplan msginfo
70msgmain msgrel msgset msgsub msgtext note objectinfo
71orderedlist othercredit part partintro preface printhistory procedure
72programlistingco publisher qandadiv qandaentry qandaset question
73refentry reference refmeta refnamediv refsect1 refsect1info refsect2
74refsect2info refsect3 refsect3info refsynopsisdiv refsynopsisdivinfo
75revhistory revision row sbr screenco screenshot sect1 sect1info sect2
76sect2info sect3 sect3info sect4 sect4info sect5 sect5info section
77sectioninfo seglistitem segmentedlist seriesinfo set setindex setinfo
78shortcut sidebar simplelist simplesect spanspec step subject
79subjectset substeps synopfragment table tbody textobject tfoot tgroup
80thead tip toc tocchap toclevel1 toclevel2 toclevel3 toclevel4
81toclevel5 tocpart varargs variablelist varlistentry videodata
82videoobject void warning subjectset
83
84classsynopsis
85constructorsynopsis
86destructorsynopsis
87fieldsynopsis
88methodparam
89methodsynopsis
90ooclass
91ooexception
92oointerface
93simplemsgentry
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.
186Hierarchically, components are <quote>top level</quote>, so a
187<sgmltag>sect1</sgmltag> is at level 2, <sgmltag>sect3</sgmltag> is
188at 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.
198Defaults 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="$/section">6</xsl:when>
221        <xsl:when test="$/section">5</xsl:when>
222        <xsl:when test="$/section">4</xsl:when>
223        <xsl:when test="$/section">3</xsl:when>
224        <xsl:otherwise>2</xsl:otherwise>
225      </xsl:choose>
226    </xsl:when>
227    <xsl:when test="name($node)='refsect1'">2</xsl:when>
228    <xsl:when test="name($node)='refsect2'">3</xsl:when>
229    <xsl:when test="name($node)='refsect3'">4</xsl:when>
230    <xsl:when test="name($node)='simplesect'">
231      <xsl:choose>
232        <xsl:when test="$/sect1">3</xsl:when>
233        <xsl:when test="$/sect2">4</xsl:when>
234        <xsl:when test="$/sect3">5</xsl:when>
235        <xsl:when test="$/sect4">6</xsl:when>
236        <xsl:when test="$/sect5">6</xsl:when>
237        <xsl:when test="$/section">
238          <xsl:choose>
239            <xsl:when test="$/section">6</xsl:when>
240            <xsl:when test="$/section">5</xsl:when>
241            <xsl:when test="$/section">4</xsl:when>
242            <xsl:otherwise>3</xsl:otherwise>
243          </xsl:choose>
244        </xsl:when>
245        <xsl:otherwise>2</xsl:otherwise>
246      </xsl:choose>
247    </xsl:when>
248    <xsl:otherwise>2</xsl:otherwise>
249  </xsl:choose>
250</xsl:template><!-- section.level -->
251
252<doc:template name="qanda.section.level" xmlns="">
253<refpurpose>Returns the hierarchical level of a QandASet.</refpurpose>
254
255<refdescription>
256<para>This template calculates the hierarchical level of a QandASet.
257</para>
258</refdescription>
259
260<refreturn>
261<para>The level, <quote>1</quote>, <quote>2</quote>, etc.
262</para>
263</refreturn>
264</doc:template>
265
266<xsl:template name="qanda.section.level">
267  <xsl:variable name="section"
268                select="(ancestor::section
269                         |ancestor::simplesect
270                         |ancestor::sect5
271                         |ancestor::sect4
272                         |ancestor::sect3
273                         |ancestor::sect2
274                         |ancestor::sect1
275                         |ancestor::refsect3
276                         |ancestor::refsect2
277                         |ancestor::refsect1)[last()]"/>
278  <xsl:choose>
279    <xsl:when test="count($section) = '0'">1</xsl:when>
280    <xsl:otherwise>
281      <xsl:call-template name="section.level">
282        <xsl:with-param name="node" select="$section"/>
283      </xsl:call-template>
284    </xsl:otherwise>
285  </xsl:choose>
286</xsl:template>
287
288<xsl:template name="qandadiv.section.level">
289  <xsl:variable name="section.level">
290    <xsl:call-template name="qanda.section.level"/>
291  </xsl:variable>
292  <xsl:variable name="anc.divs" select="ancestor::qandadiv"/>
293
294  <xsl:value-of select="count($anc.divs) + number($section.level)"/>
295</xsl:template>
296
297<xsl:template name="question.answer.label">
298  <xsl:variable name="deflabel">
299    <xsl:choose>
300      <xsl:when test="ancestor-or-self::*[@defaultlabel]">
301        <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
302                              /@defaultlabel"/>
303      </xsl:when>
304      <xsl:otherwise>
305        <xsl:value-of select="qanda.defaultlabel"/>
306      </xsl:otherwise>
307    </xsl:choose>
308  </xsl:variable>
309
310  <xsl:variable name="label" select="@label"/>
311
312<!--
313	 (hnr      (hierarchical-number-recursive (normalize "qandadiv")
314						  node))
315
316	 (parsect  (ancestor-member node (section-element-list)))
317
318	 (defnum   (if (and %qanda-inherit-numeration% 
319			    %section-autolabel%)
320		       (if (node-list-empty? parsect)
321			   (section-autolabel-prefix node)
322			   (section-autolabel parsect))
323		       ""))
324
325	 (hnumber  (let loop ((numlist hnr) (number defnum) 
326			      (sep (if (equal? defnum "") "" ".")))
327		     (if (null? numlist)
328			 number
329			 (loop (cdr numlist) 
330			       (string-append number
331					      sep
332					      (number->string (car numlist)))
333			       "."))))
334	 (cnumber  (child-number (parent node)))
335	 (number   (string-append hnumber 
336				  (if (equal? hnumber "")
337				      ""
338				      ".")
339				  (number->string cnumber))))
340-->
341
342  <xsl:choose>
343    <xsl:when test="$deflabel = 'qanda'">
344      <xsl:call-template name="gentext">
345        <xsl:with-param name="key">
346          <xsl:choose>
347            <xsl:when test="local-name(.) = 'question'">Question</xsl:when>
348            <xsl:when test="local-name(.) = 'question'">Answer</xsl:when>
349            <xsl:when test="local-name(.) = 'qandadiv'">QandADiv</xsl:when>
350            <xsl:otherwise>QandASet</xsl:otherwise>
351          </xsl:choose>
352        </xsl:with-param>
353      </xsl:call-template>
354    </xsl:when>
355    <xsl:when test="$deflabel = 'label'">
356      <xsl:value-of select="$label"/>
357    </xsl:when>
358    <xsl:when test="$deflabel = 'number'
359                    and local-name(.) = 'question'">
360      <xsl:apply-templates select="ancestor::qandaset[1]"
361                           mode="number"/>
362      <xsl:choose>
363        <xsl:when test="ancestor::qandadiv">
364          <xsl:apply-templates select="ancestor::qandadiv[1]"
365                               mode="number"/>
366          <xsl:apply-templates select="ancestor::qandaentry"
367                               mode="number"/>
368        </xsl:when>
369        <xsl:otherwise>
370          <xsl:apply-templates select="ancestor::qandaentry"
371                               mode="number"/>
372        </xsl:otherwise>
373      </xsl:choose>
374    </xsl:when>
375    <xsl:otherwise>
376      <!-- nothing -->
377    </xsl:otherwise>
378  </xsl:choose>
379</xsl:template>
380
381<xsl:template match="qandaset" mode="number">
382  <!-- FIXME: -->
383</xsl:template>
384
385<xsl:template match="qandadiv" mode="number">
386  <xsl:number level="multiple" from="qandaset" format="1."/>
387</xsl:template>
388
389<xsl:template match="qandaentry" mode="number">
390  <xsl:choose>
391    <xsl:when test="ancestor::qandadiv">
392      <xsl:number level="single" from="qandadiv" format="1."/>
393    </xsl:when>
394    <xsl:otherwise>
395      <xsl:number level="single" from="qandaset" format="1."/>
396    </xsl:otherwise>
397  </xsl:choose>
398</xsl:template>
399
400<!-- ====================================================================== -->
401
402<xsl:template name="object.id">
403  <xsl:param name="object" select="."/>
404  <xsl:choose>
405    <xsl:when test="$object/@id">
406      <xsl:value-of select="$object/@id"/>
407    </xsl:when>
408    <xsl:otherwise>
409      <xsl:value-of select="generate-id($object)"/>
410    </xsl:otherwise>
411  </xsl:choose>
412</xsl:template>
413
414<xsl:template name="person.name">
415  <!-- Return a formatted string representation of the contents of
416       the specified node (by default, the current element).
417       Handles Honorific, FirstName, SurName, and Lineage.
418       If %author-othername-in-middle% is #t, also OtherName
419       Handles *only* the first of each.
420       Format is "Honorific. FirstName [OtherName] SurName, Lineage"
421  -->
422  <xsl:param name="node" select="."/>
423
424  <xsl:choose>
425    <!-- handle corpauthor as a special case...-->
426    <xsl:when test="name($node)='corpauthor'">
427      <xsl:apply-templates select="$node"/>
428    </xsl:when>
429    <xsl:otherwise>
430      <xsl:variable name="h_nl" select="$node//honorific[1]"/>
431      <xsl:variable name="f_nl" select="$node//firstname[1]"/>
432      <xsl:variable name="o_nl" select="$node//othername[1]"/>
433      <xsl:variable name="s_nl" select="$node//surname[1]"/>
434      <xsl:variable name="l_nl" select="$node//lineage[1]"/>
435
436      <xsl:variable name="has_h" select="$h_nl"/>
437      <xsl:variable name="has_f" select="$f_nl"/>
438      <xsl:variable name="has_o"
439                    select="$o_nl and ($author.othername.in.middle != 0)"/>
440      <xsl:variable name="has_s" select="$s_nl"/>
441      <xsl:variable name="has_l" select="$l_nl"/>
442
443      <xsl:if test="$has_h">
444        <xsl:value-of select="$h_nl"/>.
445      </xsl:if>
446
447      <xsl:if test="$has_f">
448        <xsl:if test="$has_h"><xsl:text> </xsl:text></xsl:if>
449        <xsl:value-of select="$f_nl"/>
450      </xsl:if>
451
452      <xsl:if test="$has_o">
453        <xsl:if test="$has_h or $has_f"><xsl:text> </xsl:text></xsl:if>
454        <xsl:value-of select="$o_nl"/>
455      </xsl:if>
456
457      <xsl:if test="$has_s">
458        <xsl:if test="$has_h or $has_f or $has_o">
459          <xsl:text> </xsl:text>
460        </xsl:if>
461        <xsl:value-of select="$s_nl"/>
462      </xsl:if>
463
464      <xsl:if test="$has_l">
465        <xsl:text>, </xsl:text>
466        <xsl:value-of select="$l_nl"/>
467      </xsl:if>
468    </xsl:otherwise>
469  </xsl:choose>
470</xsl:template> <!-- person.name -->
471
472<xsl:template name="person.name.list">
473  <!-- Return a formatted string representation of the contents of
474       the current element. The current element must contain one or
475       more AUTHORs, CORPAUTHORs, OTHERCREDITs, and/or EDITORs.
476
477       John Doe
478     or
479       John Doe and Jane Doe
480     or
481       John Doe, Jane Doe, and A. Nonymous
482  -->
483  <xsl:param name="person.list"
484             select="/author|/corpauthor|/othercredit|/editor"/>
485  <xsl:param name="person.count" select="count($person.list)"/>
486  <xsl:param name="count" select="1"/>
487
488  <xsl:choose>
489    <xsl:when test="$count &gt; $person.count"></xsl:when>
490    <xsl:otherwise>
491      <xsl:call-template name="person.name">
492        <xsl:with-param name="node" select="$person.list[position()=$count]"/>
493      </xsl:call-template>
494
495      <xsl:choose>
496        <xsl:when test="$person.count = 2 and $count = 1">
497          <xsl:call-template name="gentext.template">
498            <xsl:with-param name="context" select="'authorgroup'"/>
499            <xsl:with-param name="name" select="'sep2'"/>
500          </xsl:call-template>
501        </xsl:when>
502        <xsl:when test="$person.count &gt; 2 and $count+1 = $person.count">
503          <xsl:call-template name="gentext.template">
504            <xsl:with-param name="context" select="'authorgroup'"/>
505            <xsl:with-param name="name" select="'seplast'"/>
506          </xsl:call-template>
507        </xsl:when>
508        <xsl:when test="$count &lt; $person.count">
509          <xsl:call-template name="gentext.template">
510            <xsl:with-param name="context" select="'authorgroup'"/>
511            <xsl:with-param name="name" select="'sep'"/>
512          </xsl:call-template>
513        </xsl:when>
514      </xsl:choose>
515
516      <xsl:call-template name="person.name.list">
517        <xsl:with-param name="person.list" select="$person.list"/>
518        <xsl:with-param name="person.count" select="$person.count"/>
519        <xsl:with-param name="count" select="$count+1"/>
520      </xsl:call-template>
521    </xsl:otherwise>
522  </xsl:choose>
523</xsl:template><!-- person.name.list -->
524
525<!-- === synopsis ======================================================= -->
526<!-- The following definitions match those given in the reference
527     documentation for DocBook V3.0
528-->
529
530<xsl:variable name="arg.choice.opt.open.str">[</xsl:variable>
531<xsl:variable name="arg.choice.opt.close.str">]</xsl:variable>
532<xsl:variable name="arg.choice.req.open.str">{</xsl:variable>
533<xsl:variable name="arg.choice.req.close.str">}</xsl:variable>
534<xsl:variable name="arg.choice.plain.open.str"><xsl:text> </xsl:text></xsl:variable>
535<xsl:variable name="arg.choice.plain.close.str"><xsl:text> </xsl:text></xsl:variable>
536<xsl:variable name="arg.choice.def.open.str">[</xsl:variable>
537<xsl:variable name="arg.choice.def.close.str">]</xsl:variable>
538<xsl:variable name="arg.rep.repeat.str">...</xsl:variable>
539<xsl:variable name="arg.rep.norepeat.str"></xsl:variable>
540<xsl:variable name="arg.rep.def.str"></xsl:variable>
541<xsl:variable name="arg.or.sep"> | </xsl:variable>
542<xsl:variable name="cmdsynopsis.hanging.indent">4pi</xsl:variable>
543
544<!-- ====================================================================== -->
545
546<!--
547<xsl:template name="xref.g.subst">
548  <xsl:param name="string"></xsl:param>
549  <xsl:param name="target" select="."/>
550  <xsl:variable name="subst">%g</xsl:variable>
551
552  <xsl:choose>
553    <xsl:when test="contains($string, $subst)">
554      <xsl:value-of select="substring-before($string, $subst)"/>
555      <xsl:call-template name="gentext.element.name">
556        <xsl:with-param name="element.name" select="name($target)"/>
557      </xsl:call-template>
558      <xsl:call-template name="xref.g.subst">
559        <xsl:with-param name="string"
560                        select="substring-after($string, $subst)"/>
561        <xsl:with-param name="target" select="$target"/>
562      </xsl:call-template>
563    </xsl:when>
564    <xsl:otherwise>
565      <xsl:value-of select="$string"/>
566    </xsl:otherwise>
567  </xsl:choose>
568</xsl:template>
569
570<xsl:template name="xref.t.subst">
571  <xsl:param name="string"></xsl:param>
572  <xsl:param name="target" select="."/>
573  <xsl:variable name="subst">%t</xsl:variable>
574
575  <xsl:choose>
576    <xsl:when test="contains($string, $subst)">
577      <xsl:call-template name="xref.g.subst">
578        <xsl:with-param name="string"
579                        select="substring-before($string, $subst)"/>
580        <xsl:with-param name="target" select="$target"/>
581      </xsl:call-template>
582      <xsl:call-template name="title.xref">
583        <xsl:with-param name="target" select="$target"/>
584      </xsl:call-template>
585      <xsl:call-template name="xref.t.subst">
586        <xsl:with-param name="string"
587                        select="substring-after($string, $subst)"/>
588        <xsl:with-param name="target" select="$target"/>
589      </xsl:call-template>
590    </xsl:when>
591    <xsl:otherwise>
592      <xsl:call-template name="xref.g.subst">
593        <xsl:with-param name="string" select="$string"/>
594        <xsl:with-param name="target" select="$target"/>
595      </xsl:call-template>
596    </xsl:otherwise>
597  </xsl:choose>
598</xsl:template>
599
600<xsl:template name="xref.n.subst">
601  <xsl:param name="string"></xsl:param>
602  <xsl:param name="target" select="."/>
603  <xsl:variable name="subst">%n</xsl:variable>
604
605  <xsl:choose>
606    <xsl:when test="contains($string, $subst)">
607      <xsl:call-template name="xref.t.subst">
608        <xsl:with-param name="string"
609                        select="substring-before($string, $subst)"/>
610        <xsl:with-param name="target" select="$target"/>
611      </xsl:call-template>
612      <xsl:call-template name="number.xref">
613        <xsl:with-param name="target" select="$target"/>
614      </xsl:call-template>
615      <xsl:call-template name="xref.t.subst">
616        <xsl:with-param name="string"
617                        select="substring-after($string, $subst)"/>
618        <xsl:with-param name="target" select="$target"/>
619      </xsl:call-template>
620    </xsl:when>
621    <xsl:otherwise>
622      <xsl:call-template name="xref.t.subst">
623        <xsl:with-param name="string" select="$string"/>
624        <xsl:with-param name="target" select="$target"/>
625      </xsl:call-template>
626    </xsl:otherwise>
627  </xsl:choose>
628</xsl:template>
629
630<xsl:template name="subst.xref.text">
631  <xsl:param name="xref.text"></xsl:param>
632  <xsl:param name="target" select="."/>
633
634  <xsl:call-template name="xref.n.subst">
635    <xsl:with-param name="string" select="$xref.text"/>
636    <xsl:with-param name="target" select="$target"/>
637  </xsl:call-template>
638</xsl:template>
639-->
640
641<!-- ====================================================================== -->
642
643<xsl:template name="filename-basename">
644  <!-- We assume all filenames are really URIs and use "/" -->
645  <xsl:param name="filename"></xsl:param>
646  <xsl:param name="recurse" select="false()"/>
647
648  <xsl:choose>
649    <xsl:when test="substring-after($filename, '/') != ''">
650      <xsl:call-template name="filename-basename">
651        <xsl:with-param name="filename"
652                        select="substring-after($filename, '/')"/>
653        <xsl:with-param name="recurse" select="true()"/>
654      </xsl:call-template>
655    </xsl:when>
656    <xsl:otherwise>
657      <xsl:value-of select="$filename"/>
658    </xsl:otherwise>
659  </xsl:choose>
660</xsl:template>
661
662<xsl:template name="filename-extension">
663  <xsl:param name="filename"></xsl:param>
664  <xsl:param name="recurse" select="false()"/>
665
666  <!-- Make sure we only look at the base name... -->
667  <xsl:variable name="basefn">
668    <xsl:choose>
669      <xsl:when test="$recurse">
670        <xsl:value-of select="$filename"/>
671      </xsl:when>
672      <xsl:otherwise>
673        <xsl:call-template name="filename-basename">
674          <xsl:with-param name="filename" select="$filename"/>
675        </xsl:call-template>
676      </xsl:otherwise>
677    </xsl:choose>
678  </xsl:variable>
679
680  <xsl:choose>
681    <xsl:when test="substring-after($basefn, '.') != ''">
682      <xsl:call-template name="filename-extension">
683        <xsl:with-param name="filename"
684                        select="substring-after($basefn, '.')"/>
685        <xsl:with-param name="recurse" select="true()"/>
686      </xsl:call-template>
687    </xsl:when>
688    <xsl:when test="$recurse">
689      <xsl:value-of select="$basefn"/>
690    </xsl:when>
691    <xsl:otherwise></xsl:otherwise>
692  </xsl:choose>
693</xsl:template>
694
695<!-- ====================================================================== -->
696
697<doc:template name="select.mediaobject" xmlns="">
698<refpurpose>Selects an appropriate media object from a list</refpurpose>
699
700<refdescription>
701<para>This template examines a list of media objects (usually the
702children of a mediaobject or inlinemediaobject) and processes
703the "right" object.</para>
704
705<para>This template relies on a template named "is.acceptable.mediaobject"
706to determine if a given object is an acceptable graphic. The semantics
707of media objects is that the first acceptable graphic should be used.
708</para>
709
710<para>If no acceptable object is located, nothing happens.</para>
711</refdescription>
712
713<refparameter>
714<variablelist>
715<varlistentry><term>olist</term>
716<listitem>
717<para>The node list of potential objects to examine.</para>
718</listitem>
719</varlistentry>
720</variablelist>
721</refparameter>
722
723<refreturn>
724<para>Calls &lt;xsl:apply-templates&gt; on the selected object.</para>
725</refreturn>
726</doc:template>
727
728<xsl:template name="select.mediaobject">
729  <xsl:param name="olist"
730             select="imageobject|imageobjectco
731                     |videoobject|audioobject|textobject"/>
732  <xsl:param name="count">1</xsl:param>
733
734  <xsl:if test="$count &lt;= count($olist)">
735    <xsl:variable name="object" select="$olist[position()=$count]"/>
736
737    <xsl:variable name="useobject">
738      <xsl:choose>
739	<!-- The phrase is never used -->
740        <xsl:when test="name($object)='textobject' and $object/phrase">
741          <xsl:text>0</xsl:text>
742        </xsl:when>
743	<!-- The first textobject is a reasonable fallback -->
744        <xsl:when test="name($object)='textobject'">
745          <xsl:text>1</xsl:text>
746        </xsl:when>
747	<!-- If there's only one object, use it -->
748	<xsl:when test="$count = 1 and count($olist) = 1">
749	  <xsl:text>1</xsl:text>
750	</xsl:when>
751	<!-- Otherwise, see if this one is a useable graphic -->
752        <xsl:otherwise>
753          <xsl:choose>
754            <!-- peek inside imageobjectco to simplify the test -->
755            <xsl:when test="local-name($object) = 'imageobjectco'">
756              <xsl:call-template name="is.acceptable.mediaobject">
757                <xsl:with-param name="object" select="$object/imageobject"/>
758              </xsl:call-template>
759            </xsl:when>
760            <xsl:otherwise>
761              <xsl:call-template name="is.acceptable.mediaobject">
762                <xsl:with-param name="object" select="$object"/>
763              </xsl:call-template>
764            </xsl:otherwise>
765          </xsl:choose>
766        </xsl:otherwise>
767      </xsl:choose>
768    </xsl:variable>
769
770    <xsl:choose>
771      <xsl:when test="$useobject='1'">
772        <xsl:apply-templates select="$object"/>
773      </xsl:when>
774      <xsl:otherwise>
775        <xsl:call-template name="select.mediaobject">
776          <xsl:with-param name="olist" select="$olist"/>
777          <xsl:with-param name="count" select="$count + 1"/>
778        </xsl:call-template>
779      </xsl:otherwise>
780    </xsl:choose>
781  </xsl:if>
782</xsl:template>
783
784<doc:template name="is.acceptable.mediaobject" xmlns="">
785<refpurpose>Returns '1' if the specified media object is recognized.</refpurpose>
786
787<refdescription>
788<para>This template examines a media object and returns '1' if the
789object is recognized as a graphic.</para>
790</refdescription>
791
792<refparameter>
793<variablelist>
794<varlistentry><term>object</term>
795<listitem>
796<para>The media object to consider.</para>
797</listitem>
798</varlistentry>
799</variablelist>
800</refparameter>
801
802<refreturn>
803<para>0 or 1</para>
804</refreturn>
805</doc:template>
806
807<xsl:template name="is.acceptable.mediaobject">
808  <xsl:param name="object"></xsl:param>
809
810  <xsl:variable name="filename">
811    <xsl:call-template name="mediaobject.filename">
812      <xsl:with-param name="object" select="$object"/>
813    </xsl:call-template>
814  </xsl:variable>
815
816  <xsl:variable name="ext">
817    <xsl:call-template name="filename-extension">
818      <xsl:with-param name="filename" select="$filename"/>
819    </xsl:call-template>
820  </xsl:variable>
821
822  <!-- there will only be one -->
823  <xsl:variable name="data" select="$object/videodata
824                                    |$object/imagedata
825                                    |$object/audiodata"/>
826
827  <xsl:variable name="format" select="$data/@format"/>
828
829  <xsl:variable name="graphic.format">
830    <xsl:if test="$format">
831      <xsl:call-template name="is.graphic.format">
832        <xsl:with-param name="format" select="$format"/>
833      </xsl:call-template>
834    </xsl:if>
835  </xsl:variable>
836
837  <xsl:variable name="graphic.ext">
838    <xsl:if test="$ext">
839      <xsl:call-template name="is.graphic.extension">
840        <xsl:with-param name="ext" select="$ext"/>
841      </xsl:call-template>
842    </xsl:if>
843  </xsl:variable>
844
845  <xsl:choose>
846    <xsl:when test="$graphic.format = '1'">1</xsl:when>
847    <xsl:when test="$graphic.ext = '1'">1</xsl:when>
848    <xsl:otherwise>0</xsl:otherwise>
849  </xsl:choose>
850</xsl:template>
851
852<xsl:template name="mediaobject.filename">
853  <xsl:param name="object"></xsl:param>
854
855  <xsl:variable name="data" select="$object/videodata
856                                    |$object/imagedata
857                                    |$object/audiodata"/>
858
859  <xsl:variable name="filename">
860    <xsl:choose>
861      <xsl:when test="$data[@fileref]">
862        <xsl:value-of select="$data/@fileref"/>
863      </xsl:when>
864      <xsl:when test="$data[@entityref]">
865        <xsl:value-of select="unparsed-entity-uri($data/@entityref)"/>
866      </xsl:when>
867      <xsl:otherwise></xsl:otherwise>
868    </xsl:choose>
869  </xsl:variable>
870
871  <xsl:variable name="has.ext" select="contains($filename, '.') != ''"/>
872
873  <xsl:variable name="ext">
874    <xsl:choose>
875      <xsl:when test="contains($filename, '.')">
876        <xsl:call-template name="filename-extension">
877          <xsl:with-param name="filename" select="$filename"/>
878        </xsl:call-template>
879      </xsl:when>
880      <xsl:otherwise>
881        <xsl:value-of select="$graphic.default.extension"/>
882      </xsl:otherwise>
883    </xsl:choose>
884  </xsl:variable>
885
886  <xsl:variable name="graphic.ext">
887    <xsl:call-template name="is.graphic.extension">
888      <xsl:with-param name="ext" select="$ext"/>
889    </xsl:call-template>
890  </xsl:variable>
891
892  <xsl:choose>
893    <xsl:when test="not($has.ext)">
894      <xsl:choose>
895        <xsl:when test="$ext != ''">
896          <xsl:value-of select="$filename"/>
897          <xsl:text>.</xsl:text>
898          <xsl:value-of select="$ext"/>
899        </xsl:when>
900        <xsl:otherwise>
901          <xsl:value-of select="$filename"/>
902        </xsl:otherwise>
903      </xsl:choose>
904    </xsl:when>
905    <xsl:when test="not($graphic.ext)">
906      <xsl:choose>
907        <xsl:when test="$graphic.default.extension != ''">
908          <xsl:value-of select="$filename"/>
909          <xsl:text>.</xsl:text>
910          <xsl:value-of select="$graphic.default.extension"/>
911        </xsl:when>
912        <xsl:otherwise>
913          <xsl:value-of select="$filename"/>
914        </xsl:otherwise>
915      </xsl:choose>
916    </xsl:when>
917    <xsl:otherwise>
918      <xsl:value-of select="$filename"/>
919    </xsl:otherwise>
920  </xsl:choose>
921</xsl:template>
922
923<!-- ====================================================================== -->
924
925<doc:template name="check.id.unique" xmlns="">
926<refpurpose>Warn users about references to non-unique IDs</refpurpose>
927<refdescription>
928<para>If passed an ID in <varname>linkend</varname>,
929<function>check.id.unique</function> prints
930a warning message to the user if either the ID does not exist or
931the ID is not unique.</para>
932</refdescription>
933</doc:template>
934
935<xsl:template name="check.id.unique">
936  <xsl:param name="linkend"></xsl:param>
937  <xsl:if test="$linkend != ''">
938    <xsl:variable name="targets" select="id($linkend)"/>
939    <xsl:variable name="target" select="$targets[1]"/>
940
941    <xsl:if test="count($targets)=0">
942      <xsl:message>
943	<xsl:text>Error: no ID for constraint linkend: </xsl:text>
944	<xsl:value-of select="$linkend"/>
945	<xsl:text>.</xsl:text>
946      </xsl:message>
947      <!--
948      <xsl:message>
949	<xsl:text>If the ID exists in your document, did your </xsl:text>
950        <xsl:text>XSLT Processor load the DTD?</xsl:text>
951      </xsl:message>
952      -->
953    </xsl:if>
954
955    <xsl:if test="count($targets)>1">
956      <xsl:message>
957	<xsl:text>Warning: multiple "IDs" for constraint linkend: </xsl:text>
958	<xsl:value-of select="$linkend"/>
959	<xsl:text>.</xsl:text>
960      </xsl:message>
961    </xsl:if>
962  </xsl:if>
963</xsl:template>
964
965<doc:template name="check.idref.targets" xmlns="">
966<refpurpose>Warn users about incorrectly typed references</refpurpose>
967<refdescription>
968<para>If passed an ID in <varname>linkend</varname>,
969<function>check.idref.targets</function> makes sure that the element
970pointed to by the link is one of the elements listed in
971<varname>element-list</varname> and warns the user otherwise.</para>
972</refdescription>
973</doc:template>
974
975<xsl:template name="check.idref.targets">
976  <xsl:param name="linkend"></xsl:param>
977  <xsl:param name="element-list"></xsl:param>
978  <xsl:if test="$linkend != ''">
979    <xsl:variable name="targets" select="id($linkend)"/>
980    <xsl:variable name="target" select="$targets[1]"/>
981
982    <xsl:if test="count($target) &gt; 0">
983      <xsl:if test="not(contains(concat(' ', $element-list, ' '), name($target)))">
984	<xsl:message>
985	  <xsl:text>Error: linkend (</xsl:text>
986	  <xsl:value-of select="$linkend"/>
987	  <xsl:text>) points to "</xsl:text>
988	  <xsl:value-of select="name($target)"/>
989	  <xsl:text>" not (one of): </xsl:text>
990	  <xsl:value-of select="$element-list"/>
991	</xsl:message>
992      </xsl:if>
993    </xsl:if>
994  </xsl:if>
995</xsl:template>
996
997<!-- ====================================================================== -->
998
999</xsl:stylesheet>
1000
1001