2 <!DOCTYPE xsl:stylesheet [
<!ENTITY % xsldoc.ent SYSTEM
"./xsldoc.ent"> %xsldoc.ent; ]
>
3 <!--#############################################################################
4 | $Id: labelid.mod.xsl,v 1.5 2004/01/01 12:26:41 j-devenish Exp $
5 |- #############################################################################
6 | $Author: j-devenish $
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'
>
14 <doc:reference id=
"labelid" xmlns=
"">
16 <releaseinfo role=
"meta">
17 $Id: labelid.mod.xsl,v
1.5 2004/
01/
01 12:
26:
41 j-devenish Exp $
24 <year>2000</year><year>2001</year><year>2002</year><year>2003</year><year>2004</year>
25 <holder>Ramon Casellas
</holder>
28 <doc:revision rcasver=
"1.5">&rev_2003_05;</doc:revision>
31 <title>Labels and Anchors for Cross-referencing
<filename>labelid.mod.xsl
</filename></title>
41 <doc:template xmlns=
"">
42 <refpurpose> Generate
&LaTeX; <function condition=
"latex">label
</function>s
</refpurpose>
46 This template marks the current object with a
<function
47 condition=
"latex">label
</function>.
57 <varlistentry><term>object</term>
58 <listitem><para>The node whose id is to be used.</para></listitem>
67 <listitem><simpara><xref linkend=
"template.generate.label.id"/></simpara></listitem>
71 <xsl:template name=
"label.id">
72 <xsl:text>\label{
</xsl:text>
73 <xsl:call-template name=
"generate.label.id"/>
74 <xsl:text>}
</xsl:text>
77 <doc:template xmlns=
"">
78 <refpurpose> Generate a reliable cross-reference id
</refpurpose>
82 The passed argument indicates the object whose
<sgmltag
83 class=
"attribute">id
</sgmltag> attribute is used to generate the
84 label. In this sense, in most cases its the current node itself. If
85 the used object has not an id attribute, a unique id is obtained by
86 means of the
<literal>generate-id
</literal> function. Moreover, if
87 we are using the hyperref package, a hypertarget is also defined
97 <varlistentry><term>object
</term>
98 <listitem><para>The node whose id is to be used.
</para></listitem>
103 <xsl:template name=
"generate.label.id">
104 <xsl:param name=
"object" select=
"."/>
105 <xsl:variable name=
"id">
107 <xsl:when test=
"$object/@id">
108 <xsl:value-of select=
"$object/@id"/>
111 <xsl:value-of select=
"generate-id($object)"/>
115 <xsl:value-of select=
"normalize-space($id)"/>
119 <xsl:template match="*" mode="label.content">
121 <xsl:text>Request for label of unexpected element: </xsl:text>
122 <xsl:value-of select="name(.)"/>
126 <xsl:template match="set|book" mode="label.content">
127 <xsl:param name="punct">.</xsl:param>
128 <xsl:if test="@label">
129 <xsl:value-of select="@label"/>
130 <xsl:value-of select="$punct"/>
134 <xsl:template match="part" mode="label.content">
135 <xsl:param name="punct">.</xsl:param>
137 <xsl:when test="@label">
138 <xsl:value-of select="@label"/>
139 <xsl:value-of select="$punct"/>
141 <xsl:when test="$part.autolabel != 0">
142 <xsl:number from="book" count="part" format="I"/>
143 <xsl:value-of select="$punct"/>
149 <xsl:template match="preface" mode="label.content">
150 <xsl:param name="punct">.</xsl:param>
152 <xsl:when test="@label">
153 <xsl:value-of select="@label"/>
154 <xsl:value-of select="$punct"/>
156 <xsl:when test="$preface.autolabel != 0">
157 <xsl:number from="book" count="preface" format="1" level="any"/>
158 <xsl:value-of select="$punct"/>
163 <xsl:template match="chapter" mode="label.content">
164 <xsl:param name="punct">.</xsl:param>
166 <xsl:when test="@label">
167 <xsl:value-of select="@label"/>
168 <xsl:value-of select="$punct"/>
170 <xsl:when test="$chapter.autolabel != 0">
171 <xsl:number from="book" count="chapter" format="1" level="any"/>
172 <xsl:value-of select="$punct"/>
177 <xsl:template match="appendix" mode="label.content">
178 <xsl:param name="punct">.</xsl:param>
180 <xsl:when test="@label">
181 <xsl:value-of select="@label"/>
182 <xsl:value-of select="$punct"/>
184 <xsl:when test="$chapter.autolabel != 0">
185 <xsl:number from="book" count="appendix" format="A" level="any"/>
186 <xsl:value-of select="$punct"/>
191 <xsl:template match="article" mode="label.content">
192 <xsl:param name="punct">.</xsl:param>
193 <xsl:if test="@label">
194 <xsl:value-of select="@label"/>
195 <xsl:value-of select="$punct"/>
200 <xsl:template match="dedication|colophon" mode="label.content">
201 <xsl:param name="punct">.</xsl:param>
202 <xsl:if test="@label">
203 <xsl:value-of select="@label"/>
204 <xsl:value-of select="$punct"/>
208 <xsl:template match="reference" mode="label.content">
209 <xsl:param name="punct">.</xsl:param>
211 <xsl:when test="@label">
212 <xsl:value-of select="@label"/>
213 <xsl:value-of select="$punct"/>
215 <xsl:when test="$part.autolabel != 0">
216 <xsl:number from="book" count="reference" format="I" level="any"/>
217 <xsl:value-of select="$punct"/>
222 <xsl:template match="refentry" mode="label.content">
223 <xsl:param name="punct">.</xsl:param>
224 <xsl:if test="@label">
225 <xsl:value-of select="@label"/>
226 <xsl:value-of select="$punct"/>
230 <xsl:template match="section" mode="label.content">
231 <xsl:param name="punct">.</xsl:param>
233 <xsl:if test="local-name(..) = 'section'">
234 <xsl:apply-templates select=".." mode="label.content">
235 <xsl:with-param name="punct">.</xsl:with-param>
236 </xsl:apply-templates>
239 <xsl:variable name="parent.is.component">
240 <xsl:call-template name="is.component">
241 <xsl:with-param name="node" select=".."/>
245 <xsl:variable name="label">
246 <xsl:call-template name="label.this.section">
247 <xsl:with-param name="section" select="."/>
251 <xsl:if test="$section.label.includes.component.label != 0
252 and $parent.is.component != 0">
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="$label != 0">
264 <xsl:number count="section"/>
265 <xsl:value-of select="$punct"/>
270 <xsl:template match="sect1" mode="label.content">
271 <xsl:param name="punct">.</xsl:param>
273 <xsl:variable name="parent.is.component">
274 <xsl:call-template name="is.component">
275 <xsl:with-param name="node" select=".."/>
278 <xsl:if test="$section.label.includes.component.label != 0
279 and $parent.is.component">
280 <xsl:apply-templates select=".." mode="label.content">
281 <xsl:with-param name="punct">.</xsl:with-param>
282 </xsl:apply-templates>
286 <xsl:when test="@label">
287 <xsl:value-of select="@label"/>
288 <xsl:value-of select="$punct"/>
290 <xsl:when test="$section.autolabel != 0">
291 <xsl:number count="sect1"/>
292 <xsl:value-of select="$punct"/>
297 <xsl:template match="sect2|sect3|sect4|sect5" mode="label.content">
298 <xsl:param name="punct">.</xsl:param>
300 <xsl:apply-templates select=".." mode="label.content">
301 <xsl:with-param name="punct">.</xsl:with-param>
302 </xsl:apply-templates>
305 <xsl:when test="@label">
306 <xsl:value-of select="@label"/>
307 <xsl:value-of select="$punct"/>
309 <xsl:when test="$section.autolabel != 0">
311 <xsl:when test="local-name(.) = 'sect2'">
312 <xsl:number count="sect2"/>
314 <xsl:when test="local-name(.) = 'sect3'">
315 <xsl:number count="sect3"/>
317 <xsl:when test="local-name(.) = 'sect4'">
318 <xsl:number count="sect4"/>
320 <xsl:when test="local-name(.) = 'sect5'">
321 <xsl:number count="sect5"/>
324 <xsl:message>label.content: this can't happen!</xsl:message>
327 <xsl:value-of select="$punct"/>
331 <xsl:template match="refsect1|refsect2|refsect3" mode="label.content">
332 <xsl:param name="punct">.</xsl:param>
334 <xsl:when test="@label">
335 <xsl:value-of select="@label"/>
336 <xsl:value-of select="$punct"/>
338 <xsl:when test="$section.autolabel != 0">
339 <xsl:number level="multiple" count="refsect1|refsect2|refsect3"/>
340 <xsl:value-of select="$punct"/>
345 <xsl:template match="simplesect" mode="label.content">
346 <xsl:param name="punct">.</xsl:param>
348 <xsl:when test="@label">
349 <xsl:value-of select="@label"/>
350 <xsl:value-of select="$punct"/>
352 <xsl:when test="$section.autolabel != 0">
353 <xsl:number level="multiple" count="section
354 |sect1|sect2|sect3|sect4|sect5
355 |refsect1|refsect2|refsect3
357 <xsl:value-of select="$punct"/>
362 <xsl:template match="qandadiv" mode="label.content">
363 <xsl:param name="punct">.</xsl:param>
364 <xsl:variable name="prefix">
365 <xsl:if test="$qanda.inherit.numeration != 0">
366 <xsl:variable name="lparent" select="(ancestor::set
372 |ancestor::simplesect
380 |ancestor::refsect3)[last()]"/>
381 <xsl:if test="count($lparent)>0">
382 <xsl:apply-templates select="$lparent" mode="label.content"/>
387 <xsl:when test="@label">
388 <xsl:value-of select="$prefix"/>
389 <xsl:value-of select="@label"/>
390 <xsl:value-of select="$punct"/>
392 <xsl:when test="$qandadiv.autolabel != 0">
393 <xsl:value-of select="$prefix"/>
394 <xsl:number level="multiple" count="qandadiv" format="1"/>
395 <xsl:value-of select="$punct"/>
400 <xsl:template match="question|answer" mode="label.content">
401 <xsl:param name="punct">.</xsl:param>
402 <xsl:variable name="prefix">
403 <xsl:if test="$qanda.inherit.numeration != 0">
404 <xsl:variable name="lparent" select="(ancestor::set
410 |ancestor::simplesect
419 |ancestor::qandadiv)[last()]"/>
420 <xsl:if test="count($lparent)>0">
421 <xsl:apply-templates select="$lparent" mode="label.content"/>
426 <xsl:variable name="inhlabel"
427 select="ancestor-or-self::qandaset/@defaultlabel[1]"/>
429 <xsl:variable name="deflabel">
431 <xsl:when test="$inhlabel != ''">
432 <xsl:value-of select="$inhlabel"/>
435 <xsl:value-of select="$qanda.defaultlabel"/>
440 <xsl:variable name="label" select="label"/>
443 <xsl:when test="count($label)>0">
444 <xsl:value-of select="$prefix"/>
445 <xsl:apply-templates select="$label"/>
446 <xsl:value-of select="$punct"/>
449 <xsl:when test="$deflabel = 'qanda'">
450 <xsl:call-template name="gentext.element.name"/>
453 <xsl:when test="$deflabel = 'number'">
454 <xsl:if test="name(.) = 'question'">
455 <xsl:value-of select="$prefix"/>
456 <xsl:number level="multiple" count="qandaentry" format="1"/>
457 <xsl:value-of select="$punct"/>
463 <xsl:template match="bibliography|glossary|index" mode="label.content">
464 <xsl:param name="punct">.</xsl:param>
465 <xsl:if test="@label">
466 <xsl:value-of select="@label"/>
467 <xsl:value-of select="$punct"/>
471 <xsl:template match="figure|table|example|equation" mode="label.content">
472 <xsl:param name="punct">.</xsl:param>
474 <xsl:when test="@label">
475 <xsl:value-of select="@label"/>
476 <xsl:value-of select="$punct"/>
479 <xsl:variable name="pchap"
480 select="ancestor::chapter|ancestor::appendix"/>
482 <xsl:when test="count($pchap)>0">
483 <xsl:apply-templates select="$pchap" mode="label.content">
484 <xsl:with-param name="punct">.</xsl:with-param>
485 </xsl:apply-templates>
486 <xsl:number format="1" from="chapter|appendix" level="any"/>
487 <xsl:value-of select="$punct"/>
490 <xsl:number format="1" from="book|article" level="any"/>
491 <xsl:value-of select="$punct"/>
498 <xsl:template match="abstract" mode="label.content">
499 <xsl:param name="punct">.</xsl:param>