2 <!--#############################################################################
3 |- #############################################################################
5 | PURPOSE: When this template is called, it marks the object with a label
7 + ############################################################################## -->
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'>
16 <!--############################################################################# -->
17 <!-- DOCUMENTATION -->
18 <doc:reference id="labelid" xmlns="">
20 <releaseinfo role="meta">
23 <author> <firstname>Ramon</firstname> <surname>Casellas</surname> </author>
24 <author> <firstname>James</firstname> <surname>Devenish</surname> </author>
27 <year>2000</year> <year>2001</year> <year>2002</year> <year>2003</year>
28 <holder>Ramon Casellas</holder>
32 <title>Labels <filename>labelid.mod.xsl</filename></title>
34 <section><title>Introduction</title>
42 <doc:template name="label.id" xmlns="">
43 <refpurpose>Marks the current object with a label.</refpurpose>
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>
56 <varlistentry><term>object</term>
57 <listitem><para>The node whose id is to be used.</para></listitem>
62 <para>This template returns the id that has been used to label the
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>
73 <xsl:template name="generate.label.id">
74 <xsl:param name="object" select="."/>
75 <xsl:variable name="id">
77 <xsl:when test="$object/@id">
78 <xsl:value-of select="$object/@id"/>
81 <xsl:value-of select="generate-id($object)"/>
85 <xsl:value-of select="normalize-space($id)"/>
92 <xsl:template match="*" mode="label.content">
94 <xsl:text>Request for label of unexpected element: </xsl:text>
95 <xsl:value-of select="name(.)"/>
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"/>
107 <xsl:template match="part" mode="label.content">
108 <xsl:param name="punct">.</xsl:param>
110 <xsl:when test="@label">
111 <xsl:value-of select="@label"/>
112 <xsl:value-of select="$punct"/>
114 <xsl:when test="$part.autolabel != 0">
115 <xsl:number from="book" count="part" format="I"/>
116 <xsl:value-of select="$punct"/>
122 <xsl:template match="preface" mode="label.content">
123 <xsl:param name="punct">.</xsl:param>
125 <xsl:when test="@label">
126 <xsl:value-of select="@label"/>
127 <xsl:value-of select="$punct"/>
129 <xsl:when test="$preface.autolabel != 0">
130 <xsl:number from="book" count="preface" format="1" level="any"/>
131 <xsl:value-of select="$punct"/>
136 <xsl:template match="chapter" mode="label.content">
137 <xsl:param name="punct">.</xsl:param>
139 <xsl:when test="@label">
140 <xsl:value-of select="@label"/>
141 <xsl:value-of select="$punct"/>
143 <xsl:when test="$chapter.autolabel != 0">
144 <xsl:number from="book" count="chapter" format="1" level="any"/>
145 <xsl:value-of select="$punct"/>
150 <xsl:template match="appendix" mode="label.content">
151 <xsl:param name="punct">.</xsl:param>
153 <xsl:when test="@label">
154 <xsl:value-of select="@label"/>
155 <xsl:value-of select="$punct"/>
157 <xsl:when test="$chapter.autolabel != 0">
158 <xsl:number from="book" count="appendix" format="A" level="any"/>
159 <xsl:value-of select="$punct"/>
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"/>
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"/>
181 <xsl:template match="reference" mode="label.content">
182 <xsl:param name="punct">.</xsl:param>
184 <xsl:when test="@label">
185 <xsl:value-of select="@label"/>
186 <xsl:value-of select="$punct"/>
188 <xsl:when test="$part.autolabel != 0">
189 <xsl:number from="book" count="reference" format="I" level="any"/>
190 <xsl:value-of select="$punct"/>
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"/>
203 <xsl:template match="section" mode="label.content">
204 <xsl:param name="punct">.</xsl:param>
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>
212 <xsl:variable name="parent.is.component">
213 <xsl:call-template name="is.component">
214 <xsl:with-param name="node" select=".."/>
218 <xsl:variable name="label">
219 <xsl:call-template name="label.this.section">
220 <xsl:with-param name="section" select="."/>
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>
232 <xsl:when test="@label">
233 <xsl:value-of select="@label"/>
234 <xsl:value-of select="$punct"/>
236 <xsl:when test="$label != 0">
237 <xsl:number count="section"/>
238 <xsl:value-of select="$punct"/>
243 <xsl:template match="sect1" mode="label.content">
244 <xsl:param name="punct">.</xsl:param>
246 <xsl:variable name="parent.is.component">
247 <xsl:call-template name="is.component">
248 <xsl:with-param name="node" select=".."/>
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>
259 <xsl:when test="@label">
260 <xsl:value-of select="@label"/>
261 <xsl:value-of select="$punct"/>
263 <xsl:when test="$section.autolabel != 0">
264 <xsl:number count="sect1"/>
265 <xsl:value-of select="$punct"/>
270 <xsl:template match="sect2|sect3|sect4|sect5" mode="label.content">
271 <xsl:param name="punct">.</xsl:param>
273 <xsl:apply-templates select=".." mode="label.content">
274 <xsl:with-param name="punct">.</xsl:with-param>
275 </xsl:apply-templates>
278 <xsl:when test="@label">
279 <xsl:value-of select="@label"/>
280 <xsl:value-of select="$punct"/>
282 <xsl:when test="$section.autolabel != 0">
284 <xsl:when test="local-name(.) = 'sect2'">
285 <xsl:number count="sect2"/>
287 <xsl:when test="local-name(.) = 'sect3'">
288 <xsl:number count="sect3"/>
290 <xsl:when test="local-name(.) = 'sect4'">
291 <xsl:number count="sect4"/>
293 <xsl:when test="local-name(.) = 'sect5'">
294 <xsl:number count="sect5"/>
297 <xsl:message>label.content: this can't happen!</xsl:message>
300 <xsl:value-of select="$punct"/>
304 <xsl:template match="refsect1|refsect2|refsect3" mode="label.content">
305 <xsl:param name="punct">.</xsl:param>
307 <xsl:when test="@label">
308 <xsl:value-of select="@label"/>
309 <xsl:value-of select="$punct"/>
311 <xsl:when test="$section.autolabel != 0">
312 <xsl:number level="multiple" count="refsect1|refsect2|refsect3"/>
313 <xsl:value-of select="$punct"/>
318 <xsl:template match="simplesect" mode="label.content">
319 <xsl:param name="punct">.</xsl:param>
321 <xsl:when test="@label">
322 <xsl:value-of select="@label"/>
323 <xsl:value-of select="$punct"/>
325 <xsl:when test="$section.autolabel != 0">
326 <xsl:number level="multiple" count="section
327 |sect1|sect2|sect3|sect4|sect5
328 |refsect1|refsect2|refsect3
330 <xsl:value-of select="$punct"/>
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
345 |ancestor::simplesect
353 |ancestor::refsect3)[last()]"/>
354 <xsl:if test="count($lparent)>0">
355 <xsl:apply-templates select="$lparent" mode="label.content"/>
360 <xsl:when test="@label">
361 <xsl:value-of select="$prefix"/>
362 <xsl:value-of select="@label"/>
363 <xsl:value-of select="$punct"/>
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"/>
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
383 |ancestor::simplesect
392 |ancestor::qandadiv)[last()]"/>
393 <xsl:if test="count($lparent)>0">
394 <xsl:apply-templates select="$lparent" mode="label.content"/>
399 <xsl:variable name="inhlabel"
400 select="ancestor-or-self::qandaset/@defaultlabel[1]"/>
402 <xsl:variable name="deflabel">
404 <xsl:when test="$inhlabel != ''">
405 <xsl:value-of select="$inhlabel"/>
408 <xsl:value-of select="$qanda.defaultlabel"/>
413 <xsl:variable name="label" select="label"/>
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"/>
422 <xsl:when test="$deflabel = 'qanda'">
423 <xsl:call-template name="gentext.element.name"/>
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"/>
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"/>
444 <xsl:template match="figure|table|example|equation" mode="label.content">
445 <xsl:param name="punct">.</xsl:param>
447 <xsl:when test="@label">
448 <xsl:value-of select="@label"/>
449 <xsl:value-of select="$punct"/>
452 <xsl:variable name="pchap"
453 select="ancestor::chapter|ancestor::appendix"/>
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"/>
463 <xsl:number format="1" from="book|article" level="any"/>
464 <xsl:value-of select="$punct"/>
471 <xsl:template match="abstract" mode="label.content">
472 <xsl:param name="punct">.</xsl:param>