Whamcloud - gitweb
LUDOC-120 presentation: build bits for webhelp.
[doc/manual.git] / webhelp / common / labels.xsl
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
4                 exclude-result-prefixes="doc"
5                 version='1.0'>
6
7 <!-- ********************************************************************
8      $Id: labels.xsl 9816 2013-09-24 03:35:07Z stilor $
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 <!--
33      Note that this template is applied to parent of the object being
34      referenced, and that object is passed via parameter.
35 -->
36 <xsl:template match="*" mode="intralabel.punctuation">
37   <xsl:param name="object" select="."/>
38
39   <xsl:text>.</xsl:text>
40 </xsl:template>
41
42 <xsl:template match="*" mode="label.markup">
43   <xsl:param name="verbose" select="1"/>
44   <xsl:if test="$verbose">
45     <xsl:message>
46       <xsl:text>Request for label of unexpected element: </xsl:text>
47       <xsl:value-of select="local-name(.)"/>
48     </xsl:message>
49   </xsl:if>
50 </xsl:template>
51
52 <xsl:template match="set|book" mode="label.markup">
53   <xsl:if test="@label">
54     <xsl:value-of select="@label"/>
55   </xsl:if>
56 </xsl:template>
57
58 <xsl:template match="part" mode="label.markup">
59   <xsl:choose>
60     <xsl:when test="@label">
61       <xsl:value-of select="@label"/>
62     </xsl:when>
63     <xsl:when test="string($part.autolabel) != 0">
64       <xsl:variable name="format">
65         <xsl:call-template name="autolabel.format">
66           <xsl:with-param name="format" select="$part.autolabel"/>
67         </xsl:call-template>
68       </xsl:variable>
69       <xsl:number from="book" count="part" format="{$format}"/>
70     </xsl:when>
71   </xsl:choose>
72 </xsl:template>
73
74 <xsl:template match="partintro" mode="label.markup">
75   <!-- no label -->
76 </xsl:template>
77
78 <xsl:template match="preface" mode="label.markup">
79   <xsl:choose>
80     <xsl:when test="@label">
81       <xsl:value-of select="@label"/>
82     </xsl:when>
83     <xsl:when test="string($preface.autolabel) != 0">
84       <xsl:if test="$component.label.includes.part.label != 0 and
85                       ancestor::part">
86         <xsl:variable name="part.label">
87           <xsl:apply-templates select="ancestor::part" 
88                                mode="label.markup"/>
89         </xsl:variable>
90         <xsl:if test="$part.label != ''">
91           <xsl:value-of select="$part.label"/>
92           <xsl:apply-templates select="ancestor::part" 
93                                mode="intralabel.punctuation">
94             <xsl:with-param name="object" select="."/>
95           </xsl:apply-templates>
96         </xsl:if>
97       </xsl:if>
98       <xsl:variable name="format">
99         <xsl:call-template name="autolabel.format">
100           <xsl:with-param name="format" select="$preface.autolabel"/>
101         </xsl:call-template>
102       </xsl:variable>
103       <xsl:choose>
104         <xsl:when test="$label.from.part != 0 and ancestor::part">
105           <xsl:number from="part" count="preface" format="{$format}" level="any"/>
106         </xsl:when>
107         <xsl:otherwise>
108           <xsl:number from="book" count="preface" format="{$format}" level="any"/>
109         </xsl:otherwise>
110       </xsl:choose>
111     </xsl:when>
112   </xsl:choose>
113 </xsl:template>
114
115 <xsl:template match="chapter" mode="label.markup">
116   <xsl:choose>
117     <xsl:when test="@label">
118       <xsl:value-of select="@label"/>
119     </xsl:when>
120     <xsl:when test="string($chapter.autolabel) != 0">
121       <xsl:if test="$component.label.includes.part.label != 0 and
122                       ancestor::part">
123         <xsl:variable name="part.label">
124           <xsl:apply-templates select="ancestor::part" 
125                                mode="label.markup"/>
126         </xsl:variable>
127         <xsl:if test="$part.label != ''">
128           <xsl:value-of select="$part.label"/>
129           <xsl:apply-templates select="ancestor::part" 
130                                mode="intralabel.punctuation">
131             <xsl:with-param name="object" select="."/>
132           </xsl:apply-templates>
133         </xsl:if>
134       </xsl:if>
135       <xsl:variable name="format">
136         <xsl:call-template name="autolabel.format">
137           <xsl:with-param name="format" select="$chapter.autolabel"/>
138         </xsl:call-template>
139       </xsl:variable>
140       <xsl:choose>
141         <xsl:when test="$label.from.part != 0 and ancestor::part">
142           <xsl:number from="part" count="chapter" format="{$format}" level="any"/>
143         </xsl:when>
144         <xsl:otherwise>
145           <xsl:number from="book" count="chapter" format="{$format}" level="any"/>
146         </xsl:otherwise>
147       </xsl:choose>
148     </xsl:when>
149   </xsl:choose>
150 </xsl:template>
151
152 <xsl:template match="appendix" mode="label.markup">
153   <xsl:choose>
154     <xsl:when test="@label">
155       <xsl:value-of select="@label"/>
156     </xsl:when>
157     <xsl:when test="string($appendix.autolabel) != 0">
158       <xsl:if test="$component.label.includes.part.label != 0 and
159                       ancestor::part">
160         <xsl:variable name="part.label">
161           <xsl:apply-templates select="ancestor::part" 
162                                mode="label.markup"/>
163         </xsl:variable>
164         <xsl:if test="$part.label != ''">
165           <xsl:value-of select="$part.label"/>
166           <xsl:apply-templates select="ancestor::part" 
167                                mode="intralabel.punctuation">
168             <xsl:with-param name="object" select="."/>
169           </xsl:apply-templates>
170         </xsl:if>
171       </xsl:if>
172       <xsl:variable name="format">
173         <xsl:call-template name="autolabel.format">
174           <xsl:with-param name="format" select="$appendix.autolabel"/>
175         </xsl:call-template>
176       </xsl:variable>
177       <xsl:choose>
178         <xsl:when test="$label.from.part != 0 and ancestor::part">
179           <xsl:number from="part" count="appendix" format="{$format}" level="any"/>
180         </xsl:when>
181         <xsl:otherwise>
182           <xsl:number from="book|article"
183                       count="appendix" format="{$format}" level="any"/>
184         </xsl:otherwise>
185       </xsl:choose>
186     </xsl:when>
187   </xsl:choose>
188 </xsl:template>
189
190 <xsl:template match="article" mode="label.markup">
191   <xsl:if test="@label">
192     <xsl:value-of select="@label"/>
193   </xsl:if>
194 </xsl:template>
195
196 <xsl:template match="dedication|colophon" mode="label.markup">
197   <xsl:if test="@label">
198     <xsl:value-of select="@label"/>
199   </xsl:if>
200 </xsl:template>
201
202 <xsl:template match="reference" mode="label.markup">
203   <xsl:choose>
204     <xsl:when test="@label">
205       <xsl:value-of select="@label"/>
206     </xsl:when>
207     <xsl:when test="string($reference.autolabel) != 0">
208       <xsl:if test="$component.label.includes.part.label != 0 and
209                       ancestor::part">
210         <xsl:variable name="part.label">
211           <xsl:apply-templates select="ancestor::part" 
212                                mode="label.markup"/>
213         </xsl:variable>
214         <xsl:if test="$part.label != ''">
215           <xsl:value-of select="$part.label"/>
216           <xsl:apply-templates select="ancestor::part" 
217                                mode="intralabel.punctuation">
218             <xsl:with-param name="object" select="."/>
219           </xsl:apply-templates>
220         </xsl:if>
221       </xsl:if>
222       <xsl:variable name="format">
223         <xsl:call-template name="autolabel.format">
224           <xsl:with-param name="format" select="$reference.autolabel"/>
225         </xsl:call-template>
226       </xsl:variable>
227       <xsl:choose>
228         <xsl:when test="$label.from.part != 0 and ancestor::part">
229           <xsl:number from="part" count="reference" format="{$format}" level="any"/>
230         </xsl:when>
231         <xsl:otherwise>
232           <xsl:number from="book" count="reference" format="{$format}" level="any"/>
233         </xsl:otherwise>
234       </xsl:choose>
235     </xsl:when>
236   </xsl:choose>
237 </xsl:template>
238
239 <xsl:template match="refentry" mode="label.markup">
240   <xsl:if test="@label">
241     <xsl:value-of select="@label"/>
242   </xsl:if>
243 </xsl:template>
244
245 <xsl:template match="section" mode="label.markup">
246   <!-- if this is a nested section, label the parent -->
247   <xsl:if test="local-name(..) = 'section'">
248     <xsl:variable name="parent.section.label">
249       <xsl:call-template name="label.this.section">
250         <xsl:with-param name="section" select=".."/>
251       </xsl:call-template>
252     </xsl:variable>
253     <xsl:if test="$parent.section.label != '0'">
254       <xsl:apply-templates select=".." mode="label.markup"/>
255       <xsl:apply-templates select=".." mode="intralabel.punctuation">
256         <xsl:with-param name="object" select="."/>
257       </xsl:apply-templates>
258     </xsl:if>
259   </xsl:if>
260
261   <!-- if the parent is a component, maybe label that too -->
262   <xsl:variable name="parent.is.component">
263     <xsl:call-template name="is.component">
264       <xsl:with-param name="node" select=".."/>
265     </xsl:call-template>
266   </xsl:variable>
267
268   <!-- does this section get labelled? -->
269   <xsl:variable name="label">
270     <xsl:call-template name="label.this.section">
271       <xsl:with-param name="section" select="."/>
272     </xsl:call-template>
273   </xsl:variable>
274
275   <xsl:if test="$section.label.includes.component.label != 0
276                 and $parent.is.component != 0">
277     <xsl:variable name="parent.label">
278       <xsl:apply-templates select=".." mode="label.markup"/>
279     </xsl:variable>
280     <xsl:if test="$parent.label != ''">
281       <xsl:apply-templates select=".." mode="label.markup"/>
282       <xsl:apply-templates select=".." mode="intralabel.punctuation">
283         <xsl:with-param name="object" select="."/>
284       </xsl:apply-templates>
285     </xsl:if>
286   </xsl:if>
287
288 <!--
289   <xsl:message>
290     test: <xsl:value-of select="$label"/>, <xsl:number count="section"/>
291   </xsl:message>
292 -->
293
294   <xsl:choose>
295     <xsl:when test="@label">
296       <xsl:value-of select="@label"/>
297     </xsl:when>
298     <xsl:when test="$label != 0">      
299       <xsl:variable name="format">
300         <xsl:call-template name="autolabel.format">
301           <xsl:with-param name="format" select="$section.autolabel"/>
302         </xsl:call-template>
303       </xsl:variable>
304       <xsl:number format="{$format}" count="section"/>
305     </xsl:when>
306   </xsl:choose>
307 </xsl:template>
308
309 <xsl:template match="sect1" mode="label.markup">
310   <!-- if the parent is a component, maybe label that too -->
311   <xsl:variable name="parent.is.component">
312     <xsl:call-template name="is.component">
313       <xsl:with-param name="node" select=".."/>
314     </xsl:call-template>
315   </xsl:variable>
316
317   <xsl:variable name="component.label">
318     <xsl:if test="$section.label.includes.component.label != 0
319                   and $parent.is.component != 0">
320       <xsl:variable name="parent.label">
321         <xsl:apply-templates select=".." mode="label.markup"/>
322       </xsl:variable>
323       <xsl:if test="$parent.label != ''">
324         <xsl:apply-templates select=".." mode="label.markup"/>
325         <xsl:apply-templates select=".." mode="intralabel.punctuation">
326           <xsl:with-param name="object" select="."/>
327         </xsl:apply-templates>
328       </xsl:if>
329     </xsl:if>
330   </xsl:variable>
331
332
333   <xsl:variable name="is.numbered">
334     <xsl:call-template name="label.this.section"/>
335   </xsl:variable>
336
337   <xsl:choose>
338     <xsl:when test="@label">
339       <xsl:value-of select="@label"/>
340     </xsl:when>
341     <xsl:when test="$is.numbered != 0">
342       <xsl:variable name="format">
343         <xsl:call-template name="autolabel.format">
344           <xsl:with-param name="format" select="$section.autolabel"/>
345         </xsl:call-template>
346       </xsl:variable>
347       <xsl:copy-of select="$component.label"/>
348       <xsl:number format="{$format}" count="sect1"/>
349     </xsl:when>
350   </xsl:choose>
351 </xsl:template>
352
353 <xsl:template match="sect2|sect3|sect4|sect5" mode="label.markup">
354   <!-- label the parent -->
355   <xsl:variable name="parent.section.label">
356     <xsl:call-template name="label.this.section">
357       <xsl:with-param name="section" select=".."/>
358     </xsl:call-template>
359   </xsl:variable>
360   <xsl:if test="$parent.section.label != '0'">
361     <xsl:apply-templates select=".." mode="label.markup"/>
362     <xsl:apply-templates select=".." mode="intralabel.punctuation">
363       <xsl:with-param name="object" select="."/>
364     </xsl:apply-templates>
365   </xsl:if>
366
367   <xsl:variable name="is.numbered">
368     <xsl:call-template name="label.this.section"/>
369   </xsl:variable>
370
371   <xsl:choose>
372     <xsl:when test="@label">
373       <xsl:value-of select="@label"/>
374     </xsl:when>
375     <xsl:when test="$is.numbered != 0">
376       <xsl:variable name="format">
377         <xsl:call-template name="autolabel.format">
378           <xsl:with-param name="format" select="$section.autolabel"/>
379         </xsl:call-template>
380       </xsl:variable>
381       <xsl:choose>
382         <xsl:when test="local-name(.) = 'sect2'">
383           <xsl:number format="{$format}" count="sect2"/>
384         </xsl:when>
385         <xsl:when test="local-name(.) = 'sect3'">
386           <xsl:number format="{$format}" count="sect3"/>
387         </xsl:when>
388         <xsl:when test="local-name(.) = 'sect4'">
389           <xsl:number format="{$format}" count="sect4"/>
390         </xsl:when>
391         <xsl:when test="local-name(.) = 'sect5'">
392           <xsl:number format="{$format}" count="sect5"/>
393         </xsl:when>
394         <xsl:otherwise>
395           <xsl:message>label.markup: this can't happen!</xsl:message>
396         </xsl:otherwise>
397       </xsl:choose>
398     </xsl:when>
399   </xsl:choose>
400 </xsl:template>
401
402 <xsl:template match="bridgehead" mode="label.markup">
403   <!-- bridgeheads are not normally numbered -->
404 </xsl:template>
405
406 <xsl:template match="refsect1" mode="label.markup">
407   <xsl:choose>
408     <xsl:when test="@label">
409       <xsl:value-of select="@label"/>
410     </xsl:when>
411     <xsl:when test="$section.autolabel != 0">
412       <xsl:variable name="format">
413         <xsl:call-template name="autolabel.format">
414           <xsl:with-param name="format" select="$section.autolabel"/>
415         </xsl:call-template>
416       </xsl:variable>
417       <xsl:number count="refsect1" format="{$format}"/>
418     </xsl:when>
419   </xsl:choose>
420 </xsl:template>
421
422 <xsl:template match="refsect2|refsect3" mode="label.markup">
423   <!-- label the parent -->
424   <xsl:variable name="parent.label">
425     <xsl:apply-templates select=".." mode="label.markup"/>
426   </xsl:variable>
427   <xsl:if test="$parent.label != ''">
428     <xsl:apply-templates select=".." mode="label.markup"/>
429     <xsl:apply-templates select=".." mode="intralabel.punctuation">
430       <xsl:with-param name="object" select="."/>
431     </xsl:apply-templates>
432   </xsl:if>
433
434   <xsl:choose>
435     <xsl:when test="@label">
436       <xsl:value-of select="@label"/>
437     </xsl:when>
438     <xsl:when test="$section.autolabel != 0">
439       <xsl:variable name="format">
440         <xsl:call-template name="autolabel.format">
441           <xsl:with-param name="format" select="$section.autolabel"/>
442         </xsl:call-template>
443       </xsl:variable>
444       <xsl:choose>
445         <xsl:when test="local-name(.) = 'refsect2'">
446           <xsl:number count="refsect2" format="{$format}"/>
447         </xsl:when>
448         <xsl:otherwise>
449           <xsl:number count="refsect3" format="{$format}"/>
450         </xsl:otherwise>
451       </xsl:choose>
452     </xsl:when>
453   </xsl:choose>
454 </xsl:template>
455
456 <xsl:template match="simplesect" mode="label.markup">
457   <!-- if this is a nested section, label the parent -->
458   <xsl:if test="local-name(..) = 'section'
459                 or local-name(..) = 'sect1'
460                 or local-name(..) = 'sect2'
461                 or local-name(..) = 'sect3'
462                 or local-name(..) = 'sect4'
463                 or local-name(..) = 'sect5'">
464     <xsl:variable name="parent.section.label">
465       <xsl:apply-templates select=".." mode="label.markup"/>
466     </xsl:variable>
467     <xsl:if test="$parent.section.label != ''">
468       <xsl:apply-templates select=".." mode="label.markup"/>
469       <xsl:apply-templates select=".." mode="intralabel.punctuation">
470         <xsl:with-param name="object" select="."/>
471       </xsl:apply-templates>
472     </xsl:if>
473   </xsl:if>
474
475   <!-- if the parent is a component, maybe label that too -->
476   <xsl:variable name="parent.is.component">
477     <xsl:call-template name="is.component">
478       <xsl:with-param name="node" select=".."/>
479     </xsl:call-template>
480   </xsl:variable>
481
482   <!-- does this section get labelled? -->
483   <xsl:variable name="label">
484     <xsl:call-template name="label.this.section">
485       <xsl:with-param name="section" select="."/>
486     </xsl:call-template>
487   </xsl:variable>
488
489   <xsl:if test="$section.label.includes.component.label != 0
490                 and $parent.is.component != 0">
491     <xsl:variable name="parent.label">
492       <xsl:apply-templates select=".." mode="label.markup"/>
493     </xsl:variable>
494     <xsl:if test="$parent.label != ''">
495       <xsl:apply-templates select=".." mode="label.markup"/>
496       <xsl:apply-templates select=".." mode="intralabel.punctuation">
497         <xsl:with-param name="object" select="."/>
498       </xsl:apply-templates>
499     </xsl:if>
500   </xsl:if>
501
502   <xsl:choose>
503     <xsl:when test="@label">
504       <xsl:value-of select="@label"/>
505     </xsl:when>
506     <xsl:when test="$label != 0">
507       <xsl:variable name="format">
508         <xsl:call-template name="autolabel.format">
509           <xsl:with-param name="format" select="$section.autolabel"/>
510         </xsl:call-template>
511       </xsl:variable>
512       <xsl:number format="{$format}" count="simplesect"/>
513     </xsl:when>
514   </xsl:choose>
515 </xsl:template>
516
517 <xsl:template match="topic" mode="label.markup">
518   <!-- topics are not numbered by default -->
519 </xsl:template>
520
521 <xsl:template match="qandadiv" mode="label.markup">
522   <xsl:variable name="lparent" select="(ancestor::set
523                                        |ancestor::book
524                                        |ancestor::chapter
525                                        |ancestor::appendix
526                                        |ancestor::preface
527                                        |ancestor::section
528                                        |ancestor::simplesect
529                                        |ancestor::sect1
530                                        |ancestor::sect2
531                                        |ancestor::sect3
532                                        |ancestor::sect4
533                                        |ancestor::sect5
534                                        |ancestor::refsect1
535                                        |ancestor::refsect2
536                                        |ancestor::refsect3)[last()]"/>
537
538   <xsl:variable name="lparent.prefix">
539     <xsl:apply-templates select="$lparent" mode="label.markup"/>
540   </xsl:variable>
541
542   <xsl:variable name="prefix">
543     <xsl:if test="$qanda.inherit.numeration != 0">
544       <xsl:if test="$lparent.prefix != ''">
545         <xsl:apply-templates select="$lparent" mode="label.markup"/>
546         <xsl:apply-templates select="$lparent" mode="intralabel.punctuation">
547           <xsl:with-param name="object" select="."/>
548         </xsl:apply-templates>
549       </xsl:if>
550     </xsl:if>
551   </xsl:variable>
552
553   <xsl:choose>
554     <xsl:when test="$qandadiv.autolabel != 0">
555       <xsl:variable name="format">
556         <xsl:call-template name="autolabel.format">
557           <xsl:with-param name="format" select="$qandadiv.autolabel"/>
558         </xsl:call-template>
559       </xsl:variable>
560       <xsl:value-of select="$prefix"/>
561       <xsl:number level="multiple" count="qandadiv" format="{$format}"/>
562     </xsl:when>
563   </xsl:choose>
564 </xsl:template>
565
566 <xsl:template match="question|answer" mode="label.markup">
567   <xsl:variable name="lparent" select="(ancestor::set
568                                        |ancestor::book
569                                        |ancestor::chapter
570                                        |ancestor::appendix
571                                        |ancestor::preface
572                                        |ancestor::section
573                                        |ancestor::simplesect
574                                        |ancestor::sect1
575                                        |ancestor::sect2
576                                        |ancestor::sect3
577                                        |ancestor::sect4
578                                        |ancestor::sect5
579                                        |ancestor::refsect1
580                                        |ancestor::refsect2
581                                        |ancestor::refsect3)[last()]"/>
582
583   <xsl:variable name="lparent.prefix">
584     <xsl:apply-templates select="$lparent" mode="label.markup"/>
585   </xsl:variable>
586
587   <xsl:variable name="prefix">
588     <xsl:if test="$qanda.inherit.numeration != 0">
589       <xsl:choose>
590         <xsl:when test="ancestor::qandadiv">
591           <xsl:variable name="div.label">
592             <xsl:apply-templates select="ancestor::qandadiv[1]" mode="label.markup"/>
593           </xsl:variable>
594           <xsl:if test="string-length($div.label) != 0">
595             <xsl:copy-of select="$div.label"/>
596             <xsl:apply-templates select="ancestor::qandadiv[1]"
597                                  mode="intralabel.punctuation">
598               <xsl:with-param name="object" select="."/>
599             </xsl:apply-templates>
600           </xsl:if>
601         </xsl:when>
602         <xsl:when test="$lparent.prefix != ''">
603           <xsl:apply-templates select="$lparent" mode="label.markup"/>
604           <xsl:apply-templates select="$lparent" mode="intralabel.punctuation">
605             <xsl:with-param name="object" select="."/>
606           </xsl:apply-templates>
607         </xsl:when>
608       </xsl:choose>
609     </xsl:if>
610   </xsl:variable>
611
612   <xsl:variable name="inhlabel"
613                 select="ancestor-or-self::qandaset/@defaultlabel[1]"/>
614
615   <xsl:variable name="deflabel">
616     <xsl:choose>
617       <xsl:when test="$inhlabel != ''">
618         <xsl:value-of select="$inhlabel"/>
619       </xsl:when>
620       <xsl:otherwise>
621         <xsl:value-of select="$qanda.defaultlabel"/>
622       </xsl:otherwise>
623     </xsl:choose>
624   </xsl:variable>
625
626   <xsl:variable name="label" select="label"/>
627
628   <xsl:choose>
629     <xsl:when test="count($label)>0">
630       <xsl:apply-templates select="$label"/>
631     </xsl:when>
632
633     <xsl:when test="$deflabel = 'qanda' and self::question">
634       <xsl:call-template name="gentext">
635         <xsl:with-param name="key" select="'Question'"/>
636       </xsl:call-template>
637     </xsl:when>
638
639     <xsl:when test="$deflabel = 'qanda' and self::answer">
640       <xsl:call-template name="gentext">
641         <xsl:with-param name="key" select="'Answer'"/>
642       </xsl:call-template>
643     </xsl:when>
644
645     <xsl:when test="($deflabel = 'qnumber' or
646                      $deflabel = 'qnumberanda') and self::question">
647       <xsl:call-template name="gentext">
648         <xsl:with-param name="key" select="'Question'"/>
649       </xsl:call-template>
650       <xsl:text>&#xA0;</xsl:text>
651       <xsl:value-of select="$prefix"/>
652       <xsl:number level="multiple" count="qandaentry" format="1"/>
653     </xsl:when>
654
655     <xsl:when test="$deflabel = 'qnumberanda' and self::answer">
656       <xsl:call-template name="gentext">
657         <xsl:with-param name="key" select="'Answer'"/>
658       </xsl:call-template>
659     </xsl:when>
660
661     <xsl:when test="$deflabel = 'number' and self::question">
662       <xsl:value-of select="$prefix"/>
663       <xsl:number level="multiple" count="qandaentry" format="1"/>
664     </xsl:when>
665   </xsl:choose>
666 </xsl:template>
667
668 <xsl:template match="bibliography|glossary|
669                      qandaset|index|setindex" mode="label.markup">
670   <xsl:if test="@label">
671     <xsl:value-of select="@label"/>
672   </xsl:if>
673 </xsl:template>
674
675 <xsl:template match="figure|table|example" mode="label.markup">
676   <xsl:variable name="pchap"
677                 select="(ancestor::chapter
678                         |ancestor::appendix
679                         |ancestor::article[ancestor::book])[last()]"/>
680
681   <xsl:variable name="prefix">
682     <xsl:if test="count($pchap) &gt; 0">
683       <xsl:apply-templates select="$pchap" mode="label.markup"/>
684     </xsl:if>
685   </xsl:variable>
686
687   <xsl:choose>
688     <xsl:when test="@label">
689       <xsl:value-of select="@label"/>
690     </xsl:when>
691     <xsl:otherwise>
692       <xsl:choose>
693         <xsl:when test="$prefix != ''">
694             <xsl:apply-templates select="$pchap" mode="label.markup"/>
695             <xsl:apply-templates select="$pchap" mode="intralabel.punctuation">
696               <xsl:with-param name="object" select="."/>
697             </xsl:apply-templates>
698           <xsl:number format="1" from="chapter|appendix" level="any"/>
699         </xsl:when>
700         <xsl:otherwise>
701           <xsl:number format="1" from="book|article" level="any"/>
702         </xsl:otherwise>
703       </xsl:choose>
704     </xsl:otherwise>
705   </xsl:choose>
706 </xsl:template>
707
708 <xsl:template match="procedure" mode="label.markup">
709   <xsl:variable name="pchap"
710                 select="ancestor::chapter
711                         |ancestor::appendix
712                         |ancestor::article[ancestor::book]"/>
713
714   <xsl:variable name="prefix">
715     <xsl:if test="count($pchap) &gt; 0">
716       <xsl:apply-templates select="$pchap" mode="label.markup"/>
717     </xsl:if>
718   </xsl:variable>
719
720   <xsl:choose>
721     <xsl:when test="@label">
722       <xsl:value-of select="@label"/>
723     </xsl:when>
724     <xsl:when test="$formal.procedures = 0">
725       <!-- No label -->
726     </xsl:when>
727     <xsl:otherwise>
728       <xsl:choose>
729         <xsl:when test="count($pchap)>0">
730           <xsl:if test="$prefix != ''">
731             <xsl:apply-templates select="$pchap" mode="label.markup"/>
732             <xsl:apply-templates select="$pchap" mode="intralabel.punctuation">
733               <xsl:with-param name="object" select="."/>
734             </xsl:apply-templates>
735           </xsl:if>
736           <xsl:number count="procedure[title|blockinfo/title|info/title]" format="1" 
737                       from="chapter|appendix" level="any"/>
738         </xsl:when>
739         <xsl:otherwise>
740           <xsl:number count="procedure[title|blockinfo/title|info/title]" format="1" 
741                       from="book|article" level="any"/>
742         </xsl:otherwise>
743       </xsl:choose>
744     </xsl:otherwise>
745   </xsl:choose>
746 </xsl:template>
747
748 <xsl:template match="equation" mode="label.markup">
749   <xsl:variable name="pchap"
750                 select="ancestor::chapter
751                         |ancestor::appendix
752                         |ancestor::article[ancestor::book]"/>
753
754   <xsl:variable name="prefix">
755     <xsl:if test="count($pchap) &gt; 0">
756       <xsl:apply-templates select="$pchap" mode="label.markup"/>
757     </xsl:if>
758   </xsl:variable>
759
760   <xsl:choose>
761     <xsl:when test="@label">
762       <xsl:value-of select="@label"/>
763     </xsl:when>
764     <xsl:otherwise>
765       <xsl:choose>
766         <xsl:when test="count($pchap)>0">
767           <xsl:if test="$prefix != ''">
768             <xsl:apply-templates select="$pchap" mode="label.markup"/>
769             <xsl:apply-templates select="$pchap" mode="intralabel.punctuation">
770               <xsl:with-param name="object" select="."/>
771             </xsl:apply-templates>
772           </xsl:if>
773           <xsl:number format="1" count="equation" 
774                       from="chapter|appendix" level="any"/>
775         </xsl:when>
776         <xsl:otherwise>
777           <xsl:number format="1" count="equation" 
778                       from="book|article" level="any"/>
779         </xsl:otherwise>
780       </xsl:choose>
781     </xsl:otherwise>
782   </xsl:choose>
783 </xsl:template>
784
785 <xsl:template match="orderedlist/listitem" mode="label.markup">
786   <xsl:variable name="numeration">
787     <xsl:call-template name="list.numeration">
788       <xsl:with-param name="node" select="parent::orderedlist"/>
789     </xsl:call-template>
790   </xsl:variable>
791
792   <xsl:variable name="type">
793     <xsl:choose>
794       <xsl:when test="$numeration='arabic'">1</xsl:when>
795       <xsl:when test="$numeration='loweralpha'">a</xsl:when>
796       <xsl:when test="$numeration='lowerroman'">i</xsl:when>
797       <xsl:when test="$numeration='upperalpha'">A</xsl:when>
798       <xsl:when test="$numeration='upperroman'">I</xsl:when>
799       <!-- What!? This should never happen -->
800       <xsl:otherwise>
801         <xsl:message>
802           <xsl:text>Unexpected numeration: </xsl:text>
803           <xsl:value-of select="$numeration"/>
804         </xsl:message>
805         <xsl:value-of select="1."/>
806       </xsl:otherwise>
807     </xsl:choose>
808   </xsl:variable>
809
810   <xsl:variable name="item-number">
811     <xsl:call-template name="orderedlist-item-number"/>
812   </xsl:variable>
813
814   <xsl:number value="$item-number" format="{$type}"/>
815 </xsl:template>
816
817 <xsl:template match="production" mode="label.markup">
818   <xsl:number count="production" level="any"/>
819 </xsl:template>
820
821 <xsl:template match="abstract" mode="label.markup">
822   <!-- nop -->
823 </xsl:template>
824
825 <xsl:template match="sidebar" mode="label.markup">
826   <!-- nop -->
827 </xsl:template>
828
829 <xsl:template match="glossdiv|glosslist" mode="label.markup">
830   <!-- nop -->
831 </xsl:template>
832
833 <xsl:template match="glossentry" mode="label.markup">
834   <!-- nop -->
835 </xsl:template>
836
837 <!-- ============================================================ -->
838
839 <xsl:template name="label.this.section">
840   <xsl:param name="section" select="."/>
841
842   <xsl:variable name="level">
843     <xsl:call-template name="section.level"/>
844   </xsl:variable>
845
846   <xsl:choose>
847     <!-- bridgeheads are not numbered -->
848     <xsl:when test="$section/self::bridgehead">0</xsl:when>
849     <xsl:when test="$level &lt;= $section.autolabel.max.depth">      
850       <xsl:value-of select="$section.autolabel"/>
851     </xsl:when>
852     <xsl:otherwise>0</xsl:otherwise>
853   </xsl:choose>
854 </xsl:template>
855
856 <doc:template name="label.this.section" xmlns="">
857 <refpurpose>Returns true if $section should be labelled</refpurpose>
858 <refdescription id="label.this.section-desc">
859 <para>Returns true if the specified section should be labelled.
860 By default, this template returns zero unless 
861 the section level is less than or equal to the value of the
862 <literal>$section.autolabel.max.depth</literal> parameter, in
863 which case it returns
864 <literal>$section.autolabel</literal>.
865 Custom stylesheets may override it to get more selective behavior.</para>
866 </refdescription>
867 </doc:template>
868
869 <!-- ============================================================ -->
870
871 <xsl:template name="default.autolabel.format">
872   <xsl:param name="context" select="."/>
873   <xsl:choose>
874     <xsl:when test="local-name($context) = 'appendix'">
875       <xsl:value-of select="'A'"/>
876     </xsl:when>
877     <xsl:when test="local-name($context) = 'part'">
878       <xsl:value-of select="'I'"/>
879     </xsl:when>
880     <xsl:otherwise>1</xsl:otherwise>
881   </xsl:choose>  
882 </xsl:template>
883   
884 <xsl:template name="autolabel.format">
885   <xsl:param name="context" select="."/>
886   <xsl:param name="format"/>
887
888   <xsl:choose>
889     <xsl:when test="string($format) != 0">
890       <xsl:choose>
891         <xsl:when test="string($format)='arabic' or $format='1'">1</xsl:when>
892         <xsl:when test="$format='loweralpha' or $format='a'">
893           <xsl:value-of select="'a'"/>
894         </xsl:when>
895         <xsl:when test="$format='lowerroman' or $format='i'">
896           <xsl:value-of select="'i'"/>
897         </xsl:when>
898         <xsl:when test="$format='upperalpha' or $format='A'">
899           <xsl:value-of select="'A'"/>
900         </xsl:when>
901         <xsl:when test="$format='upperroman' or $format='I'">
902           <xsl:value-of select="'I'"/>
903         </xsl:when>      
904         <xsl:when test="$format='arabicindic' or $format='&#x661;'">
905           <xsl:value-of select="'&#x661;'"/>
906         </xsl:when>
907         <xsl:otherwise>
908           <xsl:message>
909             <xsl:text>Unexpected </xsl:text><xsl:value-of select="local-name(.)"/><xsl:text>.autolabel value: </xsl:text>
910             <xsl:value-of select="$format"/><xsl:text>; using default.</xsl:text>
911           </xsl:message>
912           <xsl:call-template name="default.autolabel.format"/>
913         </xsl:otherwise>
914       </xsl:choose>
915     </xsl:when>
916   </xsl:choose>
917 </xsl:template>
918
919 <doc:template name="autolabel.format" xmlns="">
920 <refpurpose>Returns format for autolabel parameters</refpurpose>
921 <refdescription id="autolabel.format-desc">
922 <para>Returns format passed as parameter if non zero. Supported
923   format are 'arabic' or '1', 'loweralpha' or 'a', 'lowerroman' or 'i', 
924   'upperlapha' or 'A', 'upperroman' or 'I', 'arabicindic' or '&#x661;'.
925   If its not one of these then 
926   returns the default format.</para>
927 </refdescription>
928 </doc:template>
929
930 <!-- ============================================================ -->
931
932 </xsl:stylesheet>