Debian Codegraph @

docs/xsl-generic/common/labels.xsl

raw
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 7031 2007-07-14 19:58:59Z xmldoc $
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:apply-templates select="ancestor::qandadiv[1]" mode="label.markup"/>
574 <xsl:apply-templates select="ancestor::qandadiv[1]"
575 mode="intralabel.punctuation"/>
576 </xsl:when>
577 <xsl:when test="$lparent.prefix != ''">
578 <xsl:apply-templates select="$lparent" mode="label.markup"/>
579 <xsl:apply-templates select="$lparent" mode="intralabel.punctuation"/>
580 </xsl:when>
581 </xsl:choose>
582 </xsl:if>
583 </xsl:variable>
584
585 <xsl:variable name="inhlabel"
586 select="ancestor-or-self::qandaset/@defaultlabel[1]"/>
587
588 <xsl:variable name="deflabel">
589 <xsl:choose>
590 <xsl:when test="$inhlabel != ''">
591 <xsl:value-of select="$inhlabel"/>
592 </xsl:when>
593 <xsl:otherwise>
594 <xsl:value-of select="$qanda.defaultlabel"/>
595 </xsl:otherwise>
596 </xsl:choose>
597 </xsl:variable>
598
599 <xsl:variable name="label" select="label"/>
600
601 <xsl:choose>
602 <xsl:when test="count($label)>0">
603 <xsl:apply-templates select="$label"/>
604 </xsl:when>
605
606 <xsl:when test="$deflabel = 'qanda' and local-name(.) = 'question'">
607 <xsl:call-template name="gentext">
608 <xsl:with-param name="key" select="'Question'"/>
609 </xsl:call-template>
610 </xsl:when>
611
612 <xsl:when test="$deflabel = 'qanda' and local-name(.) = 'answer'">
613 <xsl:call-template name="gentext">
614 <xsl:with-param name="key" select="'Answer'"/>
615 </xsl:call-template>
616 </xsl:when>
617
618 <xsl:when test="$deflabel = 'number' and local-name(.) = 'question'">
619 <xsl:value-of select="$prefix"/>
620 <xsl:number level="multiple" count="qandaentry" format="1"/>
621 </xsl:when>
622 </xsl:choose>
623 </xsl:template>
624
625 <xsl:template match="bibliography|glossary|
626 qandaset|index|setindex" mode="label.markup">
627 <xsl:if test="@label">
628 <xsl:value-of select="@label"/>
629 </xsl:if>
630 </xsl:template>
631
632 <xsl:template match="figure|table|example" mode="label.markup">
633 <xsl:variable name="pchap"
634 select="ancestor::chapter
635 |ancestor::appendix
636 |ancestor::article[ancestor::book]"/>
637
638 <xsl:variable name="prefix">
639 <xsl:if test="count($pchap) &gt; 0">
640 <xsl:apply-templates select="$pchap" mode="label.markup"/>
641 </xsl:if>
642 </xsl:variable>
643
644 <xsl:choose>
645 <xsl:when test="@label">
646 <xsl:value-of select="@label"/>
647 </xsl:when>
648 <xsl:otherwise>
649 <xsl:choose>
650 <xsl:when test="$prefix != ''">
651 <xsl:apply-templates select="$pchap" mode="label.markup"/>
652 <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/>
653 <xsl:number format="1" from="chapter|appendix" level="any"/>
654 </xsl:when>
655 <xsl:otherwise>
656 <xsl:number format="1" from="book|article" level="any"/>
657 </xsl:otherwise>
658 </xsl:choose>
659 </xsl:otherwise>
660 </xsl:choose>
661 </xsl:template>
662
663 <xsl:template match="procedure" mode="label.markup">
664 <xsl:variable name="pchap"
665 select="ancestor::chapter
666 |ancestor::appendix
667 |ancestor::article[ancestor::book]"/>
668
669 <xsl:variable name="prefix">
670 <xsl:if test="count($pchap) &gt; 0">
671 <xsl:apply-templates select="$pchap" mode="label.markup"/>
672 </xsl:if>
673 </xsl:variable>
674
675 <xsl:choose>
676 <xsl:when test="@label">
677 <xsl:value-of select="@label"/>
678 </xsl:when>
679 <xsl:when test="$formal.procedures = 0">
680 <!-- No label -->
681 </xsl:when>
682 <xsl:otherwise>
683 <xsl:choose>
684 <xsl:when test="count($pchap)>0">
685 <xsl:if test="$prefix != ''">
686 <xsl:apply-templates select="$pchap" mode="label.markup"/>
687 <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/>
688 </xsl:if>
689 <xsl:number count="procedure[title]" format="1"
690 from="chapter|appendix" level="any"/>
691 </xsl:when>
692 <xsl:otherwise>
693 <xsl:number count="procedure[title]" format="1"
694 from="book|article" level="any"/>
695 </xsl:otherwise>
696 </xsl:choose>
697 </xsl:otherwise>
698 </xsl:choose>
699 </xsl:template>
700
701 <xsl:template match="equation" mode="label.markup">
702 <xsl:variable name="pchap"
703 select="ancestor::chapter
704 |ancestor::appendix
705 |ancestor::article[ancestor::book]"/>
706
707 <xsl:variable name="prefix">
708 <xsl:if test="count($pchap) &gt; 0">
709 <xsl:apply-templates select="$pchap" mode="label.markup"/>
710 </xsl:if>
711 </xsl:variable>
712
713 <xsl:choose>
714 <xsl:when test="@label">
715 <xsl:value-of select="@label"/>
716 </xsl:when>
717 <xsl:otherwise>
718 <xsl:choose>
719 <xsl:when test="count($pchap)>0">
720 <xsl:if test="$prefix != ''">
721 <xsl:apply-templates select="$pchap" mode="label.markup"/>
722 <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/>
723 </xsl:if>
724 <xsl:number format="1" count="equation[title or info/title]"
725 from="chapter|appendix" level="any"/>
726 </xsl:when>
727 <xsl:otherwise>
728 <xsl:number format="1" count="equation[title or info/title]"
729 from="book|article" level="any"/>
730 </xsl:otherwise>
731 </xsl:choose>
732 </xsl:otherwise>
733 </xsl:choose>
734 </xsl:template>
735
736 <xsl:template match="orderedlist/listitem" mode="label.markup">
737 <xsl:variable name="numeration">
738 <xsl:call-template name="list.numeration">
739 <xsl:with-param name="node" select="parent::orderedlist"/>
740 </xsl:call-template>
741 </xsl:variable>
742
743 <xsl:variable name="type">
744 <xsl:choose>
745 <xsl:when test="$numeration='arabic'">1</xsl:when>
746 <xsl:when test="$numeration='loweralpha'">a</xsl:when>
747 <xsl:when test="$numeration='lowerroman'">i</xsl:when>
748 <xsl:when test="$numeration='upperalpha'">A</xsl:when>
749 <xsl:when test="$numeration='upperroman'">I</xsl:when>
750 <!-- What!? This should never happen -->
751 <xsl:otherwise>
752 <xsl:message>
753 <xsl:text>Unexpected numeration: </xsl:text>
754 <xsl:value-of select="$numeration"/>
755 </xsl:message>
756 <xsl:value-of select="1."/>
757 </xsl:otherwise>
758 </xsl:choose>
759 </xsl:variable>
760
761 <xsl:variable name="item-number">
762 <xsl:call-template name="orderedlist-item-number"/>
763 </xsl:variable>
764
765 <xsl:number value="$item-number" format="{$type}"/>
766 </xsl:template>
767
768 <xsl:template match="abstract" mode="label.markup">
769 <!-- nop -->
770 </xsl:template>
771
772 <xsl:template match="sidebar" mode="label.markup">
773 <!-- nop -->
774 </xsl:template>
775
776 <!-- ============================================================ -->
777
778 <xsl:template name="label.this.section">
779 <xsl:param name="section" select="."/>
780
781 <xsl:variable name="level">
782 <xsl:call-template name="section.level"/>
783 </xsl:variable>
784
785 <xsl:choose>
786 <xsl:when test="$level &lt;= $section.autolabel.max.depth">
787 <xsl:value-of select="$section.autolabel"/>
788 </xsl:when>
789 <xsl:otherwise>0</xsl:otherwise>
790 </xsl:choose>
791 </xsl:template>
792
793 <doc:template name="label.this.section" xmlns="">
794 <refpurpose>Returns true if $section should be labelled</refpurpose>
795 <refdescription id="label.this.section-desc">
796 <para>Returns true if the specified section should be labelled.
797 By default, this template returns zero unless
798 the section level is less than or equal to the value of the
799 <literal>$section.autolabel.max.depth</literal> parameter, in
800 which case it returns
801 <literal>$section.autolabel</literal>.
802 Custom stylesheets may override it to get more selective behavior.</para>
803 </refdescription>
804 </doc:template>
805
806 <!-- ============================================================ -->
807
808 <xsl:template name="default.autolabel.format">
809 <xsl:param name="context" select="."/>
810 <xsl:choose>
811 <xsl:when test="local-name($context) = 'appendix'">
812 <xsl:value-of select="'A'"/>
813 </xsl:when>
814 <xsl:when test="local-name($context) = 'part'">
815 <xsl:value-of select="'I'"/>
816 </xsl:when>
817 <xsl:otherwise>1</xsl:otherwise>
818 </xsl:choose>
819 </xsl:template>
820
821 <xsl:template name="autolabel.format">
822 <xsl:param name="context" select="."/>
823 <xsl:param name="format"/>
824
825 <xsl:choose>
826 <xsl:when test="string($format) != 0">
827 <xsl:choose>
828 <xsl:when test="string($format)='arabic' or $format='1'">1</xsl:when>
829 <xsl:when test="$format='loweralpha' or $format='a'">
830 <xsl:value-of select="'a'"/>
831 </xsl:when>
832 <xsl:when test="$format='lowerroman' or $format='i'">
833 <xsl:value-of select="'i'"/>
834 </xsl:when>
835 <xsl:when test="$format='upperalpha' or $format='A'">
836 <xsl:value-of select="'A'"/>
837 </xsl:when>
838 <xsl:when test="$format='upperroman' or $format='I'">
839 <xsl:value-of select="'I'"/>
840 </xsl:when>
841 <xsl:when test="$format='arabicindic' or $format='&#x661;'">
842 <xsl:value-of select="'&#x661;'"/>
843 </xsl:when>
844 <xsl:otherwise>
845 <xsl:message>
846 <xsl:text>Unexpected </xsl:text><xsl:value-of select="local-name(.)"/><xsl:text>.autolabel value: </xsl:text>
847 <xsl:value-of select="$format"/><xsl:text>; using default.</xsl:text>
848 </xsl:message>
849 <xsl:call-template name="default.autolabel.format"/>
850 </xsl:otherwise>
851 </xsl:choose>
852 </xsl:when>
853 </xsl:choose>
854 </xsl:template>
855
856 <doc:template name="autolabel.format" xmlns="">
857 <refpurpose>Returns format for autolabel parameters</refpurpose>
858 <refdescription id="autolabel.format-desc">
859 <para>Returns format passed as parameter if non zero. Supported
860 format are 'arabic' or '1', 'loweralpha' or 'a', 'lowerroman' or 'i',
861 'upperlapha' or 'A', 'upperroman' or 'I', 'arabicindic' or '&#x661;'.
862 If its not one of these then
863 returns the default format.</para>
864 </refdescription>
865 </doc:template>
866
867 <!-- ============================================================ -->
868
869 </xsl:stylesheet>