Rocco Rutte:
[apps/madmutt.git] / doc / xslt / 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$
9      ********************************************************************
10
11      This file is part of the XSL DocBook Stylesheet distribution.
12      See ../README or http://nwalsh.com/docbook/xsl/ for copyright
13      and other information.
14
15      ******************************************************************** -->
16
17 <!-- ==================================================================== -->
18
19 <!-- label markup -->
20
21 <doc:mode mode="label.markup" xmlns="">
22 <refpurpose>Provides access to element labels</refpurpose>
23 <refdescription>
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="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($part.autolabel) != 0">
196       <xsl:variable name="format">
197         <xsl:call-template name="autolabel.format">
198           <xsl:with-param name="format" select="$part.autolabel"/>
199         </xsl:call-template>
200       </xsl:variable>
201       <xsl:number from="book" count="reference" format="{$format}" level="any"/>
202     </xsl:when>
203   </xsl:choose>
204 </xsl:template>
205
206 <xsl:template match="refentry" mode="label.markup">
207   <xsl:if test="@label">
208     <xsl:value-of select="@label"/>
209   </xsl:if>
210 </xsl:template>
211
212 <xsl:template match="section" mode="label.markup">
213   <!-- if this is a nested section, label the parent -->
214   <xsl:if test="local-name(..) = 'section'">
215     <xsl:variable name="parent.section.label">
216       <xsl:call-template name="label.this.section">
217         <xsl:with-param name="section" select=".."/>
218       </xsl:call-template>
219     </xsl:variable>
220     <xsl:if test="$parent.section.label != '0'">
221       <xsl:apply-templates select=".." mode="label.markup"/>
222       <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
223     </xsl:if>
224   </xsl:if>
225
226   <!-- if the parent is a component, maybe label that too -->
227   <xsl:variable name="parent.is.component">
228     <xsl:call-template name="is.component">
229       <xsl:with-param name="node" select=".."/>
230     </xsl:call-template>
231   </xsl:variable>
232
233   <!-- does this section get labelled? -->
234   <xsl:variable name="label">
235     <xsl:call-template name="label.this.section">
236       <xsl:with-param name="section" select="."/>
237     </xsl:call-template>
238   </xsl:variable>
239
240   <xsl:if test="$section.label.includes.component.label != 0
241                 and $parent.is.component != 0">
242     <xsl:variable name="parent.label">
243       <xsl:apply-templates select=".." mode="label.markup"/>
244     </xsl:variable>
245     <xsl:if test="$parent.label != ''">
246       <xsl:apply-templates select=".." mode="label.markup"/>
247       <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
248     </xsl:if>
249   </xsl:if>
250
251 <!--
252   <xsl:message>
253     test: <xsl:value-of select="$label"/>, <xsl:number count="section"/>
254   </xsl:message>
255 -->
256
257   <xsl:choose>
258     <xsl:when test="@label">
259       <xsl:value-of select="@label"/>
260     </xsl:when>
261     <xsl:when test="$label != 0">      
262       <xsl:variable name="format">
263         <xsl:call-template name="autolabel.format">
264           <xsl:with-param name="format" select="$section.autolabel"/>
265         </xsl:call-template>
266       </xsl:variable>
267       <xsl:number format="{$format}" count="section"/>
268     </xsl:when>
269   </xsl:choose>
270 </xsl:template>
271
272 <xsl:template match="sect1" mode="label.markup">
273   <!-- if the parent is a component, maybe label that too -->
274   <xsl:variable name="parent.is.component">
275     <xsl:call-template name="is.component">
276       <xsl:with-param name="node" select=".."/>
277     </xsl:call-template>
278   </xsl:variable>
279
280   <xsl:variable name="component.label">
281     <xsl:if test="$section.label.includes.component.label != 0
282                   and $parent.is.component != 0">
283       <xsl:variable name="parent.label">
284         <xsl:apply-templates select=".." mode="label.markup"/>
285       </xsl:variable>
286       <xsl:if test="$parent.label != ''">
287         <xsl:apply-templates select=".." mode="label.markup"/>
288         <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
289       </xsl:if>
290     </xsl:if>
291   </xsl:variable>
292
293
294   <xsl:variable name="is.numbered">
295     <xsl:call-template name="label.this.section"/>
296   </xsl:variable>
297
298   <xsl:choose>
299     <xsl:when test="@label">
300       <xsl:value-of select="@label"/>
301     </xsl:when>
302     <xsl:when test="$is.numbered != 0">
303       <xsl:variable name="format">
304         <xsl:call-template name="autolabel.format">
305           <xsl:with-param name="format" select="$section.autolabel"/>
306         </xsl:call-template>
307       </xsl:variable>
308       <xsl:copy-of select="$component.label"/>
309       <xsl:number format="{$format}" count="sect1"/>
310     </xsl:when>
311   </xsl:choose>
312 </xsl:template>
313
314 <xsl:template match="sect2|sect3|sect4|sect5" mode="label.markup">
315   <!-- label the parent -->
316   <xsl:variable name="parent.section.label">
317     <xsl:call-template name="label.this.section">
318       <xsl:with-param name="section" select=".."/>
319     </xsl:call-template>
320   </xsl:variable>
321   <xsl:if test="$parent.section.label != '0'">
322     <xsl:apply-templates select=".." mode="label.markup"/>
323     <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
324   </xsl:if>
325
326   <xsl:variable name="is.numbered">
327     <xsl:call-template name="label.this.section"/>
328   </xsl:variable>
329
330   <xsl:choose>
331     <xsl:when test="@label">
332       <xsl:value-of select="@label"/>
333     </xsl:when>
334     <xsl:when test="$is.numbered != 0">
335       <xsl:variable name="format">
336         <xsl:call-template name="autolabel.format">
337           <xsl:with-param name="format" select="$section.autolabel"/>
338         </xsl:call-template>
339       </xsl:variable>
340       <xsl:choose>
341         <xsl:when test="local-name(.) = 'sect2'">
342           <xsl:number format="{$format}" count="sect2"/>
343         </xsl:when>
344         <xsl:when test="local-name(.) = 'sect3'">
345           <xsl:number format="{$format}" count="sect3"/>
346         </xsl:when>
347         <xsl:when test="local-name(.) = 'sect4'">
348           <xsl:number format="{$format}" count="sect4"/>
349         </xsl:when>
350         <xsl:when test="local-name(.) = 'sect5'">
351           <xsl:number format="{$format}" count="sect5"/>
352         </xsl:when>
353         <xsl:otherwise>
354           <xsl:message>label.markup: this can't happen!</xsl:message>
355         </xsl:otherwise>
356       </xsl:choose>
357     </xsl:when>
358   </xsl:choose>
359 </xsl:template>
360
361 <xsl:template match="bridgehead" mode="label.markup">
362   <!-- FIXME: could we do a better job here? -->
363   <xsl:variable name="contsec"
364                 select="(ancestor::section
365                          |ancestor::simplesect
366                          |ancestor::sect1
367                          |ancestor::sect2
368                          |ancestor::sect3
369                          |ancestor::sect4
370                          |ancestor::sect5
371                          |ancestor::refsect1
372                          |ancestor::refsect2
373                          |ancestor::refsect3
374                          |ancestor::chapter
375                          |ancestor::appendix
376                          |ancestor::preface)[last()]"/>
377
378   <xsl:apply-templates select="$contsec" mode="label.markup"/>
379 </xsl:template>
380
381 <xsl:template match="refsect1" mode="label.markup">
382   <xsl:choose>
383     <xsl:when test="@label">
384       <xsl:value-of select="@label"/>
385     </xsl:when>
386     <xsl:when test="$section.autolabel != 0">
387       <xsl:variable name="format">
388         <xsl:call-template name="autolabel.format">
389           <xsl:with-param name="format" select="$section.autolabel"/>
390         </xsl:call-template>
391       </xsl:variable>
392       <xsl:number count="refsect1" format="{$format}"/>
393     </xsl:when>
394   </xsl:choose>
395 </xsl:template>
396
397 <xsl:template match="refsect2|refsect3" mode="label.markup">
398   <!-- label the parent -->
399   <xsl:variable name="parent.label">
400     <xsl:apply-templates select=".." mode="label.markup"/>
401   </xsl:variable>
402   <xsl:if test="$parent.label != ''">
403     <xsl:apply-templates select=".." mode="label.markup"/>
404     <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
405   </xsl:if>
406
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:choose>
418         <xsl:when test="local-name(.) = 'refsect2'">
419           <xsl:number count="refsect2" format="{$format}"/>
420         </xsl:when>
421         <xsl:otherwise>
422           <xsl:number count="refsect3" format="{$format}"/>
423         </xsl:otherwise>
424       </xsl:choose>
425     </xsl:when>
426   </xsl:choose>
427 </xsl:template>
428
429 <xsl:template match="simplesect" mode="label.markup">
430   <!-- if this is a nested section, label the parent -->
431   <xsl:if test="local-name(..) = 'section'
432                 or local-name(..) = 'sect1'
433                 or local-name(..) = 'sect2'
434                 or local-name(..) = 'sect3'
435                 or local-name(..) = 'sect4'
436                 or local-name(..) = 'sect5'">
437     <xsl:variable name="parent.section.label">
438       <xsl:apply-templates select=".." mode="label.markup"/>
439     </xsl:variable>
440     <xsl:if test="$parent.section.label != ''">
441       <xsl:apply-templates select=".." mode="label.markup"/>
442       <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
443     </xsl:if>
444   </xsl:if>
445
446   <!-- if the parent is a component, maybe label that too -->
447   <xsl:variable name="parent.is.component">
448     <xsl:call-template name="is.component">
449       <xsl:with-param name="node" select=".."/>
450     </xsl:call-template>
451   </xsl:variable>
452
453   <!-- does this section get labelled? -->
454   <xsl:variable name="label">
455     <xsl:call-template name="label.this.section">
456       <xsl:with-param name="section" select="."/>
457     </xsl:call-template>
458   </xsl:variable>
459
460   <xsl:if test="$section.label.includes.component.label != 0
461                 and $parent.is.component != 0">
462     <xsl:variable name="parent.label">
463       <xsl:apply-templates select=".." mode="label.markup"/>
464     </xsl:variable>
465     <xsl:if test="$parent.label != ''">
466       <xsl:apply-templates select=".." mode="label.markup"/>
467       <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
468     </xsl:if>
469   </xsl:if>
470
471   <xsl:choose>
472     <xsl:when test="@label">
473       <xsl:value-of select="@label"/>
474     </xsl:when>
475     <xsl:when test="$label != 0">
476       <xsl:variable name="format">
477         <xsl:call-template name="autolabel.format">
478           <xsl:with-param name="format" select="$section.autolabel"/>
479         </xsl:call-template>
480       </xsl:variable>
481       <xsl:number format="{$format}" count="simplesect"/>
482     </xsl:when>
483   </xsl:choose>
484 </xsl:template>
485
486 <xsl:template match="qandadiv" mode="label.markup">
487   <xsl:variable name="lparent" select="(ancestor::set
488                                        |ancestor::book
489                                        |ancestor::chapter
490                                        |ancestor::appendix
491                                        |ancestor::preface
492                                        |ancestor::section
493                                        |ancestor::simplesect
494                                        |ancestor::sect1
495                                        |ancestor::sect2
496                                        |ancestor::sect3
497                                        |ancestor::sect4
498                                        |ancestor::sect5
499                                        |ancestor::refsect1
500                                        |ancestor::refsect2
501                                        |ancestor::refsect3)[last()]"/>
502
503   <xsl:variable name="lparent.prefix">
504     <xsl:apply-templates select="$lparent" mode="label.markup"/>
505   </xsl:variable>
506
507   <xsl:variable name="prefix">
508     <xsl:if test="$qanda.inherit.numeration != 0">
509       <xsl:if test="$lparent.prefix != ''">
510         <xsl:apply-templates select="$lparent" mode="label.markup"/>
511         <xsl:apply-templates select="$lparent" mode="intralabel.punctuation"/>
512       </xsl:if>
513     </xsl:if>
514   </xsl:variable>
515
516   <xsl:choose>
517     <xsl:when test="$qandadiv.autolabel != 0">
518       <xsl:variable name="format">
519         <xsl:call-template name="autolabel.format">
520           <xsl:with-param name="format" select="$qandadiv.autolabel"/>
521         </xsl:call-template>
522       </xsl:variable>
523       <xsl:value-of select="$prefix"/>
524       <xsl:number level="multiple" count="qandadiv" format="{$format}"/>
525     </xsl:when>
526   </xsl:choose>
527 </xsl:template>
528
529 <xsl:template match="question|answer" mode="label.markup">
530   <xsl:variable name="lparent" select="(ancestor::set
531                                        |ancestor::book
532                                        |ancestor::chapter
533                                        |ancestor::appendix
534                                        |ancestor::preface
535                                        |ancestor::section
536                                        |ancestor::simplesect
537                                        |ancestor::sect1
538                                        |ancestor::sect2
539                                        |ancestor::sect3
540                                        |ancestor::sect4
541                                        |ancestor::sect5
542                                        |ancestor::refsect1
543                                        |ancestor::refsect2
544                                        |ancestor::refsect3)[last()]"/>
545
546   <xsl:variable name="lparent.prefix">
547     <xsl:apply-templates select="$lparent" mode="label.markup"/>
548   </xsl:variable>
549
550   <xsl:variable name="prefix">
551     <xsl:if test="$qanda.inherit.numeration != 0">
552       <xsl:choose>
553         <xsl:when test="ancestor::qandadiv">
554           <xsl:apply-templates select="ancestor::qandadiv[1]" mode="label.markup"/>
555           <xsl:apply-templates select="ancestor::qandadiv[1]"
556                                mode="intralabel.punctuation"/>
557         </xsl:when>
558         <xsl:when test="$lparent.prefix != ''">
559           <xsl:apply-templates select="$lparent" mode="label.markup"/>
560           <xsl:apply-templates select="$lparent" mode="intralabel.punctuation"/>
561         </xsl:when>
562       </xsl:choose>
563     </xsl:if>
564   </xsl:variable>
565
566   <xsl:variable name="inhlabel"
567                 select="ancestor-or-self::qandaset/@defaultlabel[1]"/>
568
569   <xsl:variable name="deflabel">
570     <xsl:choose>
571       <xsl:when test="$inhlabel != ''">
572         <xsl:value-of select="$inhlabel"/>
573       </xsl:when>
574       <xsl:otherwise>
575         <xsl:value-of select="$qanda.defaultlabel"/>
576       </xsl:otherwise>
577     </xsl:choose>
578   </xsl:variable>
579
580   <xsl:variable name="label" select="label"/>
581
582   <xsl:choose>
583     <xsl:when test="count($label)>0">
584       <xsl:apply-templates select="$label"/>
585     </xsl:when>
586
587     <xsl:when test="$deflabel = 'qanda' and local-name(.) = 'question'">
588       <xsl:call-template name="gentext">
589         <xsl:with-param name="key" select="'Question'"/>
590       </xsl:call-template>
591     </xsl:when>
592
593     <xsl:when test="$deflabel = 'qanda' and local-name(.) = 'answer'">
594       <xsl:call-template name="gentext">
595         <xsl:with-param name="key" select="'Answer'"/>
596       </xsl:call-template>
597     </xsl:when>
598
599     <xsl:when test="$deflabel = 'number' and local-name(.) = 'question'">
600       <xsl:value-of select="$prefix"/>
601       <xsl:number level="multiple" count="qandaentry" format="1"/>
602     </xsl:when>
603   </xsl:choose>
604 </xsl:template>
605
606 <xsl:template match="bibliography|glossary|index|setindex" mode="label.markup">
607   <xsl:if test="@label">
608     <xsl:value-of select="@label"/>
609   </xsl:if>
610 </xsl:template>
611
612 <xsl:template match="figure|table|example" mode="label.markup">
613   <xsl:variable name="pchap"
614                 select="ancestor::chapter
615                         |ancestor::appendix
616                         |ancestor::article[ancestor::book]"/>
617
618   <xsl:variable name="prefix">
619     <xsl:if test="count($pchap) &gt; 0">
620       <xsl:apply-templates select="$pchap" mode="label.markup"/>
621     </xsl:if>
622   </xsl:variable>
623
624   <xsl:choose>
625     <xsl:when test="@label">
626       <xsl:value-of select="@label"/>
627     </xsl:when>
628     <xsl:otherwise>
629       <xsl:choose>
630         <xsl:when test="count($pchap)>0">
631           <xsl:if test="$prefix != ''">
632             <xsl:apply-templates select="$pchap" mode="label.markup"/>
633             <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/>
634           </xsl:if>
635           <xsl:number format="1" from="chapter|appendix" level="any"/>
636         </xsl:when>
637         <xsl:otherwise>
638           <xsl:number format="1" from="book|article" level="any"/>
639         </xsl:otherwise>
640       </xsl:choose>
641     </xsl:otherwise>
642   </xsl:choose>
643 </xsl:template>
644
645 <xsl:template match="procedure" mode="label.markup">
646   <xsl:variable name="pchap"
647                 select="ancestor::chapter
648                         |ancestor::appendix
649                         |ancestor::article[ancestor::book]"/>
650
651   <xsl:variable name="prefix">
652     <xsl:if test="count($pchap) &gt; 0">
653       <xsl:apply-templates select="$pchap" mode="label.markup"/>
654     </xsl:if>
655   </xsl:variable>
656
657   <xsl:choose>
658     <xsl:when test="@label">
659       <xsl:value-of select="@label"/>
660     </xsl:when>
661     <xsl:when test="$formal.procedures = 0">
662       <!-- No label -->
663     </xsl:when>
664     <xsl:otherwise>
665       <xsl:choose>
666         <xsl:when test="count($pchap)>0">
667           <xsl:if test="$prefix != ''">
668             <xsl:apply-templates select="$pchap" mode="label.markup"/>
669             <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/>
670           </xsl:if>
671           <xsl:number count="procedure[title]" format="1" 
672                       from="chapter|appendix" level="any"/>
673         </xsl:when>
674         <xsl:otherwise>
675           <xsl:number count="procedure[title]" format="1" 
676                       from="book|article" level="any"/>
677         </xsl:otherwise>
678       </xsl:choose>
679     </xsl:otherwise>
680   </xsl:choose>
681 </xsl:template>
682
683 <xsl:template match="equation" mode="label.markup">
684   <xsl:variable name="pchap"
685                 select="ancestor::chapter
686                         |ancestor::appendix
687                         |ancestor::article[ancestor::book]"/>
688
689   <xsl:variable name="prefix">
690     <xsl:if test="count($pchap) &gt; 0">
691       <xsl:apply-templates select="$pchap" mode="label.markup"/>
692     </xsl:if>
693   </xsl:variable>
694
695   <xsl:choose>
696     <xsl:when test="@label">
697       <xsl:value-of select="@label"/>
698     </xsl:when>
699     <xsl:otherwise>
700       <xsl:choose>
701         <xsl:when test="count($pchap)>0">
702           <xsl:if test="$prefix != ''">
703             <xsl:apply-templates select="$pchap" mode="label.markup"/>
704             <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/>
705           </xsl:if>
706           <xsl:number format="1" count="equation[title]" from="chapter|appendix" level="any"/>
707         </xsl:when>
708         <xsl:otherwise>
709           <xsl:number format="1" count="equation[title]" from="book|article" level="any"/>
710         </xsl:otherwise>
711       </xsl:choose>
712     </xsl:otherwise>
713   </xsl:choose>
714 </xsl:template>
715
716 <xsl:template match="orderedlist/listitem" mode="label.markup">
717   <xsl:variable name="numeration">
718     <xsl:call-template name="list.numeration">
719       <xsl:with-param name="node" select="parent::orderedlist"/>
720     </xsl:call-template>
721   </xsl:variable>
722
723   <xsl:variable name="type">
724     <xsl:choose>
725       <xsl:when test="$numeration='arabic'">1</xsl:when>
726       <xsl:when test="$numeration='loweralpha'">a</xsl:when>
727       <xsl:when test="$numeration='lowerroman'">i</xsl:when>
728       <xsl:when test="$numeration='upperalpha'">A</xsl:when>
729       <xsl:when test="$numeration='upperroman'">I</xsl:when>
730       <!-- What!? This should never happen -->
731       <xsl:otherwise>
732         <xsl:message>
733           <xsl:text>Unexpected numeration: </xsl:text>
734           <xsl:value-of select="$numeration"/>
735         </xsl:message>
736         <xsl:value-of select="1."/>
737       </xsl:otherwise>
738     </xsl:choose>
739   </xsl:variable>
740
741   <xsl:variable name="item-number">
742     <xsl:call-template name="orderedlist-item-number"/>
743   </xsl:variable>
744
745   <xsl:number value="$item-number" format="{$type}"/>
746 </xsl:template>
747
748 <xsl:template match="abstract" mode="label.markup">
749   <!-- nop -->
750 </xsl:template>
751
752 <!-- ============================================================ -->
753
754 <xsl:template name="label.this.section">
755   <xsl:param name="section" select="."/>
756
757   <xsl:variable name="level">
758     <xsl:call-template name="section.level"/>
759   </xsl:variable>
760
761   <xsl:choose>
762     <xsl:when test="$level &lt;= $section.autolabel.max.depth">      
763       <xsl:value-of select="$section.autolabel"/>
764     </xsl:when>
765     <xsl:otherwise>0</xsl:otherwise>
766   </xsl:choose>
767 </xsl:template>
768
769 <doc:template name="label.this.section" xmlns="">
770 <refpurpose>Returns true if $section should be labelled</refpurpose>
771 <refdescription>
772 <para>Returns true if the specified section should be labelled.
773 By default, this template returns zero unless 
774 the section level is less than or equal to the value of the
775 <literal>$section.autolabel.max.depth</literal> parameter, in
776 which case it returns
777 <literal>$section.autolabel</literal>.
778 Custom stylesheets may override it to get more selective behavior.</para>
779 </refdescription>
780 </doc:template>
781
782 <!-- ============================================================ -->
783
784 <xsl:template name="default.autolabel.format">
785   <xsl:param name="context" select="."/>
786   <xsl:choose>
787     <xsl:when test="local-name($context) = 'appendix'">
788       <xsl:value-of select="'A'"/>
789     </xsl:when>
790     <xsl:when test="local-name($context) = 'part'">
791       <xsl:value-of select="'I'"/>
792     </xsl:when>
793     <xsl:otherwise>1</xsl:otherwise>
794   </xsl:choose>  
795 </xsl:template>
796   
797 <xsl:template name="autolabel.format">
798   <xsl:param name="context" select="."/>
799   <xsl:param name="format"/>
800
801   <xsl:choose>
802     <xsl:when test="string($format) != 0">
803       <xsl:choose>
804         <xsl:when test="$format='arabic' or $format='1'">1</xsl:when>
805         <xsl:when test="$format='loweralpha' or $format='a'">
806           <xsl:value-of select="'a'"/>
807         </xsl:when>
808         <xsl:when test="$format='lowerroman' or $format='i'">
809           <xsl:value-of select="'i'"/>
810         </xsl:when>
811         <xsl:when test="$format='upperalpha' or $format='A'">
812           <xsl:value-of select="'A'"/>
813         </xsl:when>
814         <xsl:when test="$format='upperroman' or $format='I'">
815           <xsl:value-of select="'I'"/>
816         </xsl:when>      
817         <xsl:otherwise>
818           <xsl:message>
819             <xsl:text>Unexpected </xsl:text><xsl:value-of select="local-name(.)"/><xsl:text>.autolabel value: </xsl:text>
820             <xsl:value-of select="$format"/><xsl:text>; using default.</xsl:text>
821           </xsl:message>
822           <xsl:call-template name="default.autolabel.format"/>
823         </xsl:otherwise>
824       </xsl:choose>
825     </xsl:when>
826   </xsl:choose>
827 </xsl:template>
828
829 <doc:template name="autolabel.format" xmlns="">
830 <refpurpose>Returns format for autolabel parameters</refpurpose>
831 <refdescription>
832 <para>Returns format passed as parameter if non zero. Supported
833   format are 'arabic' or '1', 'loweralpha' or 'a', 'lowerroman' or 'i', 
834   'uppoerlapha' or 'A', 'upperroman' or 'I'. If its not one of these then 
835   returns the default format.</para>
836 </refdescription>
837 </doc:template>
838
839 <!-- ============================================================ -->
840
841 </xsl:stylesheet>