~zulcss/samba/server-dailies-3.4

« back to all changes in this revision

Viewing changes to docs-xml/xslt/db2latex-xsl/xsl/common/common.xsl

  • Committer: Chuck Short
  • Date: 2010-09-28 20:38:39 UTC
  • Revision ID: zulcss@ubuntu.com-20100928203839-pgjulytsi9ue63x1
Initial version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.6 2004/01/04 09:25:06 j-devenish Exp $
 
9
     ********************************************************************
 
10
 
 
11
     This file is part of the XSL DocBook Stylesheet distribution.
 
12
 
 
13
     Copyright (C) 1999, 2000, 2001, 2002 Norman Walsh.
 
14
     ******************************************************************** -->
 
15
 
 
16
<doc:reference xmlns="">
 
17
<referenceinfo>
 
18
<releaseinfo role="meta">
 
19
$Id: common.xsl,v 1.6 2004/01/04 09:25:06 j-devenish Exp $
 
20
</releaseinfo>
 
21
<author><surname>Walsh</surname>
 
22
<firstname>Norman</firstname></author>
 
23
<copyright><year>1999</year><year>2000</year>
 
24
<holder>Norman Walsh</holder>
 
25
</copyright>
 
26
</referenceinfo>
 
27
<title>Common Template Reference</title>
 
28
 
 
29
<partintro>
 
30
<section><title>Introduction</title>
 
31
 
 
32
<para>This is technical reference documentation for the DocBook XSL
 
33
Stylesheets; it documents (some of) the parameters, templates, and
 
34
other elements of the stylesheets.</para>
 
35
 
 
36
<para>This is not intended to be <quote>user</quote> documentation.
 
37
It is provided for developers writing customization layers for the
 
38
stylesheets, and for anyone who's interested in <quote>how it
 
39
works</quote>.</para>
 
40
 
 
41
<para>Although I am trying to be thorough, this documentation is known
 
42
to be incomplete. Don't forget to read the source, too :-)</para>
 
43
</section>
 
44
</partintro>
 
45
 
 
46
</doc:reference>
 
47
 
 
48
<!-- ==================================================================== -->
 
49
<!-- Establish strip/preserve whitespace rules -->
 
50
 
 
51
<xsl:preserve-space elements="*"/>
 
52
 
 
53
<xsl:strip-space elements="
 
54
abstract affiliation anchor answer appendix area areaset areaspec
 
55
artheader article audiodata audioobject author authorblurb authorgroup
 
56
beginpage bibliodiv biblioentry bibliography biblioset blockquote book
 
57
bookbiblio bookinfo callout calloutlist caption caution chapter
 
58
citerefentry cmdsynopsis co collab colophon colspec confgroup
 
59
copyright dedication docinfo editor entry entrytbl epigraph equation
 
60
example figure footnote footnoteref formalpara funcprototype
 
61
funcsynopsis glossary glossdef glossdiv glossentry glosslist graphicco
 
62
group highlights imagedata imageobject imageobjectco important index
 
63
indexdiv indexentry indexterm informalequation informalexample
 
64
informalfigure informaltable inlineequation inlinemediaobject
 
65
itemizedlist itermset keycombo keywordset legalnotice listitem lot
 
66
mediaobject mediaobjectco menuchoice msg msgentry msgexplan msginfo
 
67
msgmain msgrel msgset msgsub msgtext note objectinfo
 
68
orderedlist othercredit part partintro preface printhistory procedure
 
69
programlistingco publisher qandadiv qandaentry qandaset question
 
70
refentry reference refmeta refnamediv refsect1 refsect1info refsect2
 
71
refsect2info refsect3 refsect3info refsynopsisdiv refsynopsisdivinfo
 
72
revhistory revision row sbr screenco screenshot sect1 sect1info sect2
 
73
sect2info sect3 sect3info sect4 sect4info sect5 sect5info section
 
74
sectioninfo seglistitem segmentedlist seriesinfo set setindex setinfo
 
75
shortcut sidebar simplelist simplesect spanspec step subject
 
76
subjectset substeps synopfragment table tbody textobject tfoot tgroup
 
77
thead tip toc tocchap toclevel1 toclevel2 toclevel3 toclevel4
 
78
toclevel5 tocpart varargs variablelist varlistentry videodata
 
79
videoobject void warning subjectset
 
80
 
 
81
classsynopsis
 
82
constructorsynopsis
 
83
destructorsynopsis
 
84
fieldsynopsis
 
85
methodparam
 
86
methodsynopsis
 
87
ooclass
 
88
ooexception
 
89
oointerface
 
90
simplemsgentry
 
91
"/>
 
92
 
 
93
<!-- ====================================================================== -->
 
94
 
 
95
<doc:template name="is.component" xmlns="">
 
96
<refpurpose>Tests if a given node is a component-level element</refpurpose>
 
97
 
 
98
<refdescription>
 
99
<para>This template returns '1' if the specified node is a component
 
100
(Chapter, Appendix, etc.), and '0' otherwise.</para>
 
101
</refdescription>
 
102
 
 
103
<refparameter>
 
104
<variablelist>
 
105
<varlistentry><term>node</term>
 
106
<listitem>
 
107
<para>The node which is to be tested.</para>
 
108
</listitem>
 
109
</varlistentry>
 
110
</variablelist>
 
111
</refparameter>
 
112
 
 
113
<refreturn>
 
114
<para>This template returns '1' if the specified node is a component
 
115
(Chapter, Appendix, etc.), and '0' otherwise.</para>
 
116
</refreturn>
 
117
</doc:template>
 
118
 
 
119
<xsl:template name="is.component">
 
120
  <xsl:param name="node" select="."/>
 
121
  <xsl:choose>
 
122
    <xsl:when test="local-name($node) = 'appendix'
 
123
                    or local-name($node) = 'article'
 
124
                    or local-name($node) = 'chapter'
 
125
                    or local-name($node) = 'preface'
 
126
                    or local-name($node) = 'bibliography'
 
127
                    or local-name($node) = 'glossary'
 
128
                    or local-name($node) = 'index'">1</xsl:when>
 
129
    <xsl:otherwise>0</xsl:otherwise>
 
130
  </xsl:choose>
 
131
</xsl:template>
 
132
 
 
133
<!-- ====================================================================== -->
 
134
 
 
135
<doc:template name="is.section" xmlns="">
 
136
<refpurpose>Tests if a given node is a section-level element</refpurpose>
 
137
 
 
138
<refdescription>
 
139
<para>This template returns '1' if the specified node is a section
 
140
(Section, Sect1, Sect2, etc.), and '0' otherwise.</para>
 
141
</refdescription>
 
142
 
 
143
<refparameter>
 
144
<variablelist>
 
145
<varlistentry><term>node</term>
 
146
<listitem>
 
147
<para>The node which is to be tested.</para>
 
148
</listitem>
 
149
</varlistentry>
 
150
</variablelist>
 
151
</refparameter>
 
152
 
 
153
<refreturn>
 
154
<para>This template returns '1' if the specified node is a section
 
155
(Section, Sect1, Sect2, etc.), and '0' otherwise.</para>
 
156
</refreturn>
 
157
</doc:template>
 
158
 
 
159
<xsl:template name="is.section">
 
160
  <xsl:param name="node" select="."/>
 
161
  <xsl:choose>
 
162
    <xsl:when test="local-name($node) = 'section'
 
163
                    or local-name($node) = 'sect1'
 
164
                    or local-name($node) = 'sect2'
 
165
                    or local-name($node) = 'sect3'
 
166
                    or local-name($node) = 'sect4'
 
167
                    or local-name($node) = 'sect5'
 
168
                    or local-name($node) = 'refsect1'
 
169
                    or local-name($node) = 'refsect2'
 
170
                    or local-name($node) = 'refsect3'
 
171
                    or local-name($node) = 'simplesect'">1</xsl:when>
 
172
    <xsl:otherwise>0</xsl:otherwise>
 
173
  </xsl:choose>
 
174
</xsl:template>
 
175
 
 
176
<!-- ====================================================================== -->
 
177
 
 
178
<doc:template name="section.level" xmlns="">
 
179
<refpurpose>Returns the hierarchical level of a section.</refpurpose>
 
180
 
 
181
<refdescription>
 
182
<para>This template calculates the hierarchical level of a section.
 
183
The element <sgmltag>sect1</sgmltag> is at level 1, <sgmltag>sect2</sgmltag> is
 
184
at level 2, etc.</para>
 
185
 
 
186
<para>Recursive sections are calculated down to the fifth level.</para>
 
187
</refdescription>
 
188
 
 
189
<refparameter>
 
190
<variablelist>
 
191
<varlistentry><term>node</term>
 
192
<listitem>
 
193
<para>The section node for which the level should be calculated.
 
194
Defaults to the context node.</para>
 
195
</listitem>
 
196
</varlistentry>
 
197
</variablelist>
 
198
</refparameter>
 
199
 
 
200
<refreturn>
 
201
<para>The section level, <quote>1</quote>, <quote>2</quote>, etc.
 
202
</para>
 
203
</refreturn>
 
204
</doc:template>
 
205
 
 
206
<xsl:template name="section.level">
 
207
  <xsl:param name="node" select="."/>
 
208
  <xsl:choose>
 
209
    <xsl:when test="name($node)='sect1'">1</xsl:when>
 
210
    <xsl:when test="name($node)='sect2'">2</xsl:when>
 
211
    <xsl:when test="name($node)='sect3'">3</xsl:when>
 
212
    <xsl:when test="name($node)='sect4'">4</xsl:when>
 
213
    <xsl:when test="name($node)='sect5'">5</xsl:when>
 
214
    <xsl:when test="name($node)='section'">
 
215
      <xsl:choose>
 
216
        <xsl:when test="$node/../../../../../../section">6</xsl:when>
 
217
        <xsl:when test="$node/../../../../../section">5</xsl:when>
 
218
        <xsl:when test="$node/../../../../section">4</xsl:when>
 
219
        <xsl:when test="$node/../../../section">3</xsl:when>
 
220
        <xsl:when test="$node/../../section">2</xsl:when>
 
221
        <xsl:otherwise>1</xsl:otherwise>
 
222
      </xsl:choose>
 
223
    </xsl:when>
 
224
    <xsl:when test="name($node)='refsect1' or
 
225
                    name($node)='refsect2' or
 
226
                    name($node)='refsect3' or
 
227
                    name($node)='refsection' or
 
228
                    name($node)='refsynopsisdiv'">
 
229
      <xsl:call-template name="refentry.section.level">
 
230
        <xsl:with-param name="node" select="$node"/>
 
231
      </xsl:call-template>
 
232
    </xsl:when>
 
233
    <xsl:when test="name($node)='simplesect'">
 
234
      <xsl:choose>
 
235
        <xsl:when test="$node/../../sect1">2</xsl:when>
 
236
        <xsl:when test="$node/../../sect2">3</xsl:when>
 
237
        <xsl:when test="$node/../../sect3">4</xsl:when>
 
238
        <xsl:when test="$node/../../sect4">5</xsl:when>
 
239
        <xsl:when test="$node/../../sect5">5</xsl:when>
 
240
        <xsl:when test="$node/../../section">
 
241
          <xsl:choose>
 
242
            <xsl:when test="$node/../../../../../section">5</xsl:when>
 
243
            <xsl:when test="$node/../../../../section">4</xsl:when>
 
244
            <xsl:when test="$node/../../../section">3</xsl:when>
 
245
            <xsl:otherwise>2</xsl:otherwise>
 
246
          </xsl:choose>
 
247
        </xsl:when>
 
248
        <xsl:otherwise>1</xsl:otherwise>
 
249
      </xsl:choose>
 
250
    </xsl:when>
 
251
    <xsl:otherwise>1</xsl:otherwise>
 
252
  </xsl:choose>
 
253
</xsl:template><!-- section.level -->
 
254
 
 
255
<doc:template name="qanda.section.level" xmlns="">
 
256
<refpurpose>Returns the hierarchical level of a QandASet.</refpurpose>
 
257
 
 
258
<refdescription>
 
259
<para>This template calculates the hierarchical level of a QandASet.
 
260
</para>
 
261
</refdescription>
 
262
 
 
263
<refreturn>
 
264
<para>The level, <quote>1</quote>, <quote>2</quote>, etc.
 
265
</para>
 
266
</refreturn>
 
267
</doc:template>
 
268
 
 
269
<xsl:template name="qanda.section.level">
 
270
  <xsl:variable name="section"
 
271
                select="(ancestor::section
 
272
                         |ancestor::simplesect
 
273
                         |ancestor::sect5
 
274
                         |ancestor::sect4
 
275
                         |ancestor::sect3
 
276
                         |ancestor::sect2
 
277
                         |ancestor::sect1
 
278
                         |ancestor::refsect3
 
279
                         |ancestor::refsect2
 
280
                         |ancestor::refsect1)[last()]"/>
 
281
 
 
282
  <xsl:choose>
 
283
    <xsl:when test="count($section) = 0">1</xsl:when>
 
284
    <xsl:otherwise>
 
285
      <xsl:variable name="slevel">
 
286
        <xsl:call-template name="section.level">
 
287
          <xsl:with-param name="node" select="$section"/>
 
288
        </xsl:call-template>
 
289
      </xsl:variable>
 
290
      <xsl:value-of select="$slevel + 1"/>
 
291
    </xsl:otherwise>
 
292
  </xsl:choose>
 
293
</xsl:template>
 
294
 
 
295
<!-- Finds the total section depth of a section in a refentry -->
 
296
<xsl:template name="refentry.section.level">
 
297
  <xsl:param name="node" select="."/>
 
298
 
 
299
  <xsl:variable name="RElevel">
 
300
    <xsl:call-template name="refentry.level">
 
301
      <xsl:with-param name="node" select="$node/ancestor::refentry[1]"/>
 
302
    </xsl:call-template>
 
303
  </xsl:variable>
 
304
 
 
305
  <xsl:variable name="levelinRE">
 
306
    <xsl:choose>
 
307
      <xsl:when test="name($node)='refsynopsisdiv'">1</xsl:when>
 
308
      <xsl:when test="name($node)='refsect1'">1</xsl:when>
 
309
      <xsl:when test="name($node)='refsect2'">2</xsl:when>
 
310
      <xsl:when test="name($node)='refsect3'">3</xsl:when>
 
311
      <xsl:when test="name($node)='refsection'">
 
312
        <xsl:choose>
 
313
          <xsl:when test="$node/../../../../../refsection">5</xsl:when>
 
314
          <xsl:when test="$node/../../../../refsection">4</xsl:when>
 
315
          <xsl:when test="$node/../../../refsection">3</xsl:when>
 
316
          <xsl:when test="$node/../../refsection">2</xsl:when>
 
317
          <xsl:otherwise>1</xsl:otherwise>
 
318
        </xsl:choose>
 
319
      </xsl:when>
 
320
    </xsl:choose>
 
321
  </xsl:variable>
 
322
 
 
323
  <xsl:value-of select="$levelinRE + $RElevel"/>
 
324
</xsl:template>
 
325
 
 
326
<!-- Finds the section depth of a refentry -->
 
327
<xsl:template name="refentry.level">
 
328
  <xsl:param name="node" select="."/>
 
329
  <xsl:variable name="container"
 
330
                select="($node/ancestor::section |
 
331
                        $node/ancestor::sect1 |
 
332
                        $node/ancestor::sect2 |
 
333
                        $node/ancestor::sect3 |
 
334
                        $node/ancestor::sect4 |
 
335
                        $node/ancestor::sect5)[last()]"/>
 
336
 
 
337
  <xsl:choose>
 
338
    <xsl:when test="$container">
 
339
      <xsl:variable name="slevel">
 
340
        <xsl:call-template name="section.level">
 
341
          <xsl:with-param name="node" select="$container"/>
 
342
        </xsl:call-template>
 
343
      </xsl:variable>
 
344
      <xsl:value-of select="$slevel + 1"/>
 
345
    </xsl:when>
 
346
    <xsl:otherwise>1</xsl:otherwise>
 
347
  </xsl:choose>
 
348
</xsl:template>
 
349
 
 
350
<xsl:template name="qandadiv.section.level">
 
351
  <xsl:variable name="section.level">
 
352
    <xsl:call-template name="qanda.section.level"/>
 
353
  </xsl:variable>
 
354
  <xsl:variable name="anc.divs" select="ancestor::qandadiv"/>
 
355
 
 
356
  <xsl:value-of select="count($anc.divs) + number($section.level)"/>
 
357
</xsl:template>
 
358
 
 
359
 
 
360
<xsl:template match="qandaset" mode="number">
 
361
  <!-- FIXME: -->
 
362
</xsl:template>
 
363
 
 
364
<xsl:template match="qandadiv" mode="number">
 
365
  <xsl:number level="multiple" from="qandaset" format="1."/>
 
366
</xsl:template>
 
367
 
 
368
<xsl:template match="qandaentry" mode="number">
 
369
  <xsl:choose>
 
370
    <xsl:when test="ancestor::qandadiv">
 
371
      <xsl:number level="single" from="qandadiv" format="1."/>
 
372
    </xsl:when>
 
373
    <xsl:otherwise>
 
374
      <xsl:number level="single" from="qandaset" format="1."/>
 
375
    </xsl:otherwise>
 
376
  </xsl:choose>
 
377
</xsl:template>
 
378
 
 
379
<!-- ====================================================================== -->
 
380
 
 
381
<xsl:template name="object.id">
 
382
  <xsl:param name="object" select="."/>
 
383
  <xsl:choose>
 
384
    <xsl:when test="$object/@id">
 
385
      <xsl:value-of select="$object/@id"/>
 
386
    </xsl:when>
 
387
    <xsl:otherwise>
 
388
      <xsl:value-of select="generate-id($object)"/>
 
389
    </xsl:otherwise>
 
390
  </xsl:choose>
 
391
</xsl:template>
 
392
 
 
393
<xsl:template name="person.name">
 
394
  <!-- Formats a personal name. Handles corpauthor as a special case. -->
 
395
  <xsl:param name="node" select="."/>
 
396
 
 
397
  <xsl:variable name="style">
 
398
    <xsl:choose>
 
399
      <xsl:when test="$node/@role">
 
400
        <xsl:value-of select="$node/@role"/>
 
401
      </xsl:when>
 
402
      <xsl:otherwise>
 
403
        <xsl:call-template name="gentext.template">
 
404
          <xsl:with-param name="context" select="'styles'"/>
 
405
          <xsl:with-param name="name" select="'person-name'"/>
 
406
        </xsl:call-template>
 
407
      </xsl:otherwise>
 
408
    </xsl:choose>
 
409
  </xsl:variable>
 
410
 
 
411
  <xsl:choose>
 
412
    <!-- the personname element is a specialcase -->
 
413
    <xsl:when test="$node/personname">
 
414
      <xsl:call-template name="person.name">
 
415
        <xsl:with-param name="node" select="$node/personname"/>
 
416
      </xsl:call-template>
 
417
    </xsl:when>
 
418
 
 
419
    <!-- handle corpauthor as a special case...-->
 
420
    <xsl:when test="name($node)='corpauthor'">
 
421
      <xsl:apply-templates select="$node"/>
 
422
    </xsl:when>
 
423
 
 
424
    <xsl:otherwise>
 
425
      <xsl:choose>
 
426
        <xsl:when test="$style = 'family-given'">
 
427
          <xsl:call-template name="person.name.family-given">
 
428
            <xsl:with-param name="node" select="$node"/>
 
429
          </xsl:call-template>
 
430
        </xsl:when>
 
431
        <xsl:when test="$style = 'last-first'">
 
432
          <xsl:call-template name="person.name.last-first">
 
433
            <xsl:with-param name="node" select="$node"/>
 
434
          </xsl:call-template>
 
435
        </xsl:when>
 
436
        <xsl:otherwise>
 
437
          <xsl:call-template name="person.name.first-last">
 
438
            <xsl:with-param name="node" select="$node"/>
 
439
          </xsl:call-template>
 
440
        </xsl:otherwise>
 
441
      </xsl:choose>
 
442
    </xsl:otherwise>
 
443
  </xsl:choose>
 
444
</xsl:template>
 
445
 
 
446
<xsl:template name="person.name.family-given">
 
447
  <xsl:param name="node" select="."/>
 
448
 
 
449
  <!-- The family-given style applies a convention for identifying given -->
 
450
  <!-- and family names in locales where it may be ambiguous -->
 
451
  <xsl:apply-templates select="$node//surname[1]"/>
 
452
 
 
453
  <xsl:if test="$node//surname and $node//firstname">
 
454
    <xsl:text> </xsl:text>
 
455
  </xsl:if>
 
456
 
 
457
  <xsl:apply-templates select="$node//firstname[1]"/>
 
458
 
 
459
  <xsl:text> [FAMILY Given]</xsl:text>
 
460
</xsl:template>
 
461
 
 
462
<xsl:template name="person.name.last-first">
 
463
  <xsl:param name="node" select="."/>
 
464
 
 
465
  <xsl:apply-templates select="$node//surname[1]"/>
 
466
 
 
467
  <xsl:if test="$node//surname and $node//firstname">
 
468
    <xsl:text>, </xsl:text>
 
469
  </xsl:if>
 
470
 
 
471
  <xsl:apply-templates select="$node//firstname[1]"/>
 
472
</xsl:template>
 
473
 
 
474
<xsl:template name="person.name.first-last">
 
475
  <xsl:param name="node" select="."/>
 
476
 
 
477
  <xsl:if test="$node//honorific">
 
478
    <xsl:apply-templates select="$node//honorific[1]"/>
 
479
    <xsl:value-of select="$punct.honorific"/>
 
480
  </xsl:if>
 
481
 
 
482
  <xsl:if test="$node//firstname">
 
483
    <xsl:if test="$node//honorific">
 
484
      <xsl:text> </xsl:text>
 
485
    </xsl:if>
 
486
    <xsl:apply-templates select="$node//firstname[1]"/>
 
487
  </xsl:if>
 
488
 
 
489
  <xsl:if test="$node//othername and $author.othername.in.middle != 0">
 
490
    <xsl:if test="$node//honorific or $node//firstname">
 
491
      <xsl:text> </xsl:text>
 
492
    </xsl:if>
 
493
    <xsl:apply-templates select="$node//othername[1]"/>
 
494
  </xsl:if>
 
495
 
 
496
  <xsl:if test="$node//surname">
 
497
    <xsl:if test="$node//honorific or $node//firstname
 
498
                  or ($node//othername and $author.othername.in.middle != 0)">
 
499
      <xsl:text> </xsl:text>
 
500
    </xsl:if>
 
501
    <xsl:apply-templates select="$node//surname[1]"/>
 
502
  </xsl:if>
 
503
 
 
504
  <xsl:if test="$node//lineage">
 
505
    <xsl:text>, </xsl:text>
 
506
    <xsl:apply-templates select="$node//lineage[1]"/>
 
507
  </xsl:if>
 
508
</xsl:template>
 
509
 
 
510
<xsl:template name="person.name.list">
 
511
  <!-- Return a formatted string representation of the contents of
 
512
       the current element. The current element must contain one or
 
513
       more AUTHORs, CORPAUTHORs, OTHERCREDITs, and/or EDITORs.
 
514
 
 
515
       John Doe
 
516
     or
 
517
       John Doe and Jane Doe
 
518
     or
 
519
       John Doe, Jane Doe, and A. Nonymous
 
520
  -->
 
521
  <xsl:param name="person.list"
 
522
             select="author|corpauthor|othercredit|editor"/>
 
523
  <xsl:param name="person.count" select="count($person.list)"/>
 
524
  <xsl:param name="count" select="1"/>
 
525
 
 
526
  <xsl:choose>
 
527
    <xsl:when test="$count &gt; $person.count"></xsl:when>
 
528
    <xsl:otherwise>
 
529
      <xsl:call-template name="person.name">
 
530
        <xsl:with-param name="node" select="$person.list[position()=$count]"/>
 
531
      </xsl:call-template>
 
532
 
 
533
      <xsl:choose>
 
534
        <xsl:when test="$person.count = 2 and $count = 1">
 
535
          <xsl:call-template name="gentext.template">
 
536
            <xsl:with-param name="context" select="'authorgroup'"/>
 
537
            <xsl:with-param name="name" select="'sep2'"/>
 
538
          </xsl:call-template>
 
539
        </xsl:when>
 
540
        <xsl:when test="$person.count &gt; 2 and $count+1 = $person.count">
 
541
          <xsl:call-template name="gentext.template">
 
542
            <xsl:with-param name="context" select="'authorgroup'"/>
 
543
            <xsl:with-param name="name" select="'seplast'"/>
 
544
          </xsl:call-template>
 
545
        </xsl:when>
 
546
        <xsl:when test="$count &lt; $person.count">
 
547
          <xsl:call-template name="gentext.template">
 
548
            <xsl:with-param name="context" select="'authorgroup'"/>
 
549
            <xsl:with-param name="name" select="'sep'"/>
 
550
          </xsl:call-template>
 
551
        </xsl:when>
 
552
      </xsl:choose>
 
553
 
 
554
      <xsl:call-template name="person.name.list">
 
555
        <xsl:with-param name="person.list" select="$person.list"/>
 
556
        <xsl:with-param name="person.count" select="$person.count"/>
 
557
        <xsl:with-param name="count" select="$count+1"/>
 
558
      </xsl:call-template>
 
559
    </xsl:otherwise>
 
560
  </xsl:choose>
 
561
</xsl:template><!-- person.name.list -->
 
562
 
 
563
<!-- === synopsis ======================================================= -->
 
564
<!-- The following definitions match those given in the reference
 
565
     documentation for DocBook V3.0
 
566
-->
 
567
 
 
568
<xsl:variable name="arg.choice.opt.open.str">[</xsl:variable>
 
569
<xsl:variable name="arg.choice.opt.close.str">]</xsl:variable>
 
570
<xsl:variable name="arg.choice.req.open.str">{</xsl:variable>
 
571
<xsl:variable name="arg.choice.req.close.str">}</xsl:variable>
 
572
<xsl:variable name="arg.choice.plain.open.str"><xsl:text> </xsl:text></xsl:variable>
 
573
<xsl:variable name="arg.choice.plain.close.str"><xsl:text> </xsl:text></xsl:variable>
 
574
<xsl:variable name="arg.choice.def.open.str">[</xsl:variable>
 
575
<xsl:variable name="arg.choice.def.close.str">]</xsl:variable>
 
576
<xsl:variable name="arg.rep.repeat.str">...</xsl:variable>
 
577
<xsl:variable name="arg.rep.norepeat.str"></xsl:variable>
 
578
<xsl:variable name="arg.rep.def.str"></xsl:variable>
 
579
<xsl:variable name="arg.or.sep"> | </xsl:variable>
 
580
<xsl:variable name="cmdsynopsis.hanging.indent">4pi</xsl:variable>
 
581
 
 
582
<!-- ====================================================================== -->
 
583
 
 
584
<!--
 
585
<xsl:template name="xref.g.subst">
 
586
  <xsl:param name="string"></xsl:param>
 
587
  <xsl:param name="target" select="."/>
 
588
  <xsl:variable name="subst">%g</xsl:variable>
 
589
 
 
590
  <xsl:choose>
 
591
    <xsl:when test="contains($string, $subst)">
 
592
      <xsl:value-of select="substring-before($string, $subst)"/>
 
593
      <xsl:call-template name="gentext.element.name">
 
594
        <xsl:with-param name="element.name" select="name($target)"/>
 
595
      </xsl:call-template>
 
596
      <xsl:call-template name="xref.g.subst">
 
597
        <xsl:with-param name="string"
 
598
                        select="substring-after($string, $subst)"/>
 
599
        <xsl:with-param name="target" select="$target"/>
 
600
      </xsl:call-template>
 
601
    </xsl:when>
 
602
    <xsl:otherwise>
 
603
      <xsl:value-of select="$string"/>
 
604
    </xsl:otherwise>
 
605
  </xsl:choose>
 
606
</xsl:template>
 
607
 
 
608
<xsl:template name="xref.t.subst">
 
609
  <xsl:param name="string"></xsl:param>
 
610
  <xsl:param name="target" select="."/>
 
611
  <xsl:variable name="subst">%t</xsl:variable>
 
612
 
 
613
  <xsl:choose>
 
614
    <xsl:when test="contains($string, $subst)">
 
615
      <xsl:call-template name="xref.g.subst">
 
616
        <xsl:with-param name="string"
 
617
                        select="substring-before($string, $subst)"/>
 
618
        <xsl:with-param name="target" select="$target"/>
 
619
      </xsl:call-template>
 
620
      <xsl:call-template name="title.xref">
 
621
        <xsl:with-param name="target" select="$target"/>
 
622
      </xsl:call-template>
 
623
      <xsl:call-template name="xref.t.subst">
 
624
        <xsl:with-param name="string"
 
625
                        select="substring-after($string, $subst)"/>
 
626
        <xsl:with-param name="target" select="$target"/>
 
627
      </xsl:call-template>
 
628
    </xsl:when>
 
629
    <xsl:otherwise>
 
630
      <xsl:call-template name="xref.g.subst">
 
631
        <xsl:with-param name="string" select="$string"/>
 
632
        <xsl:with-param name="target" select="$target"/>
 
633
      </xsl:call-template>
 
634
    </xsl:otherwise>
 
635
  </xsl:choose>
 
636
</xsl:template>
 
637
 
 
638
<xsl:template name="xref.n.subst">
 
639
  <xsl:param name="string"></xsl:param>
 
640
  <xsl:param name="target" select="."/>
 
641
  <xsl:variable name="subst">%n</xsl:variable>
 
642
 
 
643
  <xsl:choose>
 
644
    <xsl:when test="contains($string, $subst)">
 
645
      <xsl:call-template name="xref.t.subst">
 
646
        <xsl:with-param name="string"
 
647
                        select="substring-before($string, $subst)"/>
 
648
        <xsl:with-param name="target" select="$target"/>
 
649
      </xsl:call-template>
 
650
      <xsl:call-template name="number.xref">
 
651
        <xsl:with-param name="target" select="$target"/>
 
652
      </xsl:call-template>
 
653
      <xsl:call-template name="xref.t.subst">
 
654
        <xsl:with-param name="string"
 
655
                        select="substring-after($string, $subst)"/>
 
656
        <xsl:with-param name="target" select="$target"/>
 
657
      </xsl:call-template>
 
658
    </xsl:when>
 
659
    <xsl:otherwise>
 
660
      <xsl:call-template name="xref.t.subst">
 
661
        <xsl:with-param name="string" select="$string"/>
 
662
        <xsl:with-param name="target" select="$target"/>
 
663
      </xsl:call-template>
 
664
    </xsl:otherwise>
 
665
  </xsl:choose>
 
666
</xsl:template>
 
667
 
 
668
<xsl:template name="subst.xref.text">
 
669
  <xsl:param name="xref.text"></xsl:param>
 
670
  <xsl:param name="target" select="."/>
 
671
 
 
672
  <xsl:call-template name="xref.n.subst">
 
673
    <xsl:with-param name="string" select="$xref.text"/>
 
674
    <xsl:with-param name="target" select="$target"/>
 
675
  </xsl:call-template>
 
676
</xsl:template>
 
677
-->
 
678
 
 
679
<!-- ====================================================================== -->
 
680
 
 
681
<xsl:template name="filename-basename">
 
682
  <!-- We assume all filenames are really URIs and use "/" -->
 
683
  <xsl:param name="filename"></xsl:param>
 
684
  <xsl:param name="recurse" select="false()"/>
 
685
 
 
686
  <xsl:choose>
 
687
    <xsl:when test="substring-after($filename, '/') != ''">
 
688
      <xsl:call-template name="filename-basename">
 
689
        <xsl:with-param name="filename"
 
690
                        select="substring-after($filename, '/')"/>
 
691
        <xsl:with-param name="recurse" select="true()"/>
 
692
      </xsl:call-template>
 
693
    </xsl:when>
 
694
    <xsl:otherwise>
 
695
      <xsl:value-of select="$filename"/>
 
696
    </xsl:otherwise>
 
697
  </xsl:choose>
 
698
</xsl:template>
 
699
 
 
700
<xsl:template name="filename-extension">
 
701
  <xsl:param name="filename"></xsl:param>
 
702
  <xsl:param name="recurse" select="false()"/>
 
703
 
 
704
  <!-- Make sure we only look at the base name... -->
 
705
  <xsl:variable name="basefn">
 
706
    <xsl:choose>
 
707
      <xsl:when test="$recurse">
 
708
        <xsl:value-of select="$filename"/>
 
709
      </xsl:when>
 
710
      <xsl:otherwise>
 
711
        <xsl:call-template name="filename-basename">
 
712
          <xsl:with-param name="filename" select="$filename"/>
 
713
        </xsl:call-template>
 
714
      </xsl:otherwise>
 
715
    </xsl:choose>
 
716
  </xsl:variable>
 
717
 
 
718
  <xsl:choose>
 
719
    <xsl:when test="substring-after($basefn, '.') != ''">
 
720
      <xsl:call-template name="filename-extension">
 
721
        <xsl:with-param name="filename"
 
722
                        select="substring-after($basefn, '.')"/>
 
723
        <xsl:with-param name="recurse" select="true()"/>
 
724
      </xsl:call-template>
 
725
    </xsl:when>
 
726
    <xsl:when test="$recurse">
 
727
      <xsl:value-of select="$basefn"/>
 
728
    </xsl:when>
 
729
    <xsl:otherwise></xsl:otherwise>
 
730
  </xsl:choose>
 
731
</xsl:template>
 
732
 
 
733
<!-- ====================================================================== -->
 
734
 
 
735
<doc:template name="select.mediaobject" xmlns="">
 
736
<refpurpose>Selects and processes an appropriate media object from a list</refpurpose>
 
737
 
 
738
<refdescription>
 
739
<para>This template takes a list of media objects (usually the
 
740
children of a mediaobject or inlinemediaobject) and processes
 
741
the "right" object.</para>
 
742
 
 
743
<para>This template relies on a template named 
 
744
"select.mediaobject.index" to determine which object
 
745
in the list is appropriate.</para>
 
746
 
 
747
<para>If no acceptable object is located, nothing happens.</para>
 
748
</refdescription>
 
749
 
 
750
<refparameter>
 
751
<variablelist>
 
752
<varlistentry><term>olist</term>
 
753
<listitem>
 
754
<para>The node list of potential objects to examine.</para>
 
755
</listitem>
 
756
</varlistentry>
 
757
</variablelist>
 
758
</refparameter>
 
759
 
 
760
<refreturn>
 
761
<para>Calls &lt;xsl:apply-templates&gt; on the selected object.</para>
 
762
</refreturn>
 
763
</doc:template>
 
764
 
 
765
<xsl:template name="select.mediaobject">
 
766
  <xsl:param name="olist"
 
767
             select="imageobject|imageobjectco
 
768
                     |videoobject|audioobject|textobject"/>
 
769
  
 
770
  <xsl:variable name="mediaobject.index">
 
771
    <xsl:call-template name="select.mediaobject.index">
 
772
      <xsl:with-param name="olist" select="$olist"/>
 
773
      <xsl:with-param name="count" select="1"/>
 
774
    </xsl:call-template>
 
775
  </xsl:variable>
 
776
 
 
777
  <xsl:if test="$mediaobject.index != ''">
 
778
    <xsl:apply-templates select="$olist[position() = $mediaobject.index]"/>
 
779
  </xsl:if>
 
780
</xsl:template>
 
781
 
 
782
<!-- ====================================================================== -->
 
783
 
 
784
<doc:template name="select.mediaobject.index" xmlns="">
 
785
<refpurpose>Selects the position of the appropriate media object from a list</refpurpose>
 
786
 
 
787
<refdescription>
 
788
<para>This template takes a list of media objects (usually the
 
789
children of a mediaobject or inlinemediaobject) and determines
 
790
the "right" object. It returns the position of that object
 
791
to be used by the calling template.</para>
 
792
 
 
793
<para>If the parameter <parameter>use.role.for.mediaobject</parameter>
 
794
is nonzero, then it first checks for an object with
 
795
a role attribute of the appropriate value.  It takes the first
 
796
of those.  Otherwise, it takes the first acceptable object
 
797
through a recursive pass through the list.</para>
 
798
 
 
799
<para>This template relies on a template named "is.acceptable.mediaobject"
 
800
to determine if a given object is an acceptable graphic. The semantics
 
801
of media objects is that the first acceptable graphic should be used.
 
802
</para>
 
803
 
 
804
<para>If no acceptable object is located, no index is returned.</para>
 
805
</refdescription>
 
806
 
 
807
<refparameter>
 
808
<variablelist>
 
809
<varlistentry><term>olist</term>
 
810
<listitem>
 
811
<para>The node list of potential objects to examine.</para>
 
812
</listitem>
 
813
</varlistentry>
 
814
<varlistentry><term>count</term>
 
815
<listitem>
 
816
<para>The position in the list currently being considered by the 
 
817
recursive process.</para>
 
818
</listitem>
 
819
</varlistentry>
 
820
</variablelist>
 
821
</refparameter>
 
822
 
 
823
<refreturn>
 
824
<para>Returns the position in the original list of the selected object.</para>
 
825
</refreturn>
 
826
</doc:template>
 
827
 
 
828
<xsl:template name="select.mediaobject.index">
 
829
  <xsl:param name="olist"
 
830
             select="imageobject|imageobjectco
 
831
                     |videoobject|audioobject|textobject"/>
 
832
  <xsl:param name="count">1</xsl:param>
 
833
 
 
834
  <xsl:choose>
 
835
    <!-- Test for objects preferred by role -->
 
836
    <xsl:when test="$use.role.for.mediaobject != 0 
 
837
               and $preferred.mediaobject.role != ''
 
838
               and $olist[@role = $preferred.mediaobject.role]"> 
 
839
      
 
840
      <!-- Get the first hit's position index -->
 
841
      <xsl:for-each select="$olist">
 
842
        <xsl:if test="@role = $preferred.mediaobject.role and
 
843
             not(preceding-sibling::*[@role = $preferred.mediaobject.role])"> 
 
844
          <xsl:value-of select="position()"/> 
 
845
        </xsl:if>
 
846
      </xsl:for-each>
 
847
    </xsl:when>
 
848
 
 
849
    <xsl:when test="$use.role.for.mediaobject != 0 
 
850
               and $olist[@role = $stylesheet.result.type]">
 
851
      <!-- Get the first hit's position index -->
 
852
      <xsl:for-each select="$olist">
 
853
        <xsl:if test="@role = $stylesheet.result.type and 
 
854
              not(preceding-sibling::*[@role = $stylesheet.result.type])"> 
 
855
          <xsl:value-of select="position()"/> 
 
856
        </xsl:if>
 
857
      </xsl:for-each>
 
858
    </xsl:when>
 
859
    <!-- Accept 'html' for $stylesheet.result.type = 'xhtml' -->
 
860
    <xsl:when test="$use.role.for.mediaobject != 0 
 
861
               and $stylesheet.result.type = 'xhtml'
 
862
               and $olist[@role = 'html']">
 
863
      <!-- Get the first hit's position index -->
 
864
      <xsl:for-each select="$olist">
 
865
        <xsl:if test="@role = 'html' and 
 
866
              not(preceding-sibling::*[@role = 'html'])"> 
 
867
          <xsl:value-of select="position()"/> 
 
868
        </xsl:if>
 
869
      </xsl:for-each>
 
870
    </xsl:when>
 
871
    <xsl:otherwise>
 
872
      <!-- Otherwise select first acceptable object -->
 
873
      <xsl:if test="$count &lt;= count($olist)">
 
874
        <xsl:variable name="object" select="$olist[position()=$count]"/>
 
875
    
 
876
        <xsl:variable name="useobject">
 
877
          <xsl:choose>
 
878
            <!-- The phrase is used only when contains TeX Math and output is FO -->
 
879
            <xsl:when test="name($object)='textobject' and $object/phrase
 
880
                            and $object/@role='tex' and $stylesheet.result.type = 'fo'
 
881
                            and $tex.math.in.alt != ''">
 
882
              <xsl:text>1</xsl:text> 
 
883
            </xsl:when>
 
884
            <!-- The phrase is never used -->
 
885
            <xsl:when test="name($object)='textobject' and $object/phrase">
 
886
              <xsl:text>0</xsl:text>
 
887
            </xsl:when>
 
888
            <xsl:when test="name($object)='textobject'
 
889
                            and $object/ancestor::equation ">
 
890
            <!-- The first textobject is not a reasonable fallback
 
891
                 for equation image -->
 
892
              <xsl:text>0</xsl:text>
 
893
            </xsl:when>
 
894
            <!-- The first textobject is a reasonable fallback -->
 
895
            <xsl:when test="name($object)='textobject'
 
896
                            and $object[not(@role) or @role!='tex']">
 
897
              <xsl:text>1</xsl:text>
 
898
            </xsl:when>
 
899
            <!-- don't use graphic when output is FO, TeX Math is used 
 
900
                 and there is math in alt element -->
 
901
            <xsl:when test="$object/ancestor::equation and 
 
902
                            $object/ancestor::equation/alt[@role='tex']
 
903
                            and $stylesheet.result.type = 'fo'
 
904
                            and $tex.math.in.alt != ''">
 
905
              <xsl:text>0</xsl:text>
 
906
            </xsl:when>
 
907
            <!-- If there's only one object, use it -->
 
908
            <xsl:when test="$count = 1 and count($olist) = 1">
 
909
               <xsl:text>1</xsl:text>
 
910
            </xsl:when>
 
911
            <!-- Otherwise, see if this one is a useable graphic -->
 
912
            <xsl:otherwise>
 
913
              <xsl:choose>
 
914
                <!-- peek inside imageobjectco to simplify the test -->
 
915
                <xsl:when test="local-name($object) = 'imageobjectco'">
 
916
                  <xsl:call-template name="is.acceptable.mediaobject">
 
917
                    <xsl:with-param name="object" select="$object/imageobject"/>
 
918
                  </xsl:call-template>
 
919
                </xsl:when>
 
920
                <xsl:otherwise>
 
921
                  <xsl:call-template name="is.acceptable.mediaobject">
 
922
                    <xsl:with-param name="object" select="$object"/>
 
923
                  </xsl:call-template>
 
924
                </xsl:otherwise>
 
925
              </xsl:choose>
 
926
            </xsl:otherwise>
 
927
          </xsl:choose>
 
928
        </xsl:variable>
 
929
    
 
930
        <xsl:choose>
 
931
          <xsl:when test="$useobject='1'">
 
932
            <xsl:value-of select="$count"/>
 
933
          </xsl:when>
 
934
          <xsl:otherwise>
 
935
            <xsl:call-template name="select.mediaobject.index">
 
936
              <xsl:with-param name="olist" select="$olist"/>
 
937
              <xsl:with-param name="count" select="$count + 1"/>
 
938
            </xsl:call-template>
 
939
          </xsl:otherwise>
 
940
        </xsl:choose>
 
941
      </xsl:if>
 
942
    </xsl:otherwise>
 
943
  </xsl:choose>
 
944
</xsl:template>
 
945
 
 
946
<doc:template name="is.acceptable.mediaobject" xmlns="">
 
947
<refpurpose>Returns '1' if the specified media object is recognized.</refpurpose>
 
948
 
 
949
<refdescription>
 
950
<para>This template examines a media object and returns '1' if the
 
951
object is recognized as a graphic.</para>
 
952
</refdescription>
 
953
 
 
954
<refparameter>
 
955
<variablelist>
 
956
<varlistentry><term>object</term>
 
957
<listitem>
 
958
<para>The media object to consider.</para>
 
959
</listitem>
 
960
</varlistentry>
 
961
</variablelist>
 
962
</refparameter>
 
963
 
 
964
<refreturn>
 
965
<para>0 or 1</para>
 
966
</refreturn>
 
967
</doc:template>
 
968
 
 
969
<xsl:template name="is.acceptable.mediaobject">
 
970
  <xsl:param name="object"></xsl:param>
 
971
 
 
972
  <xsl:variable name="filename">
 
973
    <xsl:call-template name="mediaobject.filename">
 
974
      <xsl:with-param name="object" select="$object"/>
 
975
    </xsl:call-template>
 
976
  </xsl:variable>
 
977
 
 
978
  <xsl:variable name="ext">
 
979
    <xsl:call-template name="filename-extension">
 
980
      <xsl:with-param name="filename" select="$filename"/>
 
981
    </xsl:call-template>
 
982
  </xsl:variable>
 
983
 
 
984
  <!-- there will only be one -->
 
985
  <xsl:variable name="data" select="$object/videodata
 
986
                                    |$object/imagedata
 
987
                                    |$object/audiodata"/>
 
988
 
 
989
  <xsl:variable name="format" select="$data/@format"/>
 
990
 
 
991
  <xsl:variable name="graphic.format">
 
992
    <xsl:if test="$format">
 
993
      <xsl:call-template name="is.graphic.format">
 
994
        <xsl:with-param name="format" select="$format"/>
 
995
      </xsl:call-template>
 
996
    </xsl:if>
 
997
  </xsl:variable>
 
998
 
 
999
  <xsl:variable name="graphic.ext">
 
1000
    <xsl:if test="$ext">
 
1001
      <xsl:call-template name="is.graphic.extension">
 
1002
        <xsl:with-param name="ext" select="$ext"/>
 
1003
      </xsl:call-template>
 
1004
    </xsl:if>
 
1005
  </xsl:variable>
 
1006
 
 
1007
  <xsl:choose>
 
1008
    <xsl:when test="$use.svg = 0 and $format = 'SVG'">0</xsl:when>
 
1009
    <xsl:when xmlns:svg="http://www.w3.org/2000/svg"
 
1010
              test="$use.svg != 0 and $object/svg:*">1</xsl:when>
 
1011
    <xsl:when test="$graphic.format = '1'">1</xsl:when>
 
1012
    <xsl:when test="$graphic.ext = '1'">1</xsl:when>
 
1013
    <xsl:otherwise>0</xsl:otherwise>
 
1014
  </xsl:choose>
 
1015
</xsl:template>
 
1016
 
 
1017
<xsl:template name="mediaobject.filename">
 
1018
  <xsl:param name="object"></xsl:param>
 
1019
 
 
1020
  <xsl:variable name="data" select="$object/videodata
 
1021
                                    |$object/imagedata
 
1022
                                    |$object/audiodata
 
1023
                                    |$object"/>
 
1024
 
 
1025
  <xsl:variable name="filename">
 
1026
    <xsl:choose>
 
1027
      <xsl:when test="$data[@fileref]">
 
1028
        <xsl:value-of select="$data/@fileref"/>
 
1029
      </xsl:when>
 
1030
      <xsl:when test="$data[@entityref]">
 
1031
        <xsl:value-of select="unparsed-entity-uri($data/@entityref)"/>
 
1032
      </xsl:when>
 
1033
      <xsl:otherwise></xsl:otherwise>
 
1034
    </xsl:choose>
 
1035
  </xsl:variable>
 
1036
 
 
1037
  <xsl:variable name="real.ext">
 
1038
    <xsl:call-template name="filename-extension">
 
1039
      <xsl:with-param name="filename" select="$filename"/>
 
1040
    </xsl:call-template>
 
1041
  </xsl:variable>
 
1042
 
 
1043
  <xsl:variable name="ext">
 
1044
    <xsl:choose>
 
1045
      <xsl:when test="$real.ext != ''">
 
1046
        <xsl:value-of select="$real.ext"/>
 
1047
      </xsl:when>
 
1048
      <xsl:otherwise>
 
1049
        <xsl:value-of select="$graphic.default.extension"/>
 
1050
      </xsl:otherwise>
 
1051
    </xsl:choose>
 
1052
  </xsl:variable>
 
1053
 
 
1054
  <xsl:variable name="graphic.ext">
 
1055
    <xsl:call-template name="is.graphic.extension">
 
1056
      <xsl:with-param name="ext" select="$ext"/>
 
1057
    </xsl:call-template>
 
1058
  </xsl:variable>
 
1059
 
 
1060
  <xsl:choose>
 
1061
    <xsl:when test="$real.ext = ''">
 
1062
      <xsl:choose>
 
1063
        <xsl:when test="$ext != ''">
 
1064
          <xsl:value-of select="$filename"/>
 
1065
          <xsl:text>.</xsl:text>
 
1066
          <xsl:value-of select="$ext"/>
 
1067
        </xsl:when>
 
1068
        <xsl:otherwise>
 
1069
          <xsl:value-of select="$filename"/>
 
1070
        </xsl:otherwise>
 
1071
      </xsl:choose>
 
1072
    </xsl:when>
 
1073
    <xsl:when test="not($graphic.ext)">
 
1074
      <xsl:choose>
 
1075
        <xsl:when test="$graphic.default.extension != ''">
 
1076
          <xsl:value-of select="$filename"/>
 
1077
          <xsl:text>.</xsl:text>
 
1078
          <xsl:value-of select="$graphic.default.extension"/>
 
1079
        </xsl:when>
 
1080
        <xsl:otherwise>
 
1081
          <xsl:value-of select="$filename"/>
 
1082
        </xsl:otherwise>
 
1083
      </xsl:choose>
 
1084
    </xsl:when>
 
1085
    <xsl:otherwise>
 
1086
      <xsl:value-of select="$filename"/>
 
1087
    </xsl:otherwise>
 
1088
  </xsl:choose>
 
1089
</xsl:template>
 
1090
 
 
1091
<!-- ====================================================================== -->
 
1092
 
 
1093
<doc:template name="check.id.unique" xmlns="">
 
1094
<refpurpose>Warn users about references to non-unique IDs</refpurpose>
 
1095
<refdescription>
 
1096
<para>If passed an ID in <varname>linkend</varname>,
 
1097
<function>check.id.unique</function> prints
 
1098
a warning message to the user if either the ID does not exist or
 
1099
the ID is not unique.</para>
 
1100
</refdescription>
 
1101
</doc:template>
 
1102
 
 
1103
<xsl:template name="check.id.unique">
 
1104
  <xsl:param name="linkend"></xsl:param>
 
1105
  <xsl:if test="$linkend != ''">
 
1106
    <xsl:variable name="targets" select="key('id',$linkend)"/>
 
1107
    <xsl:variable name="target" select="$targets[1]"/>
 
1108
 
 
1109
    <xsl:if test="count($targets)=0">
 
1110
      <xsl:message>
 
1111
        <xsl:text>Error: no ID for constraint linkend: </xsl:text>
 
1112
        <xsl:value-of select="$linkend"/>
 
1113
        <xsl:text>.</xsl:text>
 
1114
      </xsl:message>
 
1115
      <!--
 
1116
      <xsl:message>
 
1117
        <xsl:text>If the ID exists in your document, did your </xsl:text>
 
1118
        <xsl:text>XSLT Processor load the DTD?</xsl:text>
 
1119
      </xsl:message>
 
1120
      -->
 
1121
    </xsl:if>
 
1122
 
 
1123
    <xsl:if test="count($targets)>1">
 
1124
      <xsl:message>
 
1125
        <xsl:text>Warning: multiple "IDs" for constraint linkend: </xsl:text>
 
1126
        <xsl:value-of select="$linkend"/>
 
1127
        <xsl:text>.</xsl:text>
 
1128
      </xsl:message>
 
1129
    </xsl:if>
 
1130
  </xsl:if>
 
1131
</xsl:template>
 
1132
 
 
1133
<doc:template name="check.idref.targets" xmlns="">
 
1134
<refpurpose>Warn users about incorrectly typed references</refpurpose>
 
1135
<refdescription>
 
1136
<para>If passed an ID in <varname>linkend</varname>,
 
1137
<function>check.idref.targets</function> makes sure that the element
 
1138
pointed to by the link is one of the elements listed in
 
1139
<varname>element-list</varname> and warns the user otherwise.</para>
 
1140
</refdescription>
 
1141
</doc:template>
 
1142
 
 
1143
<xsl:template name="check.idref.targets">
 
1144
  <xsl:param name="linkend"></xsl:param>
 
1145
  <xsl:param name="element-list"></xsl:param>
 
1146
  <xsl:if test="$linkend != ''">
 
1147
    <xsl:variable name="targets" select="key('id',$linkend)"/>
 
1148
    <xsl:variable name="target" select="$targets[1]"/>
 
1149
 
 
1150
    <xsl:if test="count($target) &gt; 0">
 
1151
      <xsl:if test="not(contains(concat(' ', $element-list, ' '), name($target)))">
 
1152
        <xsl:message>
 
1153
          <xsl:text>Error: linkend (</xsl:text>
 
1154
          <xsl:value-of select="$linkend"/>
 
1155
          <xsl:text>) points to "</xsl:text>
 
1156
          <xsl:value-of select="name($target)"/>
 
1157
          <xsl:text>" not (one of): </xsl:text>
 
1158
          <xsl:value-of select="$element-list"/>
 
1159
        </xsl:message>
 
1160
      </xsl:if>
 
1161
    </xsl:if>
 
1162
  </xsl:if>
 
1163
</xsl:template>
 
1164
 
 
1165
<!-- ====================================================================== -->
 
1166
<!-- Procedure Step Numeration -->
 
1167
 
 
1168
<xsl:param name="procedure.step.numeration.formats" select="'1aiAI'"/>
 
1169
 
 
1170
<xsl:template name="procedure.step.numeration">
 
1171
  <xsl:param name="context" select="."/>
 
1172
  <xsl:variable name="format.length"
 
1173
                select="string-length($procedure.step.numeration.formats)"/>
 
1174
  <xsl:choose>
 
1175
    <xsl:when test="local-name($context) = 'substeps'">
 
1176
      <xsl:variable name="ssdepth"
 
1177
                    select="count($context/ancestor::substeps)"/>
 
1178
      <xsl:variable name="sstype" select="($ssdepth mod $format.length)+2"/>
 
1179
      <xsl:choose>
 
1180
        <xsl:when test="$sstype &gt; $format.length">
 
1181
          <xsl:value-of select="substring($procedure.step.numeration.formats,1,1)"/>
 
1182
        </xsl:when>
 
1183
        <xsl:otherwise>
 
1184
          <xsl:value-of select="substring($procedure.step.numeration.formats,$sstype,1)"/>
 
1185
        </xsl:otherwise>
 
1186
      </xsl:choose>
 
1187
    </xsl:when>
 
1188
    <xsl:when test="local-name($context) = 'step'">
 
1189
      <xsl:variable name="sdepth"
 
1190
                    select="count($context/ancestor::substeps)"/>
 
1191
      <xsl:variable name="stype" select="($sdepth mod $format.length)+1"/>
 
1192
      <xsl:value-of select="substring($procedure.step.numeration.formats,$stype,1)"/>
 
1193
    </xsl:when>
 
1194
    <xsl:otherwise>
 
1195
      <xsl:message>
 
1196
        <xsl:text>Unexpected context in procedure.step.numeration: </xsl:text>
 
1197
        <xsl:value-of select="local-name($context)"/>
 
1198
      </xsl:message>
 
1199
    </xsl:otherwise>
 
1200
  </xsl:choose>
 
1201
</xsl:template>
 
1202
 
 
1203
<xsl:template match="step" mode="number">
 
1204
  <xsl:param name="rest" select="''"/>
 
1205
  <xsl:param name="recursive" select="1"/>
 
1206
  <xsl:variable name="format">
 
1207
    <xsl:call-template name="procedure.step.numeration"/>
 
1208
  </xsl:variable>
 
1209
  <xsl:variable name="num">
 
1210
    <xsl:number count="step" format="{$format}"/>
 
1211
  </xsl:variable>
 
1212
  <xsl:choose>
 
1213
    <xsl:when test="$recursive != 0 and ancestor::step">
 
1214
      <xsl:apply-templates select="ancestor::step[1]" mode="number">
 
1215
        <xsl:with-param name="rest" select="concat('.', $num, $rest)"/>
 
1216
      </xsl:apply-templates>
 
1217
    </xsl:when>
 
1218
    <xsl:otherwise>
 
1219
      <xsl:value-of select="concat($num, $rest)"/>
 
1220
    </xsl:otherwise>
 
1221
  </xsl:choose>
 
1222
</xsl:template>
 
1223
 
 
1224
<!-- ====================================================================== -->
 
1225
<!-- OrderedList Numeration -->
 
1226
 
 
1227
<xsl:template name="orderedlist-starting-number">
 
1228
  <xsl:param name="list" select="."/>
 
1229
  <xsl:choose>
 
1230
    <xsl:when test="not($list/@continuation = 'continues')">1</xsl:when>
 
1231
    <xsl:otherwise>
 
1232
      <xsl:variable name="prevlist"
 
1233
                    select="$list/preceding::orderedlist[1]"/>
 
1234
      <xsl:choose>
 
1235
        <xsl:when test="count($prevlist) = 0">2</xsl:when>
 
1236
        <xsl:otherwise>
 
1237
          <xsl:variable name="prevlength" select="count($prevlist/listitem)"/>
 
1238
          <xsl:variable name="prevstart">
 
1239
            <xsl:call-template name="orderedlist-starting-number">
 
1240
              <xsl:with-param name="list" select="$prevlist"/>
 
1241
            </xsl:call-template>
 
1242
          </xsl:variable>
 
1243
          <xsl:value-of select="$prevstart + $prevlength"/>
 
1244
        </xsl:otherwise>
 
1245
      </xsl:choose>
 
1246
    </xsl:otherwise>
 
1247
  </xsl:choose>
 
1248
</xsl:template>
 
1249
 
 
1250
<xsl:template name="orderedlist-item-number">
 
1251
  <!-- context node must be a listitem in an orderedlist -->
 
1252
  <xsl:param name="node" select="."/>
 
1253
 
 
1254
  <xsl:choose>
 
1255
    <xsl:when test="$node/@override">
 
1256
      <xsl:value-of select="$node/@override"/>
 
1257
    </xsl:when>
 
1258
    <xsl:when test="$node/preceding-sibling::listitem">
 
1259
      <xsl:variable name="pnum">
 
1260
        <xsl:call-template name="orderedlist-item-number">
 
1261
          <xsl:with-param name="node" select="$node/preceding-sibling::listitem[1]"/>
 
1262
        </xsl:call-template>
 
1263
      </xsl:variable>
 
1264
      <xsl:value-of select="$pnum + 1"/>
 
1265
    </xsl:when>
 
1266
    <xsl:otherwise>
 
1267
      <xsl:call-template name="orderedlist-starting-number">
 
1268
        <xsl:with-param name="list" select="parent::*"/>
 
1269
      </xsl:call-template>
 
1270
    </xsl:otherwise>
 
1271
  </xsl:choose>
 
1272
</xsl:template>
 
1273
 
 
1274
<xsl:template name="next.numeration">
 
1275
  <xsl:param name="numeration" select="'default'"/>
 
1276
  <xsl:choose>
 
1277
    <!-- Change this list if you want to change the order of numerations -->
 
1278
    <xsl:when test="$numeration = 'arabic'">loweralpha</xsl:when>
 
1279
    <xsl:when test="$numeration = 'loweralpha'">lowerroman</xsl:when>
 
1280
    <xsl:when test="$numeration = 'lowerroman'">upperalpha</xsl:when>
 
1281
    <xsl:when test="$numeration = 'upperalpha'">upperroman</xsl:when>
 
1282
    <xsl:when test="$numeration = 'upperroman'">arabic</xsl:when>
 
1283
    <xsl:otherwise>arabic</xsl:otherwise>
 
1284
  </xsl:choose>
 
1285
</xsl:template>
 
1286
 
 
1287
<xsl:template name="list.numeration">
 
1288
  <xsl:param name="node" select="."/>
 
1289
 
 
1290
  <xsl:choose>
 
1291
    <xsl:when test="$node/@numeration">
 
1292
      <xsl:value-of select="$node/@numeration"/>
 
1293
    </xsl:when>
 
1294
    <xsl:otherwise>
 
1295
      <xsl:choose>
 
1296
        <xsl:when test="$node/ancestor::orderedlist">
 
1297
          <xsl:call-template name="next.numeration">
 
1298
            <xsl:with-param name="numeration">
 
1299
              <xsl:call-template name="list.numeration">
 
1300
                <xsl:with-param name="node" select="$node/ancestor::orderedlist[1]"/>
 
1301
              </xsl:call-template>
 
1302
            </xsl:with-param>
 
1303
          </xsl:call-template>
 
1304
        </xsl:when>
 
1305
        <xsl:otherwise>
 
1306
          <xsl:call-template name="next.numeration"/>
 
1307
        </xsl:otherwise>
 
1308
      </xsl:choose>
 
1309
    </xsl:otherwise>
 
1310
  </xsl:choose>
 
1311
</xsl:template>
 
1312
 
 
1313
<!-- ====================================================================== -->
 
1314
<!-- ItemizedList "Numeration" -->
 
1315
 
 
1316
<xsl:template name="next.itemsymbol">
 
1317
  <xsl:param name="itemsymbol" select="'default'"/>
 
1318
  <xsl:choose>
 
1319
    <!-- Change this list if you want to change the order of symbols -->
 
1320
    <xsl:when test="$itemsymbol = 'disc'">circle</xsl:when>
 
1321
    <xsl:when test="$itemsymbol = 'round'">square</xsl:when>
 
1322
    <xsl:otherwise>disc</xsl:otherwise>
 
1323
  </xsl:choose>
 
1324
</xsl:template>
 
1325
 
 
1326
<xsl:template name="list.itemsymbol">
 
1327
  <xsl:param name="node" select="."/>
 
1328
 
 
1329
  <xsl:choose>
 
1330
    <xsl:when test="$node/@mark">
 
1331
      <xsl:value-of select="$node/@mark"/>
 
1332
    </xsl:when>
 
1333
    <xsl:otherwise>
 
1334
      <xsl:choose>
 
1335
        <xsl:when test="$node/ancestor::itemizedlist">
 
1336
          <xsl:call-template name="next.itemsymbol">
 
1337
            <xsl:with-param name="itemsymbol">
 
1338
              <xsl:call-template name="list.itemsymbol">
 
1339
                <xsl:with-param name="node" select="$node/ancestor::itemizedlist[1]"/>
 
1340
              </xsl:call-template>
 
1341
            </xsl:with-param>
 
1342
          </xsl:call-template>
 
1343
        </xsl:when>
 
1344
        <xsl:otherwise>
 
1345
          <xsl:call-template name="next.itemsymbol"/>
 
1346
        </xsl:otherwise>
 
1347
      </xsl:choose>
 
1348
    </xsl:otherwise>
 
1349
  </xsl:choose>
 
1350
</xsl:template>
 
1351
 
 
1352
<!-- ====================================================================== -->
 
1353
 
 
1354
<doc:template name="copyright.years" xmlns="">
 
1355
<refpurpose>Print a set of years with collapsed ranges</refpurpose>
 
1356
 
 
1357
<refdescription>
 
1358
<para>This template prints a list of year elements with consecutive
 
1359
years printed as a range. In other words:</para>
 
1360
 
 
1361
<screen><![CDATA[<year>1992</year>
 
1362
<year>1993</year>
 
1363
<year>1994</year>]]></screen>
 
1364
 
 
1365
<para>is printed <quote>1992-1994</quote>, whereas:</para>
 
1366
 
 
1367
<screen><![CDATA[<year>1992</year>
 
1368
<year>1994</year>]]></screen>
 
1369
 
 
1370
<para>is printed <quote>1992, 1994</quote>.</para>
 
1371
 
 
1372
<para>This template assumes that all the year elements contain only
 
1373
decimal year numbers, that the elements are sorted in increasing
 
1374
numerical order, that there are no duplicates, and that all the years
 
1375
are expressed in full <quote>century+year</quote>
 
1376
(<quote>1999</quote> not <quote>99</quote>) notation.</para>
 
1377
</refdescription>
 
1378
 
 
1379
<refparameter>
 
1380
<variablelist>
 
1381
<varlistentry><term>years</term>
 
1382
<listitem>
 
1383
<para>The initial set of year elements.</para>
 
1384
</listitem>
 
1385
</varlistentry>
 
1386
<varlistentry><term>print.ranges</term>
 
1387
<listitem>
 
1388
<para>If non-zero, multi-year ranges are collapsed. If zero, all years
 
1389
are printed discretely.</para>
 
1390
</listitem>
 
1391
</varlistentry>
 
1392
<varlistentry><term>single.year.ranges</term>
 
1393
<listitem>
 
1394
<para>If non-zero, two consecutive years will be printed as a range,
 
1395
otherwise, they will be printed discretely. In other words, a single
 
1396
year range is <quote>1991-1992</quote> but discretely it's
 
1397
<quote>1991, 1992</quote>.</para>
 
1398
</listitem>
 
1399
</varlistentry>
 
1400
</variablelist>
 
1401
</refparameter>
 
1402
 
 
1403
<refreturn>
 
1404
<para>This template returns the formatted list of years.</para>
 
1405
</refreturn>
 
1406
</doc:template>
 
1407
 
 
1408
<xsl:template name="copyright.years">
 
1409
  <xsl:param name="years"/>
 
1410
  <xsl:param name="print.ranges" select="1"/>
 
1411
  <xsl:param name="single.year.ranges" select="0"/>
 
1412
  <xsl:param name="firstyear" select="0"/>
 
1413
  <xsl:param name="nextyear" select="0"/>
 
1414
 
 
1415
  <!--
 
1416
  <xsl:message terminate="no">
 
1417
    <xsl:text>CY: </xsl:text>
 
1418
    <xsl:value-of select="count($years)"/>
 
1419
    <xsl:text>, </xsl:text>
 
1420
    <xsl:value-of select="$firstyear"/>
 
1421
    <xsl:text>, </xsl:text>
 
1422
    <xsl:value-of select="$nextyear"/>
 
1423
    <xsl:text>, </xsl:text>
 
1424
    <xsl:value-of select="$print.ranges"/>
 
1425
    <xsl:text>, </xsl:text>
 
1426
    <xsl:value-of select="$single.year.ranges"/>
 
1427
    <xsl:text> (</xsl:text>
 
1428
    <xsl:value-of select="$years[1]"/>
 
1429
    <xsl:text>)</xsl:text>
 
1430
  </xsl:message>
 
1431
  -->
 
1432
 
 
1433
  <xsl:choose>
 
1434
    <xsl:when test="$print.ranges = 0 and count($years) &gt; 0">
 
1435
      <xsl:choose>
 
1436
        <xsl:when test="count($years) = 1">
 
1437
          <xsl:apply-templates select="$years[1]" mode="titlepage.mode"/>
 
1438
        </xsl:when>
 
1439
        <xsl:otherwise>
 
1440
          <xsl:apply-templates select="$years[1]" mode="titlepage.mode"/>
 
1441
          <xsl:text>, </xsl:text>
 
1442
          <xsl:call-template name="copyright.years">
 
1443
            <xsl:with-param name="years"
 
1444
                            select="$years[position() &gt; 1]"/>
 
1445
            <xsl:with-param name="print.ranges" select="$print.ranges"/>
 
1446
            <xsl:with-param name="single.year.ranges"
 
1447
                            select="$single.year.ranges"/>
 
1448
          </xsl:call-template>
 
1449
        </xsl:otherwise>
 
1450
      </xsl:choose>
 
1451
    </xsl:when>
 
1452
    <xsl:when test="count($years) = 0">
 
1453
      <xsl:variable name="lastyear" select="$nextyear - 1"/>
 
1454
      <xsl:choose>
 
1455
        <xsl:when test="$firstyear = 0">
 
1456
          <!-- there weren't any years at all -->
 
1457
        </xsl:when>
 
1458
        <xsl:when test="$firstyear = $lastyear">
 
1459
          <xsl:value-of select="$firstyear"/>
 
1460
        </xsl:when>
 
1461
        <xsl:when test="$single.year.ranges = 0
 
1462
                        and $lastyear = $firstyear + 1">
 
1463
          <xsl:value-of select="$firstyear"/>
 
1464
          <xsl:text>, </xsl:text>
 
1465
          <xsl:value-of select="$lastyear"/>
 
1466
        </xsl:when>
 
1467
        <xsl:otherwise>
 
1468
          <xsl:value-of select="$firstyear"/>
 
1469
          <xsl:text>-</xsl:text>
 
1470
          <xsl:value-of select="$lastyear"/>
 
1471
        </xsl:otherwise>
 
1472
      </xsl:choose>
 
1473
    </xsl:when>
 
1474
    <xsl:when test="$firstyear = 0">
 
1475
      <xsl:call-template name="copyright.years">
 
1476
        <xsl:with-param name="years"
 
1477
                        select="$years[position() &gt; 1]"/>
 
1478
        <xsl:with-param name="firstyear" select="$years[1]"/>
 
1479
        <xsl:with-param name="nextyear" select="$years[1] + 1"/>
 
1480
        <xsl:with-param name="print.ranges" select="$print.ranges"/>
 
1481
        <xsl:with-param name="single.year.ranges"
 
1482
                        select="$single.year.ranges"/>
 
1483
      </xsl:call-template>
 
1484
    </xsl:when>
 
1485
    <xsl:when test="$nextyear = $years[1]">
 
1486
      <xsl:call-template name="copyright.years">
 
1487
        <xsl:with-param name="years"
 
1488
                        select="$years[position() &gt; 1]"/>
 
1489
        <xsl:with-param name="firstyear" select="$firstyear"/>
 
1490
        <xsl:with-param name="nextyear" select="$nextyear + 1"/>
 
1491
        <xsl:with-param name="print.ranges" select="$print.ranges"/>
 
1492
        <xsl:with-param name="single.year.ranges"
 
1493
                        select="$single.year.ranges"/>
 
1494
      </xsl:call-template>
 
1495
    </xsl:when>
 
1496
    <xsl:otherwise>
 
1497
      <!-- we have years left, but they aren't in the current range -->
 
1498
      <xsl:choose>
 
1499
        <xsl:when test="$nextyear = $firstyear + 1">
 
1500
          <xsl:value-of select="$firstyear"/>
 
1501
          <xsl:text>, </xsl:text>
 
1502
        </xsl:when>
 
1503
        <xsl:when test="$single.year.ranges = 0
 
1504
                        and $nextyear = $firstyear + 2">
 
1505
          <xsl:value-of select="$firstyear"/>
 
1506
          <xsl:text>, </xsl:text>
 
1507
          <xsl:value-of select="$nextyear - 1"/>
 
1508
          <xsl:text>, </xsl:text>
 
1509
        </xsl:when>
 
1510
        <xsl:otherwise>
 
1511
          <xsl:value-of select="$firstyear"/>
 
1512
          <xsl:text>-</xsl:text>
 
1513
          <xsl:value-of select="$nextyear - 1"/>
 
1514
          <xsl:text>, </xsl:text>
 
1515
        </xsl:otherwise>
 
1516
      </xsl:choose>
 
1517
      <xsl:call-template name="copyright.years">
 
1518
        <xsl:with-param name="years"
 
1519
                        select="$years[position() &gt; 1]"/>
 
1520
        <xsl:with-param name="firstyear" select="$years[1]"/>
 
1521
        <xsl:with-param name="nextyear" select="$years[1] + 1"/>
 
1522
        <xsl:with-param name="print.ranges" select="$print.ranges"/>
 
1523
        <xsl:with-param name="single.year.ranges"
 
1524
                        select="$single.year.ranges"/>
 
1525
      </xsl:call-template>
 
1526
    </xsl:otherwise>
 
1527
  </xsl:choose>
 
1528
</xsl:template>
 
1529
 
 
1530
<!-- ====================================================================== -->
 
1531
 
 
1532
<doc:template name="find.path.params" xmlns="">
 
1533
<refpurpose>Search in a table for the "best" match for the node</refpurpose>
 
1534
 
 
1535
<refdescription>
 
1536
<para>This template searches in a table for the value that most-closely
 
1537
(in the typical best-match sense of XSLT) matches the current (element)
 
1538
node location.</para>
 
1539
</refdescription>
 
1540
</doc:template>
 
1541
 
 
1542
<xsl:template name="find.path.params">
 
1543
  <xsl:param name="node" select="."/>
 
1544
  <xsl:param name="table" select="''"/>
 
1545
  <xsl:param name="location">
 
1546
    <xsl:call-template name="xpath.location">
 
1547
      <xsl:with-param name="node" select="$node"/>
 
1548
    </xsl:call-template>
 
1549
  </xsl:param>
 
1550
 
 
1551
  <xsl:variable name="value">
 
1552
    <xsl:call-template name="lookup.key">
 
1553
      <xsl:with-param name="key" select="$location"/>
 
1554
      <xsl:with-param name="table" select="$table"/>
 
1555
    </xsl:call-template>
 
1556
  </xsl:variable>
 
1557
 
 
1558
  <xsl:choose>
 
1559
    <xsl:when test="$value != ''">
 
1560
      <xsl:value-of select="$value"/>
 
1561
    </xsl:when>
 
1562
    <xsl:when test="contains($location, '/')">
 
1563
      <xsl:call-template name="find.path.params">
 
1564
        <xsl:with-param name="node" select="$node"/>
 
1565
        <xsl:with-param name="table" select="$table"/>
 
1566
        <xsl:with-param name="location" select="substring-after($location, '/')"/>
 
1567
      </xsl:call-template>
 
1568
    </xsl:when>
 
1569
  </xsl:choose>
 
1570
</xsl:template>
 
1571
 
 
1572
</xsl:stylesheet>
 
1573