2 <!--#############################################################################
3 |- #############################################################################
5 | PURPOSE: Manage XREFs
6 + ############################################################################## -->
9 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
10 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
11 exclude-result-prefixes="doc" version='1.0'>
15 <!--############################################################################# -->
16 <!-- DOCUMENTATION -->
17 <doc:reference id="xref" xmlns="">
19 <releaseinfo role="meta">
22 <author> <surname>Casellas</surname><firstname>Ramon</firstname> </author>
23 <author> <surname>James</surname><firstname>Devenish</firstname> </author>
26 <year>2000</year> <year>2001</year> <year>2002</year> <year>2003</year>
27 <holder>Ramon Casellas</holder>
31 <title>Xref, Cross References <filename>xref.mod.xsl</filename></title>
33 <section><title>Introduction</title>
42 <!--############################################################################# -->
43 <doc:template match="anchor" xmlns="">
44 <refpurpose>Anchor XSL template</refpurpose>
46 <para>The <sgmltag>anchor</sgmltag> element
47 The DB2LaTeX processing of the element is quite straightforward :
48 Map to a <literal>\label</literal>.</para>
51 <!--############################################################################# -->
53 <xsl:template match="anchor">
54 <xsl:text>\hypertarget{</xsl:text>
55 <xsl:value-of select="@id"/>
56 <xsl:text>}{}</xsl:text>
63 <!--############################################################################# -->
64 <doc:template name="id.is.xrefed" xmlns="">
65 <refpurpose>Auxiliary named template</refpurpose>
67 <para>This template returns 1 if there exists somewhere an xref
68 whose linkend is the target's id.</para>
71 <!--############################################################################# -->
73 <xsl:template name="id.is.xrefed">
74 <xsl:param name="i" select="1"/>
75 <xsl:param name="target" select="."/>
76 <xsl:param name="xrefs" select="//xref"/>
78 <xsl:when test="xrefs[i]/@linkend = 'target/@id'">
79 <xsl:value-of select="1"/>
81 <xsl:when test="i = count(xrefs)">
82 <xsl:value-of select="0"/>
85 <xsl:call-template name="id.is.xrefed">
86 <xsl:with-param name="i" select="i+1"/>
96 <!--############################################################################# -->
97 <doc:template name="xref.xreflabel" xmlns="">
98 <refpurpose>Auxiliary named template</refpurpose>
100 <para> Called to process an xreflabel...you might use this to make
101 xreflabels come out in the right font for different targets,
105 <!--############################################################################# -->
107 <xsl:template name="xref.xreflabel">
108 <xsl:param name="target" select="."/>
109 <xsl:value-of select="$target/@xreflabel"/>
117 <!--############################################################################# -->
118 <doc:template match="xref|link" xmlns="">
119 <refpurpose>Xref and Link XSL Template</refpurpose>
123 <!--############################################################################# -->
125 <xsl:template match="xref|link">
126 <xsl:variable name="targets" select="id(@linkend)"/>
127 <xsl:variable name="target" select="$targets[1]"/>
128 <xsl:variable name="refelem" select="local-name($target)"/>
129 <xsl:call-template name="check.id.unique"><xsl:with-param name="linkend" select="@linkend"/></xsl:call-template>
131 <xsl:when test="$refelem=''">
132 <xsl:message><xsl:text>XRef to nonexistent id: </xsl:text><xsl:value-of select="@linkend"/></xsl:message>
133 <xsl:text>XrefId[?</xsl:text>
134 <xsl:if test="local-name(.)='link'"><xsl:apply-templates/></xsl:if>
135 <xsl:text>?]</xsl:text>
138 <!-- This is a link with content ... -->
139 <xsl:when test="local-name(.)='link' and .!=''">
140 <xsl:call-template name="generate.hyperlink">
141 <xsl:with-param name="target" select="$target"/>
142 <xsl:with-param name="text"><xsl:apply-templates/></xsl:with-param>
148 <xsl:when test="@endterm">
149 <xsl:variable name="etargets" select="id(@endterm)"/>
150 <xsl:variable name="etarget" select="$etargets[1]"/>
152 <xsl:when test="count($etarget) = 0">
154 <xsl:value-of select="count($etargets)"/>
155 <xsl:text>Endterm points to nonexistent ID: </xsl:text>
156 <xsl:value-of select="@endterm"/>
158 <xsl:text>[NONEXISTENT ID]</xsl:text>
161 <xsl:call-template name="generate.hyperlink">
162 <xsl:with-param name="target" select="$target"/>
163 <xsl:with-param name="text"><xsl:apply-templates select="$etarget" mode="xref.text"/></xsl:with-param>
168 <!-- If an xreflabel has been specified for the target ... -->
169 <xsl:when test="local-name(.)='xref' and $target/@xreflabel">
170 <xsl:call-template name="generate.hyperlink">
171 <xsl:with-param name="target" select="$target"/>
172 <xsl:with-param name="text">
173 <xsl:text>{[</xsl:text>
174 <xsl:call-template name="xref.xreflabel">
175 <xsl:with-param name="target" select="$target"/>
177 <xsl:text>]}</xsl:text>
182 <xsl:call-template name="generate.hyperlink">
183 <xsl:with-param name="target" select="$target"/>
184 <xsl:with-param name="text"><xsl:apply-templates select="$target" mode="xref-to"/></xsl:with-param>
190 <xsl:if test="$insert.xref.page.number=1 and $refelem!='' and local-name(.)='xref'">
191 <xsl:call-template name="xref.p.subst">
192 <xsl:with-param name="string">
193 <xsl:call-template name="gentext.xref.text">
194 <xsl:with-param name="element.name" select="'page.citation'"/>
195 <xsl:with-param name="default"> [%p]</xsl:with-param>
198 <xsl:with-param name="target" select="$target"/>
203 <doc:template name="generate.hyperlink" xmlns="">
204 <refpurpose> Choose hyperlink syntax </refpurpose>
206 <para>Will use hyperref, if it is available. Otherwise, just outputs
207 unlinked text. If the destination is a citation, a backreference is
208 emitted (even though it is technically a hyperlink, not a citation).
209 If the 'text' arises from an @endterm, then the 'optional argument'
210 syntax of <literal>\cite</literal> is used.</para>
213 <xsl:template name="generate.hyperlink">
214 <xsl:param name="target"/>
215 <xsl:param name="text"/>
216 <xsl:variable name="element" select="local-name($target)"/>
217 <xsl:variable name="citation" select="$element='biblioentry' or $element='bibliomixed'"/>
219 <xsl:when test="$citation and @endterm!=''">
220 <xsl:text>\docbooktolatexcite</xsl:text>
221 <xsl:text>{</xsl:text>
222 <xsl:value-of select="$target/@id"/>
223 <xsl:text>}{</xsl:text>
224 <xsl:call-template name="scape-optionalarg">
225 <xsl:with-param name="string" select="$text"/>
227 <xsl:text>}</xsl:text>
230 <xsl:if test="$latex.use.hyperref=1">
231 <xsl:text>\hyperlink{</xsl:text>
232 <xsl:value-of select="$target/@id"/>
233 <xsl:text>}</xsl:text>
235 <xsl:text>{</xsl:text>
236 <xsl:if test="$citation">
237 <xsl:text>\docbooktolatexbackcite{</xsl:text>
238 <xsl:value-of select="$target/@id"/>
239 <xsl:text>}</xsl:text>
241 <xsl:value-of select="$text"/>
242 <xsl:text>}</xsl:text>
247 <doc:template name="xref.p.subst" xmlns="">
248 <refpurpose>Insert page number into xrefs</refpurpose>
249 <refdescription><para></para></refdescription>
251 <xsl:template name="xref.p.subst">
252 <xsl:param name="string"></xsl:param>
253 <xsl:param name="target" select="."/>
254 <xsl:variable name="subst">%p</xsl:variable>
256 <xsl:when test="contains($string, $subst)">
257 <xsl:value-of select="substring-before($string, $subst)"/>
258 <xsl:text>\pageref*{</xsl:text>
259 <xsl:value-of select="$target/@id"/>
260 <xsl:text>}</xsl:text>
261 <xsl:value-of select="substring-after($string, $subst)"/>
264 <xsl:value-of select="$string"/>
275 <!--############################################################################# -->
276 <doc:template name="number.xref" xmlns="">
277 <refpurpose>Numbering template</refpurpose>
280 Let LaTeX manage the numbering. Otherwise sty files that
281 do specify another numberic (e.g I,II) get messed
285 <!--############################################################################# -->
287 <xsl:template name="number.xref">
288 <xsl:text>{\ref*{</xsl:text><xsl:value-of select="@id"/><xsl:text>}}</xsl:text>
298 <!--############################################################################# -->
299 <doc:template name="cross-reference" xmlns="">
300 <refpurpose>FIXME</refpurpose>
307 <!--############################################################################# -->
309 <xsl:template name="cross-reference">
310 <xsl:param name="target" select="."/>
311 <xsl:param name="refelem" select="local-name($target)"/>
312 <xsl:param name="xref.text">
313 <xsl:call-template name="gentext.xref.text">
314 <xsl:with-param name="element.name" select="$refelem"/>
315 <xsl:with-param name="default">%g %n</xsl:with-param>
318 <xsl:call-template name="subst.xref.text">
319 <xsl:with-param name="xref.text" select="$xref.text"/>
320 <xsl:with-param name="target" select="$target"/>
328 <xsl:template match="*" mode="xref-to">
329 <xsl:param name="target" select="."/>
330 <xsl:param name="refelem" select="local-name($target)"/>
332 <xsl:text>[Don't know what gentext to create for xref to: "</xsl:text>
333 <xsl:value-of select="$refelem"/>
334 <xsl:text>"]</xsl:text>
336 <xsl:text>UNKGENTEXT</xsl:text><xsl:value-of select="$refelem"/>
343 <xsl:template match="formalpara" mode="xref-to">
344 <xsl:param name="target" select="."/>
345 <xsl:param name="refelem" select="local-name($target)"/>
346 <xsl:call-template name="cross-reference">
347 <xsl:with-param name="target" select="$target"/>
352 <xsl:template match="figure|example|table|equation" mode="xref-to">
353 <xsl:param name="target" select="."/>
354 <xsl:param name="refelem" select="local-name($target)"/>
355 <xsl:call-template name="cross-reference">
356 <xsl:with-param name="target" select="$target"/>
361 <xsl:template match="dedication|preface|part|chapter|appendix" mode="xref-to">
362 <xsl:param name="target" select="."/>
363 <xsl:param name="refelem" select="local-name($target)"/>
364 <xsl:call-template name="cross-reference">
365 <xsl:with-param name="target" select="$target"/>
369 <xsl:template match="cmdsynopsis" mode="xref-to">
370 <xsl:param name="target" select="."/>
371 <xsl:param name="refelem" select="local-name($target)"/>
372 <xsl:variable name="command" select="($target//command)[1]"/>
373 <xsl:apply-templates select="$command" mode="xref"/>
376 <xsl:template match="funcsynopsis" mode="xref-to">
377 <xsl:param name="target" select="."/>
378 <xsl:param name="refelem" select="local-name($target)"/>
379 <xsl:variable name="func" select="($target//function)[1]"/>
380 <xsl:apply-templates select="$func" mode="xref"/>
384 <xsl:template match="biblioentry" mode="xref-to">
385 <!-- handles both biblioentry and bibliomixed -->
386 <xsl:param name="target" select="."/>
387 <xsl:param name="refelem" select="local-name($target)"/>
388 <xsl:text>[</xsl:text>
390 <xsl:when test="local-name($target/*[1]) = 'abbrev'">
391 <xsl:apply-templates select="$target/*[1]"/>
394 <xsl:value-of select="@id"/>
397 <xsl:text>]</xsl:text>
402 <xsl:template match="bibliography|glossary|index" mode="xref-to">
403 <xsl:param name="target" select="."/>
404 <xsl:param name="refelem" select="local-name($target)"/>
405 <xsl:call-template name="cross-reference">
406 <xsl:with-param name="target" select="$target"/>
411 <xsl:template match="section|simplesect
412 |sect1|sect2|sect3|sect4|sect5
413 |refsect1|refsect2|refsect3" mode="xref-to">
414 <xsl:param name="target" select="."/>
415 <xsl:param name="refelem" select="local-name($target)"/>
416 <xsl:call-template name="cross-reference">
417 <xsl:with-param name="target" select="$target"/>
421 <xsl:template match="question|answer" mode="xref-to">
422 <xsl:param name="target" select="."/>
423 <xsl:param name="refelem" select="local-name($target)"/>
424 <xsl:call-template name="cross-reference">
425 <xsl:with-param name="target" select="$target"/>
429 <xsl:template match="reference" mode="xref-to">
430 <xsl:param name="target" select="."/>
431 <xsl:param name="refelem" select="local-name($target)"/>
432 <xsl:call-template name="cross-reference">
433 <xsl:with-param name="target" select="$target"/>
437 <xsl:template match="co" mode="xref-to">
438 <xsl:param name="target" select="."/>
439 <xsl:param name="refelem" select="local-name($target)"/>
440 <xsl:apply-templates select="$target" mode="callout-bug"/>
443 <xsl:template match="co" mode="conumber">
444 <xsl:number from="literallayout|programlisting|screen|synopsis"
450 <xsl:template match="book" mode="xref-to">
451 <xsl:param name="target" select="."/>
452 <xsl:param name="refelem" select="local-name($target)"/>
453 <xsl:variable name="title">
455 <xsl:when test="$target/title">
456 <xsl:apply-templates select="$target/title" mode="xref"/>
459 <xsl:apply-templates select="$target/bookinfo/title" mode="xref"/>
463 <xsl:text>{\em </xsl:text> <xsl:copy-of select="$title"/> <xsl:text>}</xsl:text>
467 <xsl:template match="command" mode="xref">
468 <xsl:call-template name="inline.boldseq"/>
471 <xsl:template match="function" mode="xref">
472 <xsl:call-template name="inline.monoseq"/>
478 <!--############################################################################# -->
479 <doc:template match="ulink" xmlns="">
480 <refpurpose>A link that addresses its target by means of a URL (Uniform Resource Locator)</refpurpose>
483 <title>Pertinent Variables</title>
485 <listitem><simpara><xref linkend="param.ulink.show"/></simpara></listitem>
486 <listitem><simpara><xref linkend="param.ulink.footnotes"/></simpara></listitem>
487 <listitem><simpara><xref linkend="latex.hyphenation.tttricks"/></simpara></listitem>
492 <!--############################################################################# -->
495 <xsl:template match="ulink" name="ulink">
496 <xsl:param name="hyphenation">\docbookhyphenateurl</xsl:param>
497 <xsl:param name="url" select="@url"/>
499 <xsl:when test=". = '' or . = $url">
500 <xsl:call-template name="generate.typeset.url">
501 <xsl:with-param name="hyphenation" select="$hyphenation"/>
502 <xsl:with-param name="url" select="$url"/>
505 <xsl:when test="$latex.use.tabularx=1 and count(ancestor::table)>0">
506 <xsl:apply-templates/>
507 <xsl:text> </xsl:text>
508 <xsl:call-template name="generate.typeset.url">
509 <xsl:with-param name="hyphenation" select="$hyphenation"/>
510 <xsl:with-param name="url" select="$url"/>
513 <xsl:when test="$ulink.footnotes='1' or $ulink.show='1'">
514 <xsl:apply-templates/>
515 <xsl:if test="$ulink.footnotes='1' and count(ancestor::footnote)=0">
516 <xsl:call-template name="footnote">
517 <xsl:with-param name="hyphenation" select="$hyphenation"/>
518 <xsl:with-param name="url" select="$url"/>
521 <xsl:if test="$ulink.show='1' or ($ulink.footnotes='1' and ancestor::footnote)">
522 <xsl:text> </xsl:text>
523 <xsl:call-template name="generate.typeset.url">
524 <xsl:with-param name="hyphenation" select="$hyphenation"/>
525 <xsl:with-param name="url" select="$url"/>
530 <xsl:text>\href{</xsl:text>
531 <xsl:call-template name="scape-href">
532 <xsl:with-param name="string" select="$url"/>
534 <xsl:text>}</xsl:text>
535 <xsl:text>{</xsl:text>
536 <xsl:apply-templates/>
537 <xsl:text>}</xsl:text><!-- End Of second argument of \href -->
545 <!--############################################################################# -->
546 <doc:template match="olink" xmlns="">
547 <refpurpose>OLink XSL template</refpurpose>
552 <!--############################################################################# -->
554 <xsl:template match="olink">
555 <xsl:apply-templates/>
564 <!--############################################################################# -->
565 <xsl:template name="title.xref">
566 <xsl:param name="target" select="."/>
568 <xsl:when test="name($target) = 'figure'
569 or name($target) = 'example'
570 or name($target) = 'equation'
571 or name($target) = 'table'
572 or name($target) = 'dedication'
573 or name($target) = 'preface'
574 or name($target) = 'bibliography'
575 or name($target) = 'glossary'
576 or name($target) = 'index'
577 or name($target) = 'setindex'
578 or name($target) = 'colophon'">
579 <xsl:call-template name="gentext.startquote"/>
580 <xsl:apply-templates select="$target" mode="title.content"/>
581 <xsl:call-template name="gentext.endquote"/>
584 <xsl:text>{\em </xsl:text><xsl:apply-templates select="$target" mode="title.content"/><xsl:text>}</xsl:text>
590 <!--############################################################################# -->
591 <xsl:template match="title" mode="xref">
592 <xsl:apply-templates/>
595 <xsl:template match="command" mode="xref">
596 <xsl:call-template name="inline.boldseq"/>
599 <xsl:template match="function" mode="xref">
600 <xsl:call-template name="inline.monoseq"/>
603 <xsl:template name="generate.typeset.url">
604 <xsl:param name="hyphenation"/>
605 <xsl:param name="url" select="@url"/>
607 <xsl:when test="$latex.use.url='1'">
608 <xsl:text>\url{</xsl:text>
609 <xsl:value-of select="$url"/>
610 <xsl:text>}</xsl:text>
613 <xsl:text>\href{</xsl:text>
614 <xsl:call-template name="scape-href">
615 <xsl:with-param name="string" select="$url"/>
617 <xsl:text>}{\texttt{</xsl:text>
618 <xsl:call-template name="generate.string.url">
619 <xsl:with-param name="hyphenation" select="$hyphenation"/>
620 <xsl:with-param name="string" select="$url"/>
622 <xsl:text>}}</xsl:text>
627 <!--############################################################################# -->
628 <doc:template name="generate.string.url" xmlns="">
629 <refpurpose>Escape and hyphenate a string as a teletype URL.</refpurpose>
632 This template typsets teletype text using slash.hyphen if
633 $latex.hyphenation.tttricks is disabled.
634 Has two parameters: 'hyphenation' and 'string'.
638 <!--############################################################################# -->
639 <xsl:template name="generate.string.url">
640 <xsl:param name="hyphenation" />
641 <xsl:param name="string" />
642 <xsl:param name="url" select="$string"/>
644 <xsl:when test="$latex.hyphenation.tttricks=1">
645 <xsl:value-of select="$hyphenation" />
646 <xsl:text>{</xsl:text>
647 <xsl:call-template name="normalize-scape"><xsl:with-param name="string" select="$string"/></xsl:call-template>
648 <xsl:text>}</xsl:text>
651 <!-- LaTeX chars are scaped. Each / except the :// is mapped to a /\- -->
652 <xsl:call-template name="scape.slash.hyphen"><xsl:with-param name="string" select="$url"/></xsl:call-template>