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