trying to get HEAD building again. If you want the code
[kai/samba-autobuild/.git] / docs / docbook / xslt / db2latex / labelid.mod.xsl
1 <?xml version='1.0'?>
2 <!--############################################################################# 
3 |- #############################################################################
4 |                                                                                                               
5 |   PURPOSE: When this template is called, it marks the object with a label
6 | and an hypertarget.
7 + ############################################################################## -->
8
9 <xsl:stylesheet 
10     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
11     xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
12     exclude-result-prefixes="doc" version='1.0'>
13
14
15
16     <!--############################################################################# -->
17     <!-- DOCUMENTATION                                                                -->
18     <doc:reference id="labelid" xmlns="">
19         <referenceinfo>
20             <releaseinfo role="meta">
21             </releaseinfo>
22         <authorgroup>
23             <author> <firstname>Ramon</firstname> <surname>Casellas</surname> </author>
24             <author> <firstname>James</firstname> <surname>Devenish</surname> </author>
25         </authorgroup>
26             <copyright>
27                 <year>2000</year> <year>2001</year> <year>2002</year> <year>2003</year>
28                 <holder>Ramon Casellas</holder>
29             </copyright>
30         </referenceinfo>
31
32         <title>Labels <filename>labelid.mod.xsl</filename></title>
33         <partintro>
34             <section><title>Introduction</title>
35                 <para></para>
36             </section>
37         </partintro>
38     </doc:reference>
39
40
41
42     <doc:template name="label.id" xmlns="">
43         <refpurpose>Marks the current object with a label.</refpurpose>
44         <refdescription>
45             <para>This template marks the current object with a <literal>
46                     \label{.}</literal>. The passed argument indicates the object whose 
47                 <literal>id attribute</literal> is used to generate the label.
48                 In this sense, in most cases its the current node itself.
49                 If the used object has not an id attribute, a unique id is
50                 obtained by means of the <literal>generate-id</literal> function.
51                 Moreover, if we are using the hyperref package, a hypertarget is
52                 also defined for this object. </para>
53         </refdescription>
54         <refparameter>
55             <variablelist>
56                 <varlistentry><term>object</term>
57                     <listitem><para>The node whose id is to be used.</para></listitem>
58                 </varlistentry>
59             </variablelist>
60         </refparameter>
61         <refreturn>
62             <para>This template returns the id that has been used to label the
63                 object.</para>
64         </refreturn>
65     </doc:template>
66
67     <xsl:template name="label.id">
68         <xsl:text>\label{</xsl:text>
69         <xsl:call-template name="generate.label.id"/>
70         <xsl:text>}</xsl:text>
71         </xsl:template>
72
73     <xsl:template name="generate.label.id">
74         <xsl:param name="object"        select="."/>
75         <xsl:variable name="id">
76             <xsl:choose>
77                 <xsl:when test="$object/@id">
78                     <xsl:value-of select="$object/@id"/>
79                 </xsl:when>
80                 <xsl:otherwise>
81                     <xsl:value-of select="generate-id($object)"/>
82                 </xsl:otherwise>
83             </xsl:choose>
84         </xsl:variable>
85         <xsl:value-of select="normalize-space($id)"/>
86     </xsl:template>
87
88
89
90
91     <!--
92     <xsl:template match="*" mode="label.content">
93         <xsl:message>
94             <xsl:text>Request for label of unexpected element: </xsl:text>
95             <xsl:value-of select="name(.)"/>
96         </xsl:message>
97     </xsl:template>
98
99     <xsl:template match="set|book" mode="label.content">
100         <xsl:param name="punct">.</xsl:param>
101         <xsl:if test="@label">
102             <xsl:value-of select="@label"/>
103             <xsl:value-of select="$punct"/>
104         </xsl:if>
105     </xsl:template>
106
107     <xsl:template match="part" mode="label.content">
108         <xsl:param name="punct">.</xsl:param>
109         <xsl:choose>
110             <xsl:when test="@label">
111                 <xsl:value-of select="@label"/>
112                 <xsl:value-of select="$punct"/>
113             </xsl:when>
114             <xsl:when test="$part.autolabel != 0">
115                 <xsl:number from="book" count="part" format="I"/>
116                 <xsl:value-of select="$punct"/>
117             </xsl:when>
118         </xsl:choose>
119     </xsl:template>
120
121
122     <xsl:template match="preface" mode="label.content">
123         <xsl:param name="punct">.</xsl:param>
124         <xsl:choose>
125             <xsl:when test="@label">
126                 <xsl:value-of select="@label"/>
127                 <xsl:value-of select="$punct"/>
128             </xsl:when>
129             <xsl:when test="$preface.autolabel != 0">
130                 <xsl:number from="book" count="preface" format="1" level="any"/>
131                 <xsl:value-of select="$punct"/>
132             </xsl:when>
133         </xsl:choose>
134     </xsl:template>
135
136     <xsl:template match="chapter" mode="label.content">
137         <xsl:param name="punct">.</xsl:param>
138         <xsl:choose>
139             <xsl:when test="@label">
140                 <xsl:value-of select="@label"/>
141                 <xsl:value-of select="$punct"/>
142             </xsl:when>
143             <xsl:when test="$chapter.autolabel != 0">
144                 <xsl:number from="book" count="chapter" format="1" level="any"/>
145                 <xsl:value-of select="$punct"/>
146             </xsl:when>
147         </xsl:choose>
148     </xsl:template>
149
150     <xsl:template match="appendix" mode="label.content">
151         <xsl:param name="punct">.</xsl:param>
152         <xsl:choose>
153             <xsl:when test="@label">
154                 <xsl:value-of select="@label"/>
155                 <xsl:value-of select="$punct"/>
156             </xsl:when>
157             <xsl:when test="$chapter.autolabel != 0">
158                 <xsl:number from="book" count="appendix" format="A" level="any"/>
159                 <xsl:value-of select="$punct"/>
160             </xsl:when>
161         </xsl:choose>
162     </xsl:template>
163
164     <xsl:template match="article" mode="label.content">
165         <xsl:param name="punct">.</xsl:param>
166         <xsl:if test="@label">
167             <xsl:value-of select="@label"/>
168             <xsl:value-of select="$punct"/>
169         </xsl:if>
170     </xsl:template>
171
172
173     <xsl:template match="dedication|colophon" mode="label.content">
174         <xsl:param name="punct">.</xsl:param>
175         <xsl:if test="@label">
176             <xsl:value-of select="@label"/>
177             <xsl:value-of select="$punct"/>
178         </xsl:if>
179     </xsl:template>
180
181     <xsl:template match="reference" mode="label.content">
182         <xsl:param name="punct">.</xsl:param>
183         <xsl:choose>
184             <xsl:when test="@label">
185                 <xsl:value-of select="@label"/>
186                 <xsl:value-of select="$punct"/>
187             </xsl:when>
188             <xsl:when test="$part.autolabel != 0">
189                 <xsl:number from="book" count="reference" format="I" level="any"/>
190                 <xsl:value-of select="$punct"/>
191             </xsl:when>
192         </xsl:choose>
193     </xsl:template>
194
195     <xsl:template match="refentry" mode="label.content">
196         <xsl:param name="punct">.</xsl:param>
197         <xsl:if test="@label">
198             <xsl:value-of select="@label"/>
199             <xsl:value-of select="$punct"/>
200         </xsl:if>
201     </xsl:template>
202
203     <xsl:template match="section" mode="label.content">
204         <xsl:param name="punct">.</xsl:param>
205
206         <xsl:if test="local-name(..) = 'section'">
207             <xsl:apply-templates select=".." mode="label.content">
208                 <xsl:with-param name="punct">.</xsl:with-param>
209             </xsl:apply-templates>
210         </xsl:if>
211
212         <xsl:variable name="parent.is.component">
213             <xsl:call-template name="is.component">
214                 <xsl:with-param name="node" select=".."/>
215             </xsl:call-template>
216         </xsl:variable>
217
218         <xsl:variable name="label">
219             <xsl:call-template name="label.this.section">
220                 <xsl:with-param name="section" select="."/>
221             </xsl:call-template>
222         </xsl:variable>
223
224         <xsl:if test="$section.label.includes.component.label != 0
225             and $parent.is.component != 0">
226             <xsl:apply-templates select=".." mode="label.content">
227                 <xsl:with-param name="punct">.</xsl:with-param>
228             </xsl:apply-templates>
229         </xsl:if>
230
231         <xsl:choose>
232             <xsl:when test="@label">
233                 <xsl:value-of select="@label"/>
234                 <xsl:value-of select="$punct"/>
235             </xsl:when>
236             <xsl:when test="$label != 0">
237                 <xsl:number count="section"/>
238                 <xsl:value-of select="$punct"/>
239             </xsl:when>
240         </xsl:choose>
241     </xsl:template>
242
243     <xsl:template match="sect1" mode="label.content">
244         <xsl:param name="punct">.</xsl:param>
245
246         <xsl:variable name="parent.is.component">
247             <xsl:call-template name="is.component">
248                 <xsl:with-param name="node" select=".."/>
249             </xsl:call-template>
250         </xsl:variable>
251         <xsl:if test="$section.label.includes.component.label != 0
252             and $parent.is.component">
253             <xsl:apply-templates select=".." mode="label.content">
254                 <xsl:with-param name="punct">.</xsl:with-param>
255             </xsl:apply-templates>
256         </xsl:if>
257
258         <xsl:choose>
259             <xsl:when test="@label">
260                 <xsl:value-of select="@label"/>
261                 <xsl:value-of select="$punct"/>
262             </xsl:when>
263             <xsl:when test="$section.autolabel != 0">
264                 <xsl:number count="sect1"/>
265                 <xsl:value-of select="$punct"/>
266             </xsl:when>
267         </xsl:choose>
268     </xsl:template>
269
270     <xsl:template match="sect2|sect3|sect4|sect5" mode="label.content">
271         <xsl:param name="punct">.</xsl:param>
272
273         <xsl:apply-templates select=".." mode="label.content">
274             <xsl:with-param name="punct">.</xsl:with-param>
275         </xsl:apply-templates>
276
277         <xsl:choose>
278             <xsl:when test="@label">
279                 <xsl:value-of select="@label"/>
280                 <xsl:value-of select="$punct"/>
281             </xsl:when>
282             <xsl:when test="$section.autolabel != 0">
283                 <xsl:choose>
284                     <xsl:when test="local-name(.) = 'sect2'">
285                         <xsl:number count="sect2"/>
286                     </xsl:when>
287                     <xsl:when test="local-name(.) = 'sect3'">
288                         <xsl:number count="sect3"/>
289                     </xsl:when>
290                     <xsl:when test="local-name(.) = 'sect4'">
291                         <xsl:number count="sect4"/>
292                     </xsl:when>
293                     <xsl:when test="local-name(.) = 'sect5'">
294                         <xsl:number count="sect5"/>
295                     </xsl:when>
296                     <xsl:otherwise>
297                         <xsl:message>label.content: this can't happen!</xsl:message>
298                     </xsl:otherwise>
299                 </xsl:choose>
300                 <xsl:value-of select="$punct"/>
301             </xsl:when>
302         </xsl:choose>
303     </xsl:template>
304     <xsl:template match="refsect1|refsect2|refsect3" mode="label.content">
305         <xsl:param name="punct">.</xsl:param>
306         <xsl:choose>
307             <xsl:when test="@label">
308                 <xsl:value-of select="@label"/>
309                 <xsl:value-of select="$punct"/>
310             </xsl:when>
311             <xsl:when test="$section.autolabel != 0">
312                 <xsl:number level="multiple" count="refsect1|refsect2|refsect3"/>
313                 <xsl:value-of select="$punct"/>
314             </xsl:when>
315         </xsl:choose>
316     </xsl:template>
317
318     <xsl:template match="simplesect" mode="label.content">
319         <xsl:param name="punct">.</xsl:param>
320         <xsl:choose>
321             <xsl:when test="@label">
322                 <xsl:value-of select="@label"/>
323                 <xsl:value-of select="$punct"/>
324             </xsl:when>
325             <xsl:when test="$section.autolabel != 0">
326                 <xsl:number level="multiple" count="section
327                     |sect1|sect2|sect3|sect4|sect5
328                     |refsect1|refsect2|refsect3
329                     |simplesect"/>
330                 <xsl:value-of select="$punct"/>
331             </xsl:when>
332         </xsl:choose>
333     </xsl:template>
334
335     <xsl:template match="qandadiv" mode="label.content">
336         <xsl:param name="punct">.</xsl:param>
337         <xsl:variable name="prefix">
338             <xsl:if test="$qanda.inherit.numeration != 0">
339                 <xsl:variable name="lparent" select="(ancestor::set
340                     |ancestor::book
341                     |ancestor::chapter
342                     |ancestor::appendix
343                     |ancestor::preface
344                     |ancestor::section
345                     |ancestor::simplesect
346                     |ancestor::sect1
347                     |ancestor::sect2
348                     |ancestor::sect3
349                     |ancestor::sect4
350                     |ancestor::sect5
351                     |ancestor::refsect1
352                     |ancestor::refsect2
353                     |ancestor::refsect3)[last()]"/>
354                 <xsl:if test="count($lparent)>0">
355                     <xsl:apply-templates select="$lparent" mode="label.content"/>
356                 </xsl:if>
357             </xsl:if>
358         </xsl:variable>
359         <xsl:choose>
360             <xsl:when test="@label">
361                 <xsl:value-of select="$prefix"/>
362                 <xsl:value-of select="@label"/>
363                 <xsl:value-of select="$punct"/>
364             </xsl:when>
365             <xsl:when test="$qandadiv.autolabel != 0">
366                 <xsl:value-of select="$prefix"/>
367                 <xsl:number level="multiple" count="qandadiv" format="1"/>
368                 <xsl:value-of select="$punct"/>
369             </xsl:when>
370         </xsl:choose>
371     </xsl:template>
372
373     <xsl:template match="question|answer" mode="label.content">
374         <xsl:param name="punct">.</xsl:param>
375         <xsl:variable name="prefix">
376             <xsl:if test="$qanda.inherit.numeration != 0">
377                 <xsl:variable name="lparent" select="(ancestor::set
378                     |ancestor::book
379                     |ancestor::chapter
380                     |ancestor::appendix
381                     |ancestor::preface
382                     |ancestor::section
383                     |ancestor::simplesect
384                     |ancestor::sect1
385                     |ancestor::sect2
386                     |ancestor::sect3
387                     |ancestor::sect4
388                     |ancestor::sect5
389                     |ancestor::refsect1
390                     |ancestor::refsect2
391                     |ancestor::refsect3
392                     |ancestor::qandadiv)[last()]"/>
393                 <xsl:if test="count($lparent)>0">
394                     <xsl:apply-templates select="$lparent" mode="label.content"/>
395                 </xsl:if>
396             </xsl:if>
397         </xsl:variable>
398
399         <xsl:variable name="inhlabel"
400             select="ancestor-or-self::qandaset/@defaultlabel[1]"/>
401
402         <xsl:variable name="deflabel">
403             <xsl:choose>
404                 <xsl:when test="$inhlabel != ''">
405                     <xsl:value-of select="$inhlabel"/>
406                 </xsl:when>
407                 <xsl:otherwise>
408                     <xsl:value-of select="$qanda.defaultlabel"/>
409                 </xsl:otherwise>
410             </xsl:choose>
411         </xsl:variable>
412
413         <xsl:variable name="label" select="label"/>
414
415         <xsl:choose>
416             <xsl:when test="count($label)>0">
417                 <xsl:value-of select="$prefix"/>
418                 <xsl:apply-templates select="$label"/>
419                 <xsl:value-of select="$punct"/>
420             </xsl:when>
421
422             <xsl:when test="$deflabel = 'qanda'">
423                 <xsl:call-template name="gentext.element.name"/>
424             </xsl:when>
425
426             <xsl:when test="$deflabel = 'number'">
427                 <xsl:if test="name(.) = 'question'">
428                     <xsl:value-of select="$prefix"/>
429                     <xsl:number level="multiple" count="qandaentry" format="1"/>
430                     <xsl:value-of select="$punct"/>
431                 </xsl:if>
432             </xsl:when>
433         </xsl:choose>
434     </xsl:template>
435
436     <xsl:template match="bibliography|glossary|index" mode="label.content">
437         <xsl:param name="punct">.</xsl:param>
438         <xsl:if test="@label">
439             <xsl:value-of select="@label"/>
440             <xsl:value-of select="$punct"/>
441         </xsl:if>
442     </xsl:template>
443
444     <xsl:template match="figure|table|example|equation" mode="label.content">
445         <xsl:param name="punct">.</xsl:param>
446         <xsl:choose>
447             <xsl:when test="@label">
448                 <xsl:value-of select="@label"/>
449                 <xsl:value-of select="$punct"/>
450             </xsl:when>
451             <xsl:otherwise>
452                 <xsl:variable name="pchap"
453                     select="ancestor::chapter|ancestor::appendix"/>
454                 <xsl:choose>
455                     <xsl:when test="count($pchap)>0">
456                         <xsl:apply-templates select="$pchap" mode="label.content">
457                             <xsl:with-param name="punct">.</xsl:with-param>
458                         </xsl:apply-templates>
459                         <xsl:number format="1" from="chapter|appendix" level="any"/>
460                         <xsl:value-of select="$punct"/>
461                     </xsl:when>
462                     <xsl:otherwise>
463                         <xsl:number format="1" from="book|article" level="any"/>
464                         <xsl:value-of select="$punct"/>
465                     </xsl:otherwise>
466                 </xsl:choose>
467             </xsl:otherwise>
468         </xsl:choose>
469     </xsl:template>
470
471     <xsl:template match="abstract" mode="label.content">
472         <xsl:param name="punct">.</xsl:param>
473     </xsl:template>
474     --> 
475
476 </xsl:stylesheet>