2 <!--#############################################################################
3 | $Id: labelid.mod.xsl,v 1.1.2.1 2003/05/01 14:06:14 jelmer Exp $
4 |- #############################################################################
7 | PURPOSE: When this template is called, it marks the object with a label
9 + ############################################################################## -->
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'>
18 <!--############################################################################# -->
19 <!-- DOCUMENTATION -->
20 <doc:reference id="labelid" xmlns="">
22 <releaseinfo role="meta">
23 $Id: labelid.mod.xsl,v 1.1.2.1 2003/05/01 14:06:14 jelmer Exp $
26 <author> <firstname>Ramon</firstname> <surname>Casellas</surname> </author>
27 <author> <firstname>James</firstname> <surname>Devenish</surname> </author>
30 <year>2000</year> <year>2001</year> <year>2002</year> <year>2003</year>
31 <holder>Ramon Casellas</holder>
35 <title>Labels <filename>labelid.mod.xsl</filename></title>
37 <section><title>Introduction</title>
45 <doc:template name="label.id" xmlns="">
46 <refpurpose>Marks the current object with a label.</refpurpose>
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>
59 <varlistentry><term>object</term>
60 <listitem><para>The node whose id is to be used.</para></listitem>
65 <para>This template returns the id that has been used to label the
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>
76 <xsl:template name="generate.label.id">
77 <xsl:param name="object" select="."/>
78 <xsl:variable name="id">
80 <xsl:when test="$object/@id">
81 <xsl:value-of select="$object/@id"/>
84 <xsl:value-of select="generate-id($object)"/>
88 <xsl:value-of select="normalize-space($id)"/>
95 <xsl:template match="*" mode="label.content">
97 <xsl:text>Request for label of unexpected element: </xsl:text>
98 <xsl:value-of select="name(.)"/>
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"/>
110 <xsl:template match="part" mode="label.content">
111 <xsl:param name="punct">.</xsl:param>
113 <xsl:when test="@label">
114 <xsl:value-of select="@label"/>
115 <xsl:value-of select="$punct"/>
117 <xsl:when test="$part.autolabel != 0">
118 <xsl:number from="book" count="part" format="I"/>
119 <xsl:value-of select="$punct"/>
125 <xsl:template match="preface" mode="label.content">
126 <xsl:param name="punct">.</xsl:param>
128 <xsl:when test="@label">
129 <xsl:value-of select="@label"/>
130 <xsl:value-of select="$punct"/>
132 <xsl:when test="$preface.autolabel != 0">
133 <xsl:number from="book" count="preface" format="1" level="any"/>
134 <xsl:value-of select="$punct"/>
139 <xsl:template match="chapter" mode="label.content">
140 <xsl:param name="punct">.</xsl:param>
142 <xsl:when test="@label">
143 <xsl:value-of select="@label"/>
144 <xsl:value-of select="$punct"/>
146 <xsl:when test="$chapter.autolabel != 0">
147 <xsl:number from="book" count="chapter" format="1" level="any"/>
148 <xsl:value-of select="$punct"/>
153 <xsl:template match="appendix" mode="label.content">
154 <xsl:param name="punct">.</xsl:param>
156 <xsl:when test="@label">
157 <xsl:value-of select="@label"/>
158 <xsl:value-of select="$punct"/>
160 <xsl:when test="$chapter.autolabel != 0">
161 <xsl:number from="book" count="appendix" format="A" level="any"/>
162 <xsl:value-of select="$punct"/>
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"/>
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"/>
184 <xsl:template match="reference" mode="label.content">
185 <xsl:param name="punct">.</xsl:param>
187 <xsl:when test="@label">
188 <xsl:value-of select="@label"/>
189 <xsl:value-of select="$punct"/>
191 <xsl:when test="$part.autolabel != 0">
192 <xsl:number from="book" count="reference" format="I" level="any"/>
193 <xsl:value-of select="$punct"/>
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"/>
206 <xsl:template match="section" mode="label.content">
207 <xsl:param name="punct">.</xsl:param>
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>
215 <xsl:variable name="parent.is.component">
216 <xsl:call-template name="is.component">
217 <xsl:with-param name="node" select=".."/>
221 <xsl:variable name="label">
222 <xsl:call-template name="label.this.section">
223 <xsl:with-param name="section" select="."/>
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>
235 <xsl:when test="@label">
236 <xsl:value-of select="@label"/>
237 <xsl:value-of select="$punct"/>
239 <xsl:when test="$label != 0">
240 <xsl:number count="section"/>
241 <xsl:value-of select="$punct"/>
246 <xsl:template match="sect1" mode="label.content">
247 <xsl:param name="punct">.</xsl:param>
249 <xsl:variable name="parent.is.component">
250 <xsl:call-template name="is.component">
251 <xsl:with-param name="node" select=".."/>
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>
262 <xsl:when test="@label">
263 <xsl:value-of select="@label"/>
264 <xsl:value-of select="$punct"/>
266 <xsl:when test="$section.autolabel != 0">
267 <xsl:number count="sect1"/>
268 <xsl:value-of select="$punct"/>
273 <xsl:template match="sect2|sect3|sect4|sect5" mode="label.content">
274 <xsl:param name="punct">.</xsl:param>
276 <xsl:apply-templates select=".." mode="label.content">
277 <xsl:with-param name="punct">.</xsl:with-param>
278 </xsl:apply-templates>
281 <xsl:when test="@label">
282 <xsl:value-of select="@label"/>
283 <xsl:value-of select="$punct"/>
285 <xsl:when test="$section.autolabel != 0">
287 <xsl:when test="local-name(.) = 'sect2'">
288 <xsl:number count="sect2"/>
290 <xsl:when test="local-name(.) = 'sect3'">
291 <xsl:number count="sect3"/>
293 <xsl:when test="local-name(.) = 'sect4'">
294 <xsl:number count="sect4"/>
296 <xsl:when test="local-name(.) = 'sect5'">
297 <xsl:number count="sect5"/>
300 <xsl:message>label.content: this can't happen!</xsl:message>
303 <xsl:value-of select="$punct"/>
307 <xsl:template match="refsect1|refsect2|refsect3" mode="label.content">
308 <xsl:param name="punct">.</xsl:param>
310 <xsl:when test="@label">
311 <xsl:value-of select="@label"/>
312 <xsl:value-of select="$punct"/>
314 <xsl:when test="$section.autolabel != 0">
315 <xsl:number level="multiple" count="refsect1|refsect2|refsect3"/>
316 <xsl:value-of select="$punct"/>
321 <xsl:template match="simplesect" mode="label.content">
322 <xsl:param name="punct">.</xsl:param>
324 <xsl:when test="@label">
325 <xsl:value-of select="@label"/>
326 <xsl:value-of select="$punct"/>
328 <xsl:when test="$section.autolabel != 0">
329 <xsl:number level="multiple" count="section
330 |sect1|sect2|sect3|sect4|sect5
331 |refsect1|refsect2|refsect3
333 <xsl:value-of select="$punct"/>
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
348 |ancestor::simplesect
356 |ancestor::refsect3)[last()]"/>
357 <xsl:if test="count($lparent)>0">
358 <xsl:apply-templates select="$lparent" mode="label.content"/>
363 <xsl:when test="@label">
364 <xsl:value-of select="$prefix"/>
365 <xsl:value-of select="@label"/>
366 <xsl:value-of select="$punct"/>
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"/>
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
386 |ancestor::simplesect
395 |ancestor::qandadiv)[last()]"/>
396 <xsl:if test="count($lparent)>0">
397 <xsl:apply-templates select="$lparent" mode="label.content"/>
402 <xsl:variable name="inhlabel"
403 select="ancestor-or-self::qandaset/@defaultlabel[1]"/>
405 <xsl:variable name="deflabel">
407 <xsl:when test="$inhlabel != ''">
408 <xsl:value-of select="$inhlabel"/>
411 <xsl:value-of select="$qanda.defaultlabel"/>
416 <xsl:variable name="label" select="label"/>
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"/>
425 <xsl:when test="$deflabel = 'qanda'">
426 <xsl:call-template name="gentext.element.name"/>
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"/>
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"/>
447 <xsl:template match="figure|table|example|equation" mode="label.content">
448 <xsl:param name="punct">.</xsl:param>
450 <xsl:when test="@label">
451 <xsl:value-of select="@label"/>
452 <xsl:value-of select="$punct"/>
455 <xsl:variable name="pchap"
456 select="ancestor::chapter|ancestor::appendix"/>
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"/>
466 <xsl:number format="1" from="book|article" level="any"/>
467 <xsl:value-of select="$punct"/>
474 <xsl:template match="abstract" mode="label.content">
475 <xsl:param name="punct">.</xsl:param>