Project

General

Profile

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: labels.xsl 8350 2009-03-17 07:24:29Z bobstayton $
9
     ********************************************************************
10

    
11
     This file is part of the XSL DocBook Stylesheet distribution.
12
     See ../README or http://docbook.sf.net/release/xsl/current/ for
13
     copyright and other information.
14

    
15
     ******************************************************************** -->
16

    
17
<!-- ==================================================================== -->
18

    
19
<!-- label markup -->
20

    
21
<doc:mode mode="label.markup" xmlns="">
22
<refpurpose>Provides access to element labels</refpurpose>
23
<refdescription id="label.markup-desc">
24
<para>Processing an element in the
25
<literal role="mode">label.markup</literal> mode produces the
26
element label.</para>
27
<para>Trailing punctuation is not added to the label.
28
</para>
29
</refdescription>
30
</doc:mode>
31

    
32
<xsl:template match="*" mode="intralabel.punctuation">
33
  <xsl:text>.</xsl:text>
34
</xsl:template>
35

    
36
<xsl:template match="*" mode="label.markup">
37
  <xsl:param name="verbose" select="1"/>
38
  <xsl:if test="$verbose">
39
    <xsl:message>
40
      <xsl:text>Request for label of unexpected element: </xsl:text>
41
      <xsl:value-of select="local-name(.)"/>
42
    </xsl:message>
43
  </xsl:if>
44
</xsl:template>
45

    
46
<xsl:template match="set|book" mode="label.markup">
47
  <xsl:if test="@label">
48
    <xsl:value-of select="@label"/>
49
  </xsl:if>
50
</xsl:template>
51

    
52
<xsl:template match="part" mode="label.markup">
53
  <xsl:choose>
54
    <xsl:when test="@label">
55
      <xsl:value-of select="@label"/>
56
    </xsl:when>
57
    <xsl:when test="string($part.autolabel) != 0">
58
      <xsl:variable name="format">
59
        <xsl:call-template name="autolabel.format">
60
          <xsl:with-param name="format" select="$part.autolabel"/>
61
        </xsl:call-template>
62
      </xsl:variable>
63
      <xsl:number from="book" count="part" format="{$format}"/>
64
    </xsl:when>
65
  </xsl:choose>
66
</xsl:template>
67

    
68
<xsl:template match="partintro" mode="label.markup">
69
  <!-- no label -->
70
</xsl:template>
71

    
72
<xsl:template match="preface" mode="label.markup">
73
  <xsl:choose>
74
    <xsl:when test="@label">
75
      <xsl:value-of select="@label"/>
76
    </xsl:when>
77
    <xsl:when test="string($preface.autolabel) != 0">
78
      <xsl:if test="$component.label.includes.part.label != 0 and
79
                      ancestor::part">
80
        <xsl:variable name="part.label">
81
          <xsl:apply-templates select="ancestor::part" 
82
                               mode="label.markup"/>
83
        </xsl:variable>
84
        <xsl:if test="$part.label != ''">
85
          <xsl:value-of select="$part.label"/>
86
          <xsl:apply-templates select="ancestor::part" 
87
                               mode="intralabel.punctuation"/>
88
        </xsl:if>
89
      </xsl:if>
90
      <xsl:variable name="format">
91
        <xsl:call-template name="autolabel.format">
92
          <xsl:with-param name="format" select="$preface.autolabel"/>
93
        </xsl:call-template>
94
      </xsl:variable>
95
      <xsl:choose>
96
        <xsl:when test="$label.from.part != 0 and ancestor::part">
97
          <xsl:number from="part" count="preface" format="{$format}" level="any"/>
98
        </xsl:when>
99
        <xsl:otherwise>
100
          <xsl:number from="book" count="preface" format="{$format}" level="any"/>
101
        </xsl:otherwise>
102
      </xsl:choose>
103
    </xsl:when>
104
  </xsl:choose>
105
</xsl:template>
106

    
107
<xsl:template match="chapter" mode="label.markup">
108
  <xsl:choose>
109
    <xsl:when test="@label">
110
      <xsl:value-of select="@label"/>
111
    </xsl:when>
112
    <xsl:when test="string($chapter.autolabel) != 0">
113
      <xsl:if test="$component.label.includes.part.label != 0 and
114
                      ancestor::part">
115
        <xsl:variable name="part.label">
116
          <xsl:apply-templates select="ancestor::part" 
117
                               mode="label.markup"/>
118
        </xsl:variable>
119
        <xsl:if test="$part.label != ''">
120
          <xsl:value-of select="$part.label"/>
121
          <xsl:apply-templates select="ancestor::part" 
122
                               mode="intralabel.punctuation"/>
123
        </xsl:if>
124
      </xsl:if>
125
      <xsl:variable name="format">
126
        <xsl:call-template name="autolabel.format">
127
          <xsl:with-param name="format" select="$chapter.autolabel"/>
128
        </xsl:call-template>
129
      </xsl:variable>
130
      <xsl:choose>
131
        <xsl:when test="$label.from.part != 0 and ancestor::part">
132
          <xsl:number from="part" count="chapter" format="{$format}" level="any"/>
133
        </xsl:when>
134
        <xsl:otherwise>
135
          <xsl:number from="book" count="chapter" format="{$format}" level="any"/>
136
        </xsl:otherwise>
137
      </xsl:choose>
138
    </xsl:when>
139
  </xsl:choose>
140
</xsl:template>
141

    
142
<xsl:template match="appendix" mode="label.markup">
143
  <xsl:choose>
144
    <xsl:when test="@label">
145
      <xsl:value-of select="@label"/>
146
    </xsl:when>
147
    <xsl:when test="string($appendix.autolabel) != 0">
148
      <xsl:if test="$component.label.includes.part.label != 0 and
149
                      ancestor::part">
150
        <xsl:variable name="part.label">
151
          <xsl:apply-templates select="ancestor::part" 
152
                               mode="label.markup"/>
153
        </xsl:variable>
154
        <xsl:if test="$part.label != ''">
155
          <xsl:value-of select="$part.label"/>
156
          <xsl:apply-templates select="ancestor::part" 
157
                               mode="intralabel.punctuation"/>
158
        </xsl:if>
159
      </xsl:if>
160
      <xsl:variable name="format">
161
        <xsl:call-template name="autolabel.format">
162
          <xsl:with-param name="format" select="$appendix.autolabel"/>
163
        </xsl:call-template>
164
      </xsl:variable>
165
      <xsl:choose>
166
        <xsl:when test="$label.from.part != 0 and ancestor::part">
167
          <xsl:number from="part" count="appendix" format="{$format}" level="any"/>
168
        </xsl:when>
169
        <xsl:otherwise>
170
          <xsl:number from="book|article"
171
                      count="appendix" format="{$format}" level="any"/>
172
        </xsl:otherwise>
173
      </xsl:choose>
174
    </xsl:when>
175
  </xsl:choose>
176
</xsl:template>
177

    
178
<xsl:template match="article" mode="label.markup">
179
  <xsl:if test="@label">
180
    <xsl:value-of select="@label"/>
181
  </xsl:if>
182
</xsl:template>
183

    
184
<xsl:template match="dedication|colophon" mode="label.markup">
185
  <xsl:if test="@label">
186
    <xsl:value-of select="@label"/>
187
  </xsl:if>
188
</xsl:template>
189

    
190
<xsl:template match="reference" mode="label.markup">
191
  <xsl:choose>
192
    <xsl:when test="@label">
193
      <xsl:value-of select="@label"/>
194
    </xsl:when>
195
    <xsl:when test="string($reference.autolabel) != 0">
196
      <xsl:if test="$component.label.includes.part.label != 0 and
197
                      ancestor::part">
198
        <xsl:variable name="part.label">
199
          <xsl:apply-templates select="ancestor::part" 
200
                               mode="label.markup"/>
201
        </xsl:variable>
202
        <xsl:if test="$part.label != ''">
203
          <xsl:value-of select="$part.label"/>
204
          <xsl:apply-templates select="ancestor::part" 
205
                               mode="intralabel.punctuation"/>
206
        </xsl:if>
207
      </xsl:if>
208
      <xsl:variable name="format">
209
        <xsl:call-template name="autolabel.format">
210
          <xsl:with-param name="format" select="$reference.autolabel"/>
211
        </xsl:call-template>
212
      </xsl:variable>
213
      <xsl:choose>
214
        <xsl:when test="$label.from.part != 0 and ancestor::part">
215
          <xsl:number from="part" count="reference" format="{$format}" level="any"/>
216
        </xsl:when>
217
        <xsl:otherwise>
218
          <xsl:number from="book" count="reference" format="{$format}" level="any"/>
219
        </xsl:otherwise>
220
      </xsl:choose>
221
    </xsl:when>
222
  </xsl:choose>
223
</xsl:template>
224

    
225
<xsl:template match="refentry" mode="label.markup">
226
  <xsl:if test="@label">
227
    <xsl:value-of select="@label"/>
228
  </xsl:if>
229
</xsl:template>
230

    
231
<xsl:template match="section" mode="label.markup">
232
  <!-- if this is a nested section, label the parent -->
233
  <xsl:if test="local-name(..) = 'section'">
234
    <xsl:variable name="parent.section.label">
235
      <xsl:call-template name="label.this.section">
236
        <xsl:with-param name="section" select=".."/>
237
      </xsl:call-template>
238
    </xsl:variable>
239
    <xsl:if test="$parent.section.label != '0'">
240
      <xsl:apply-templates select=".." mode="label.markup"/>
241
      <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
242
    </xsl:if>
243
  </xsl:if>
244

    
245
  <!-- if the parent is a component, maybe label that too -->
246
  <xsl:variable name="parent.is.component">
247
    <xsl:call-template name="is.component">
248
      <xsl:with-param name="node" select=".."/>
249
    </xsl:call-template>
250
  </xsl:variable>
251

    
252
  <!-- does this section get labelled? -->
253
  <xsl:variable name="label">
254
    <xsl:call-template name="label.this.section">
255
      <xsl:with-param name="section" select="."/>
256
    </xsl:call-template>
257
  </xsl:variable>
258

    
259
  <xsl:if test="$section.label.includes.component.label != 0
260
                and $parent.is.component != 0">
261
    <xsl:variable name="parent.label">
262
      <xsl:apply-templates select=".." mode="label.markup"/>
263
    </xsl:variable>
264
    <xsl:if test="$parent.label != ''">
265
      <xsl:apply-templates select=".." mode="label.markup"/>
266
      <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
267
    </xsl:if>
268
  </xsl:if>
269

    
270
<!--
271
  <xsl:message>
272
    test: <xsl:value-of select="$label"/>, <xsl:number count="section"/>
273
  </xsl:message>
274
-->
275

    
276
  <xsl:choose>
277
    <xsl:when test="@label">
278
      <xsl:value-of select="@label"/>
279
    </xsl:when>
280
    <xsl:when test="$label != 0">      
281
      <xsl:variable name="format">
282
        <xsl:call-template name="autolabel.format">
283
          <xsl:with-param name="format" select="$section.autolabel"/>
284
        </xsl:call-template>
285
      </xsl:variable>
286
      <xsl:number format="{$format}" count="section"/>
287
    </xsl:when>
288
  </xsl:choose>
289
</xsl:template>
290

    
291
<xsl:template match="sect1" mode="label.markup">
292
  <!-- if the parent is a component, maybe label that too -->
293
  <xsl:variable name="parent.is.component">
294
    <xsl:call-template name="is.component">
295
      <xsl:with-param name="node" select=".."/>
296
    </xsl:call-template>
297
  </xsl:variable>
298

    
299
  <xsl:variable name="component.label">
300
    <xsl:if test="$section.label.includes.component.label != 0
301
                  and $parent.is.component != 0">
302
      <xsl:variable name="parent.label">
303
        <xsl:apply-templates select=".." mode="label.markup"/>
304
      </xsl:variable>
305
      <xsl:if test="$parent.label != ''">
306
        <xsl:apply-templates select=".." mode="label.markup"/>
307
        <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
308
      </xsl:if>
309
    </xsl:if>
310
  </xsl:variable>
311

    
312

    
313
  <xsl:variable name="is.numbered">
314
    <xsl:call-template name="label.this.section"/>
315
  </xsl:variable>
316

    
317
  <xsl:choose>
318
    <xsl:when test="@label">
319
      <xsl:value-of select="@label"/>
320
    </xsl:when>
321
    <xsl:when test="$is.numbered != 0">
322
      <xsl:variable name="format">
323
        <xsl:call-template name="autolabel.format">
324
          <xsl:with-param name="format" select="$section.autolabel"/>
325
        </xsl:call-template>
326
      </xsl:variable>
327
      <xsl:copy-of select="$component.label"/>
328
      <xsl:number format="{$format}" count="sect1"/>
329
    </xsl:when>
330
  </xsl:choose>
331
</xsl:template>
332

    
333
<xsl:template match="sect2|sect3|sect4|sect5" mode="label.markup">
334
  <!-- label the parent -->
335
  <xsl:variable name="parent.section.label">
336
    <xsl:call-template name="label.this.section">
337
      <xsl:with-param name="section" select=".."/>
338
    </xsl:call-template>
339
  </xsl:variable>
340
  <xsl:if test="$parent.section.label != '0'">
341
    <xsl:apply-templates select=".." mode="label.markup"/>
342
    <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
343
  </xsl:if>
344

    
345
  <xsl:variable name="is.numbered">
346
    <xsl:call-template name="label.this.section"/>
347
  </xsl:variable>
348

    
349
  <xsl:choose>
350
    <xsl:when test="@label">
351
      <xsl:value-of select="@label"/>
352
    </xsl:when>
353
    <xsl:when test="$is.numbered != 0">
354
      <xsl:variable name="format">
355
        <xsl:call-template name="autolabel.format">
356
          <xsl:with-param name="format" select="$section.autolabel"/>
357
        </xsl:call-template>
358
      </xsl:variable>
359
      <xsl:choose>
360
        <xsl:when test="local-name(.) = 'sect2'">
361
          <xsl:number format="{$format}" count="sect2"/>
362
        </xsl:when>
363
        <xsl:when test="local-name(.) = 'sect3'">
364
          <xsl:number format="{$format}" count="sect3"/>
365
        </xsl:when>
366
        <xsl:when test="local-name(.) = 'sect4'">
367
          <xsl:number format="{$format}" count="sect4"/>
368
        </xsl:when>
369
        <xsl:when test="local-name(.) = 'sect5'">
370
          <xsl:number format="{$format}" count="sect5"/>
371
        </xsl:when>
372
        <xsl:otherwise>
373
          <xsl:message>label.markup: this can't happen!</xsl:message>
374
        </xsl:otherwise>
375
      </xsl:choose>
376
    </xsl:when>
377
  </xsl:choose>
378
</xsl:template>
379

    
380
<xsl:template match="bridgehead" mode="label.markup">
381
  <!-- FIXME: could we do a better job here? -->
382
  <xsl:variable name="contsec"
383
                select="(ancestor::section
384
                         |ancestor::simplesect
385
                         |ancestor::sect1
386
                         |ancestor::sect2
387
                         |ancestor::sect3
388
                         |ancestor::sect4
389
                         |ancestor::sect5
390
                         |ancestor::refsect1
391
                         |ancestor::refsect2
392
                         |ancestor::refsect3
393
                         |ancestor::chapter
394
                         |ancestor::appendix
395
                         |ancestor::preface)[last()]"/>
396

    
397
  <xsl:apply-templates select="$contsec" mode="label.markup"/>
398
</xsl:template>
399

    
400
<xsl:template match="refsect1" mode="label.markup">
401
  <xsl:choose>
402
    <xsl:when test="@label">
403
      <xsl:value-of select="@label"/>
404
    </xsl:when>
405
    <xsl:when test="$section.autolabel != 0">
406
      <xsl:variable name="format">
407
        <xsl:call-template name="autolabel.format">
408
          <xsl:with-param name="format" select="$section.autolabel"/>
409
        </xsl:call-template>
410
      </xsl:variable>
411
      <xsl:number count="refsect1" format="{$format}"/>
412
    </xsl:when>
413
  </xsl:choose>
414
</xsl:template>
415

    
416
<xsl:template match="refsect2|refsect3" mode="label.markup">
417
  <!-- label the parent -->
418
  <xsl:variable name="parent.label">
419
    <xsl:apply-templates select=".." mode="label.markup"/>
420
  </xsl:variable>
421
  <xsl:if test="$parent.label != ''">
422
    <xsl:apply-templates select=".." mode="label.markup"/>
423
    <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
424
  </xsl:if>
425

    
426
  <xsl:choose>
427
    <xsl:when test="@label">
428
      <xsl:value-of select="@label"/>
429
    </xsl:when>
430
    <xsl:when test="$section.autolabel != 0">
431
      <xsl:variable name="format">
432
        <xsl:call-template name="autolabel.format">
433
          <xsl:with-param name="format" select="$section.autolabel"/>
434
        </xsl:call-template>
435
      </xsl:variable>
436
      <xsl:choose>
437
        <xsl:when test="local-name(.) = 'refsect2'">
438
          <xsl:number count="refsect2" format="{$format}"/>
439
        </xsl:when>
440
        <xsl:otherwise>
441
          <xsl:number count="refsect3" format="{$format}"/>
442
        </xsl:otherwise>
443
      </xsl:choose>
444
    </xsl:when>
445
  </xsl:choose>
446
</xsl:template>
447

    
448
<xsl:template match="simplesect" mode="label.markup">
449
  <!-- if this is a nested section, label the parent -->
450
  <xsl:if test="local-name(..) = 'section'
451
                or local-name(..) = 'sect1'
452
                or local-name(..) = 'sect2'
453
                or local-name(..) = 'sect3'
454
                or local-name(..) = 'sect4'
455
                or local-name(..) = 'sect5'">
456
    <xsl:variable name="parent.section.label">
457
      <xsl:apply-templates select=".." mode="label.markup"/>
458
    </xsl:variable>
459
    <xsl:if test="$parent.section.label != ''">
460
      <xsl:apply-templates select=".." mode="label.markup"/>
461
      <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
462
    </xsl:if>
463
  </xsl:if>
464

    
465
  <!-- if the parent is a component, maybe label that too -->
466
  <xsl:variable name="parent.is.component">
467
    <xsl:call-template name="is.component">
468
      <xsl:with-param name="node" select=".."/>
469
    </xsl:call-template>
470
  </xsl:variable>
471

    
472
  <!-- does this section get labelled? -->
473
  <xsl:variable name="label">
474
    <xsl:call-template name="label.this.section">
475
      <xsl:with-param name="section" select="."/>
476
    </xsl:call-template>
477
  </xsl:variable>
478

    
479
  <xsl:if test="$section.label.includes.component.label != 0
480
                and $parent.is.component != 0">
481
    <xsl:variable name="parent.label">
482
      <xsl:apply-templates select=".." mode="label.markup"/>
483
    </xsl:variable>
484
    <xsl:if test="$parent.label != ''">
485
      <xsl:apply-templates select=".." mode="label.markup"/>
486
      <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
487
    </xsl:if>
488
  </xsl:if>
489

    
490
  <xsl:choose>
491
    <xsl:when test="@label">
492
      <xsl:value-of select="@label"/>
493
    </xsl:when>
494
    <xsl:when test="$label != 0">
495
      <xsl:variable name="format">
496
        <xsl:call-template name="autolabel.format">
497
          <xsl:with-param name="format" select="$section.autolabel"/>
498
        </xsl:call-template>
499
      </xsl:variable>
500
      <xsl:number format="{$format}" count="simplesect"/>
501
    </xsl:when>
502
  </xsl:choose>
503
</xsl:template>
504

    
505
<xsl:template match="qandadiv" mode="label.markup">
506
  <xsl:variable name="lparent" select="(ancestor::set
507
                                       |ancestor::book
508
                                       |ancestor::chapter
509
                                       |ancestor::appendix
510
                                       |ancestor::preface
511
                                       |ancestor::section
512
                                       |ancestor::simplesect
513
                                       |ancestor::sect1
514
                                       |ancestor::sect2
515
                                       |ancestor::sect3
516
                                       |ancestor::sect4
517
                                       |ancestor::sect5
518
                                       |ancestor::refsect1
519
                                       |ancestor::refsect2
520
                                       |ancestor::refsect3)[last()]"/>
521

    
522
  <xsl:variable name="lparent.prefix">
523
    <xsl:apply-templates select="$lparent" mode="label.markup"/>
524
  </xsl:variable>
525

    
526
  <xsl:variable name="prefix">
527
    <xsl:if test="$qanda.inherit.numeration != 0">
528
      <xsl:if test="$lparent.prefix != ''">
529
        <xsl:apply-templates select="$lparent" mode="label.markup"/>
530
        <xsl:apply-templates select="$lparent" mode="intralabel.punctuation"/>
531
      </xsl:if>
532
    </xsl:if>
533
  </xsl:variable>
534

    
535
  <xsl:choose>
536
    <xsl:when test="$qandadiv.autolabel != 0">
537
      <xsl:variable name="format">
538
        <xsl:call-template name="autolabel.format">
539
          <xsl:with-param name="format" select="$qandadiv.autolabel"/>
540
        </xsl:call-template>
541
      </xsl:variable>
542
      <xsl:value-of select="$prefix"/>
543
      <xsl:number level="multiple" count="qandadiv" format="{$format}"/>
544
    </xsl:when>
545
  </xsl:choose>
546
</xsl:template>
547

    
548
<xsl:template match="question|answer" mode="label.markup">
549
  <xsl:variable name="lparent" select="(ancestor::set
550
                                       |ancestor::book
551
                                       |ancestor::chapter
552
                                       |ancestor::appendix
553
                                       |ancestor::preface
554
                                       |ancestor::section
555
                                       |ancestor::simplesect
556
                                       |ancestor::sect1
557
                                       |ancestor::sect2
558
                                       |ancestor::sect3
559
                                       |ancestor::sect4
560
                                       |ancestor::sect5
561
                                       |ancestor::refsect1
562
                                       |ancestor::refsect2
563
                                       |ancestor::refsect3)[last()]"/>
564

    
565
  <xsl:variable name="lparent.prefix">
566
    <xsl:apply-templates select="$lparent" mode="label.markup"/>
567
  </xsl:variable>
568

    
569
  <xsl:variable name="prefix">
570
    <xsl:if test="$qanda.inherit.numeration != 0">
571
      <xsl:choose>
572
        <xsl:when test="ancestor::qandadiv">
573
          <xsl:variable name="div.label">
574
            <xsl:apply-templates select="ancestor::qandadiv[1]" mode="label.markup"/>
575
          </xsl:variable>
576
          <xsl:if test="string-length($div.label) != 0">
577
            <xsl:copy-of select="$div.label"/>
578
            <xsl:apply-templates select="ancestor::qandadiv[1]"
579
                                 mode="intralabel.punctuation"/>
580
          </xsl:if>
581
        </xsl:when>
582
        <xsl:when test="$lparent.prefix != ''">
583
          <xsl:apply-templates select="$lparent" mode="label.markup"/>
584
          <xsl:apply-templates select="$lparent" mode="intralabel.punctuation"/>
585
        </xsl:when>
586
      </xsl:choose>
587
    </xsl:if>
588
  </xsl:variable>
589

    
590
  <xsl:variable name="inhlabel"
591
                select="ancestor-or-self::qandaset/@defaultlabel[1]"/>
592

    
593
  <xsl:variable name="deflabel">
594
    <xsl:choose>
595
      <xsl:when test="$inhlabel != ''">
596
        <xsl:value-of select="$inhlabel"/>
597
      </xsl:when>
598
      <xsl:otherwise>
599
        <xsl:value-of select="$qanda.defaultlabel"/>
600
      </xsl:otherwise>
601
    </xsl:choose>
602
  </xsl:variable>
603

    
604
  <xsl:variable name="label" select="label"/>
605

    
606
  <xsl:choose>
607
    <xsl:when test="count($label)>0">
608
      <xsl:apply-templates select="$label"/>
609
    </xsl:when>
610

    
611
    <xsl:when test="$deflabel = 'qanda' and self::question">
612
      <xsl:call-template name="gentext">
613
        <xsl:with-param name="key" select="'Question'"/>
614
      </xsl:call-template>
615
    </xsl:when>
616

    
617
    <xsl:when test="$deflabel = 'qanda' and self::answer">
618
      <xsl:call-template name="gentext">
619
        <xsl:with-param name="key" select="'Answer'"/>
620
      </xsl:call-template>
621
    </xsl:when>
622

    
623
    <xsl:when test="($deflabel = 'qnumber' or
624
                     $deflabel = 'qnumberanda') and self::question">
625
      <xsl:call-template name="gentext">
626
        <xsl:with-param name="key" select="'Question'"/>
627
      </xsl:call-template>
628
      <xsl:text>&#xA0;</xsl:text>
629
      <xsl:value-of select="$prefix"/>
630
      <xsl:number level="multiple" count="qandaentry" format="1"/>
631
    </xsl:when>
632

    
633
    <xsl:when test="$deflabel = 'qnumberanda' and self::answer">
634
      <xsl:call-template name="gentext">
635
        <xsl:with-param name="key" select="'Answer'"/>
636
      </xsl:call-template>
637
    </xsl:when>
638

    
639
    <xsl:when test="$deflabel = 'number' and self::question">
640
      <xsl:value-of select="$prefix"/>
641
      <xsl:number level="multiple" count="qandaentry" format="1"/>
642
    </xsl:when>
643
  </xsl:choose>
644
</xsl:template>
645

    
646
<xsl:template match="bibliography|glossary|
647
                     qandaset|index|setindex" mode="label.markup">
648
  <xsl:if test="@label">
649
    <xsl:value-of select="@label"/>
650
  </xsl:if>
651
</xsl:template>
652

    
653
<xsl:template match="figure|table|example" mode="label.markup">
654
  <xsl:variable name="pchap"
655
                select="(ancestor::chapter
656
                        |ancestor::appendix
657
                        |ancestor::article[ancestor::book])[last()]"/>
658

    
659
  <xsl:variable name="prefix">
660
    <xsl:if test="count($pchap) &gt; 0">
661
      <xsl:apply-templates select="$pchap" mode="label.markup"/>
662
    </xsl:if>
663
  </xsl:variable>
664

    
665
  <xsl:choose>
666
    <xsl:when test="@label">
667
      <xsl:value-of select="@label"/>
668
    </xsl:when>
669
    <xsl:otherwise>
670
      <xsl:choose>
671
        <xsl:when test="$prefix != ''">
672
            <xsl:apply-templates select="$pchap" mode="label.markup"/>
673
            <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/>
674
          <xsl:number format="1" from="chapter|appendix" level="any"/>
675
        </xsl:when>
676
        <xsl:otherwise>
677
          <xsl:number format="1" from="book|article" level="any"/>
678
        </xsl:otherwise>
679
      </xsl:choose>
680
    </xsl:otherwise>
681
  </xsl:choose>
682
</xsl:template>
683

    
684
<xsl:template match="procedure" mode="label.markup">
685
  <xsl:variable name="pchap"
686
                select="ancestor::chapter
687
                        |ancestor::appendix
688
                        |ancestor::article[ancestor::book]"/>
689

    
690
  <xsl:variable name="prefix">
691
    <xsl:if test="count($pchap) &gt; 0">
692
      <xsl:apply-templates select="$pchap" mode="label.markup"/>
693
    </xsl:if>
694
  </xsl:variable>
695

    
696
  <xsl:choose>
697
    <xsl:when test="@label">
698
      <xsl:value-of select="@label"/>
699
    </xsl:when>
700
    <xsl:when test="$formal.procedures = 0">
701
      <!-- No label -->
702
    </xsl:when>
703
    <xsl:otherwise>
704
      <xsl:choose>
705
        <xsl:when test="count($pchap)>0">
706
          <xsl:if test="$prefix != ''">
707
            <xsl:apply-templates select="$pchap" mode="label.markup"/>
708
            <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/>
709
          </xsl:if>
710
          <xsl:number count="procedure[title]" format="1" 
711
                      from="chapter|appendix" level="any"/>
712
        </xsl:when>
713
        <xsl:otherwise>
714
          <xsl:number count="procedure[title]" format="1" 
715
                      from="book|article" level="any"/>
716
        </xsl:otherwise>
717
      </xsl:choose>
718
    </xsl:otherwise>
719
  </xsl:choose>
720
</xsl:template>
721

    
722
<xsl:template match="equation" mode="label.markup">
723
  <xsl:variable name="pchap"
724
                select="ancestor::chapter
725
                        |ancestor::appendix
726
                        |ancestor::article[ancestor::book]"/>
727

    
728
  <xsl:variable name="prefix">
729
    <xsl:if test="count($pchap) &gt; 0">
730
      <xsl:apply-templates select="$pchap" mode="label.markup"/>
731
    </xsl:if>
732
  </xsl:variable>
733

    
734
  <xsl:choose>
735
    <xsl:when test="@label">
736
      <xsl:value-of select="@label"/>
737
    </xsl:when>
738
    <xsl:otherwise>
739
      <xsl:choose>
740
        <xsl:when test="count($pchap)>0">
741
          <xsl:if test="$prefix != ''">
742
            <xsl:apply-templates select="$pchap" mode="label.markup"/>
743
            <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/>
744
          </xsl:if>
745
          <xsl:number format="1" count="equation[title or info/title]" 
746
                      from="chapter|appendix" level="any"/>
747
        </xsl:when>
748
        <xsl:otherwise>
749
          <xsl:number format="1" count="equation[title or info/title]" 
750
                      from="book|article" level="any"/>
751
        </xsl:otherwise>
752
      </xsl:choose>
753
    </xsl:otherwise>
754
  </xsl:choose>
755
</xsl:template>
756

    
757
<xsl:template match="orderedlist/listitem" mode="label.markup">
758
  <xsl:variable name="numeration">
759
    <xsl:call-template name="list.numeration">
760
      <xsl:with-param name="node" select="parent::orderedlist"/>
761
    </xsl:call-template>
762
  </xsl:variable>
763

    
764
  <xsl:variable name="type">
765
    <xsl:choose>
766
      <xsl:when test="$numeration='arabic'">1</xsl:when>
767
      <xsl:when test="$numeration='loweralpha'">a</xsl:when>
768
      <xsl:when test="$numeration='lowerroman'">i</xsl:when>
769
      <xsl:when test="$numeration='upperalpha'">A</xsl:when>
770
      <xsl:when test="$numeration='upperroman'">I</xsl:when>
771
      <!-- What!? This should never happen -->
772
      <xsl:otherwise>
773
        <xsl:message>
774
          <xsl:text>Unexpected numeration: </xsl:text>
775
          <xsl:value-of select="$numeration"/>
776
        </xsl:message>
777
        <xsl:value-of select="1."/>
778
      </xsl:otherwise>
779
    </xsl:choose>
780
  </xsl:variable>
781

    
782
  <xsl:variable name="item-number">
783
    <xsl:call-template name="orderedlist-item-number"/>
784
  </xsl:variable>
785

    
786
  <xsl:number value="$item-number" format="{$type}"/>
787
</xsl:template>
788

    
789
<xsl:template match="abstract" mode="label.markup">
790
  <!-- nop -->
791
</xsl:template>
792

    
793
<xsl:template match="sidebar" mode="label.markup">
794
  <!-- nop -->
795
</xsl:template>
796

    
797
<!-- ============================================================ -->
798

    
799
<xsl:template name="label.this.section">
800
  <xsl:param name="section" select="."/>
801

    
802
  <xsl:variable name="level">
803
    <xsl:call-template name="section.level"/>
804
  </xsl:variable>
805

    
806
  <xsl:choose>
807
    <xsl:when test="$level &lt;= $section.autolabel.max.depth">      
808
      <xsl:value-of select="$section.autolabel"/>
809
    </xsl:when>
810
    <xsl:otherwise>0</xsl:otherwise>
811
  </xsl:choose>
812
</xsl:template>
813

    
814
<doc:template name="label.this.section" xmlns="">
815
<refpurpose>Returns true if $section should be labelled</refpurpose>
816
<refdescription id="label.this.section-desc">
817
<para>Returns true if the specified section should be labelled.
818
By default, this template returns zero unless 
819
the section level is less than or equal to the value of the
820
<literal>$section.autolabel.max.depth</literal> parameter, in
821
which case it returns
822
<literal>$section.autolabel</literal>.
823
Custom stylesheets may override it to get more selective behavior.</para>
824
</refdescription>
825
</doc:template>
826

    
827
<!-- ============================================================ -->
828

    
829
<xsl:template name="default.autolabel.format">
830
  <xsl:param name="context" select="."/>
831
  <xsl:choose>
832
    <xsl:when test="local-name($context) = 'appendix'">
833
      <xsl:value-of select="'A'"/>
834
    </xsl:when>
835
    <xsl:when test="local-name($context) = 'part'">
836
      <xsl:value-of select="'I'"/>
837
    </xsl:when>
838
    <xsl:otherwise>1</xsl:otherwise>
839
  </xsl:choose>  
840
</xsl:template>
841
  
842
<xsl:template name="autolabel.format">
843
  <xsl:param name="context" select="."/>
844
  <xsl:param name="format"/>
845

    
846
  <xsl:choose>
847
    <xsl:when test="string($format) != 0">
848
      <xsl:choose>
849
        <xsl:when test="string($format)='arabic' or $format='1'">1</xsl:when>
850
        <xsl:when test="$format='loweralpha' or $format='a'">
851
          <xsl:value-of select="'a'"/>
852
        </xsl:when>
853
        <xsl:when test="$format='lowerroman' or $format='i'">
854
          <xsl:value-of select="'i'"/>
855
        </xsl:when>
856
        <xsl:when test="$format='upperalpha' or $format='A'">
857
          <xsl:value-of select="'A'"/>
858
        </xsl:when>
859
        <xsl:when test="$format='upperroman' or $format='I'">
860
          <xsl:value-of select="'I'"/>
861
        </xsl:when>      
862
        <xsl:when test="$format='arabicindic' or $format='&#x661;'">
863
          <xsl:value-of select="'&#x661;'"/>
864
        </xsl:when>
865
        <xsl:otherwise>
866
          <xsl:message>
867
            <xsl:text>Unexpected </xsl:text><xsl:value-of select="local-name(.)"/><xsl:text>.autolabel value: </xsl:text>
868
            <xsl:value-of select="$format"/><xsl:text>; using default.</xsl:text>
869
          </xsl:message>
870
          <xsl:call-template name="default.autolabel.format"/>
871
        </xsl:otherwise>
872
      </xsl:choose>
873
    </xsl:when>
874
  </xsl:choose>
875
</xsl:template>
876

    
877
<doc:template name="autolabel.format" xmlns="">
878
<refpurpose>Returns format for autolabel parameters</refpurpose>
879
<refdescription id="autolabel.format-desc">
880
<para>Returns format passed as parameter if non zero. Supported
881
  format are 'arabic' or '1', 'loweralpha' or 'a', 'lowerroman' or 'i', 
882
  'upperlapha' or 'A', 'upperroman' or 'I', 'arabicindic' or '&#x661;'.
883
  If its not one of these then 
884
  returns the default format.</para>
885
</refdescription>
886
</doc:template>
887

    
888
<!-- ============================================================ -->
889

    
890
</xsl:stylesheet>
(41-41/78)