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