source: clfs-embedded/BOOK/stylesheets/lfs-xsl/docbook-xsl-snapshot/fo/xref.xsl @ 9882b55

Last change on this file since 9882b55 was 9882b55, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Added the new lfs-xsl stylesheets.

  • Property mode set to 100644
File size: 50.4 KB
Line 
1<?xml version='1.0'?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                xmlns:fo="http://www.w3.org/1999/XSL/Format"
4                xmlns:exsl="http://exslt.org/common"
5                xmlns:xlink='http://www.w3.org/1999/xlink'
6                exclude-result-prefixes="exsl"
7                version='1.0'>
8
9<!-- ********************************************************************
10     $Id$
11     ********************************************************************
12
13     This file is part of the XSL DocBook Stylesheet distribution.
14     See ../README or http://docbook.sf.net/release/xsl/current/ for
15     copyright and other information.
16
17     ******************************************************************** -->
18
19<!-- Use internal variable for olink xlink role for consistency -->
20<xsl:variable 
21      name="xolink.role">http://docbook.org/xlink/role/olink</xsl:variable>
22
23<!-- ==================================================================== -->
24
25<xsl:template match="anchor">
26  <xsl:variable name="id">
27    <xsl:call-template name="object.id"/>
28  </xsl:variable>
29  <fo:inline id="{$id}"/>
30</xsl:template>
31
32<!-- ==================================================================== -->
33
34<xsl:template match="xref" name="xref">
35  <xsl:param name="xhref" select="@xlink:href"/>
36  <!-- is the @xlink:href a local idref link? -->
37  <xsl:param name="xlink.idref">
38    <xsl:if test="starts-with($xhref,'#')
39                  and (not(contains($xhref,'&#40;'))
40                  or starts-with($xhref, '#xpointer&#40;id&#40;'))">
41      <xsl:call-template name="xpointer.idref">
42        <xsl:with-param name="xpointer" select="$xhref"/>
43      </xsl:call-template>
44   </xsl:if>
45  </xsl:param>
46  <xsl:param name="xlink.targets" select="key('id',$xlink.idref)"/>
47  <xsl:param name="linkend.targets" select="key('id',@linkend)"/>
48  <xsl:param name="target" select="($xlink.targets | $linkend.targets)[1]"/>
49  <xsl:param name="refelem" select="local-name($target)"/>
50
51  <xsl:variable name="xrefstyle">
52    <xsl:choose>
53      <xsl:when test="@role and not(@xrefstyle)
54                      and $use.role.as.xrefstyle != 0">
55        <xsl:value-of select="@role"/>
56      </xsl:when>
57      <xsl:otherwise>
58        <xsl:value-of select="@xrefstyle"/>
59      </xsl:otherwise>
60    </xsl:choose>
61  </xsl:variable>
62
63  <xsl:variable name="content">
64    <fo:inline xsl:use-attribute-sets="xref.properties">
65      <xsl:choose>
66        <xsl:when test="@endterm">
67          <xsl:variable name="etargets" select="key('id',@endterm)"/>
68          <xsl:variable name="etarget" select="$etargets[1]"/>
69          <xsl:choose>
70            <xsl:when test="count($etarget) = 0">
71              <xsl:message>
72                <xsl:value-of select="count($etargets)"/>
73                <xsl:text>Endterm points to nonexistent ID: </xsl:text>
74                <xsl:value-of select="@endterm"/>
75              </xsl:message>
76              <xsl:text>???</xsl:text>
77            </xsl:when>
78            <xsl:otherwise>
79              <xsl:apply-templates select="$etarget" mode="endterm"/>
80            </xsl:otherwise>
81          </xsl:choose>
82        </xsl:when>
83 
84        <xsl:when test="$target/@xreflabel">
85          <xsl:call-template name="xref.xreflabel">
86            <xsl:with-param name="target" select="$target"/>
87          </xsl:call-template>
88        </xsl:when>
89 
90        <xsl:when test="$target">
91          <xsl:if test="not(parent::citation)">
92            <xsl:apply-templates select="$target" mode="xref-to-prefix"/>
93          </xsl:if>
94 
95          <xsl:apply-templates select="$target" mode="xref-to">
96            <xsl:with-param name="referrer" select="."/>
97            <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
98          </xsl:apply-templates>
99 
100          <xsl:if test="not(parent::citation)">
101            <xsl:apply-templates select="$target" mode="xref-to-suffix"/>
102          </xsl:if>
103        </xsl:when>
104        <xsl:otherwise>
105          <xsl:message>
106            <xsl:text>ERROR: xref linking to </xsl:text>
107            <xsl:value-of select="@linkend|@xlink:href"/>
108            <xsl:text> has no generated link text.</xsl:text>
109          </xsl:message>
110          <xsl:text>???</xsl:text>
111        </xsl:otherwise>
112      </xsl:choose>
113    </fo:inline>
114  </xsl:variable>
115
116  <!-- Convert it into an active link -->
117  <xsl:call-template name="simple.xlink">
118    <xsl:with-param name="content" select="$content"/>
119  </xsl:call-template>
120
121  <!-- Add standard page reference? -->
122  <xsl:choose>
123    <xsl:when test="not($target)">
124      <!-- page numbers only for local targets -->
125    </xsl:when>
126    <xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')
127                  and contains($xrefstyle, 'nopage')">
128      <!-- negative xrefstyle in instance turns it off -->
129    </xsl:when>
130    <!-- positive xrefstyle already handles it -->
131    <xsl:when test="not(starts-with(normalize-space($xrefstyle), 'select:')
132                  and (contains($xrefstyle, 'page')
133                       or contains($xrefstyle, 'Page')))
134                  and ( $insert.xref.page.number = 'yes'
135                     or $insert.xref.page.number = '1')
136                  or local-name($target) = 'para'">
137      <xsl:apply-templates select="$target" mode="page.citation">
138        <xsl:with-param name="id" select="$target/@id|$target/@xml:id"/>
139      </xsl:apply-templates>
140    </xsl:when>
141  </xsl:choose>
142</xsl:template>
143
144<!-- ==================================================================== -->
145
146<!-- Handled largely like an xref -->
147<!-- To be done: add support for begin, end, and units attributes -->
148<xsl:template match="biblioref" name="biblioref">
149  <xsl:variable name="targets" select="key('id',@linkend)"/>
150  <xsl:variable name="target" select="$targets[1]"/>
151  <xsl:variable name="refelem" select="local-name($target)"/>
152
153  <xsl:call-template name="check.id.unique">
154    <xsl:with-param name="linkend" select="@linkend"/>
155  </xsl:call-template>
156
157  <xsl:choose>
158    <xsl:when test="$refelem=''">
159      <xsl:message>
160        <xsl:text>XRef to nonexistent id: </xsl:text>
161        <xsl:value-of select="@linkend"/>
162      </xsl:message>
163      <xsl:text>???</xsl:text>
164    </xsl:when>
165
166    <xsl:when test="@endterm">
167      <fo:basic-link internal-destination="{@linkend}"
168                     xsl:use-attribute-sets="xref.properties">
169        <xsl:variable name="etargets" select="key('id',@endterm)"/>
170        <xsl:variable name="etarget" select="$etargets[1]"/>
171        <xsl:choose>
172          <xsl:when test="count($etarget) = 0">
173            <xsl:message>
174              <xsl:value-of select="count($etargets)"/>
175              <xsl:text>Endterm points to nonexistent ID: </xsl:text>
176              <xsl:value-of select="@endterm"/>
177            </xsl:message>
178            <xsl:text>???</xsl:text>
179          </xsl:when>
180          <xsl:otherwise>
181            <xsl:apply-templates select="$etarget" mode="endterm"/>
182          </xsl:otherwise>
183        </xsl:choose>
184      </fo:basic-link>
185    </xsl:when>
186
187    <xsl:when test="$target/@xreflabel">
188      <fo:basic-link internal-destination="{@linkend}"
189                     xsl:use-attribute-sets="xref.properties">
190        <xsl:call-template name="xref.xreflabel">
191          <xsl:with-param name="target" select="$target"/>
192        </xsl:call-template>
193      </fo:basic-link>
194    </xsl:when>
195
196    <xsl:otherwise>
197      <xsl:if test="not(parent::citation)">
198        <xsl:apply-templates select="$target" mode="xref-to-prefix"/>
199      </xsl:if>
200
201      <fo:basic-link internal-destination="{@linkend}"
202                     xsl:use-attribute-sets="xref.properties">
203        <xsl:apply-templates select="$target" mode="xref-to">
204          <xsl:with-param name="referrer" select="."/>
205          <xsl:with-param name="xrefstyle">
206            <xsl:choose>
207              <xsl:when test="@role and not(@xrefstyle) and $use.role.as.xrefstyle != 0">
208                <xsl:value-of select="@role"/>
209              </xsl:when>
210              <xsl:otherwise>
211                <xsl:value-of select="@xrefstyle"/>
212              </xsl:otherwise>
213            </xsl:choose>
214          </xsl:with-param>
215        </xsl:apply-templates>
216      </fo:basic-link>
217
218      <xsl:if test="not(parent::citation)">
219        <xsl:apply-templates select="$target" mode="xref-to-suffix"/>
220      </xsl:if>
221    </xsl:otherwise>
222  </xsl:choose>
223
224</xsl:template>
225
226<!-- ==================================================================== -->
227
228<xsl:template match="*" mode="endterm">
229  <!-- Process the children of the endterm element -->
230  <xsl:variable name="endterm">
231    <xsl:apply-templates select="child::node()"/>
232  </xsl:variable>
233
234  <xsl:choose>
235    <xsl:when test="function-available('exsl:node-set')">
236      <xsl:apply-templates select="exsl:node-set($endterm)" mode="remove-ids"/>
237    </xsl:when>
238    <xsl:otherwise>
239      <xsl:copy-of select="$endterm"/>
240    </xsl:otherwise>
241  </xsl:choose>
242</xsl:template>
243
244<xsl:template match="*" mode="remove-ids">
245  <xsl:copy>
246    <xsl:for-each select="@*">
247      <xsl:choose>
248        <xsl:when test="name(.) != 'id'">
249          <xsl:copy/>
250        </xsl:when>
251        <xsl:otherwise>
252          <xsl:message>removing <xsl:value-of select="name(.)"/></xsl:message>
253        </xsl:otherwise>
254      </xsl:choose>
255    </xsl:for-each>
256    <xsl:apply-templates mode="remove-ids"/>
257  </xsl:copy>
258</xsl:template>
259
260<!--- ==================================================================== -->
261
262<xsl:template match="*" mode="xref-to-prefix"/>
263<xsl:template match="*" mode="xref-to-suffix"/>
264
265<xsl:template match="*" mode="xref-to">
266  <xsl:param name="referrer"/>
267  <xsl:param name="xrefstyle"/>
268  <xsl:param name="verbose" select="1"/>
269
270
271  <xsl:if test="$verbose != 0">
272    <xsl:message>
273      <xsl:text>Don't know what gentext to create for xref to: "</xsl:text>
274      <xsl:value-of select="name(.)"/>
275      <xsl:text>"</xsl:text>
276    </xsl:message>
277    <xsl:text>???</xsl:text>
278  </xsl:if>
279</xsl:template>
280
281<xsl:template match="title" mode="xref-to">
282  <xsl:param name="referrer"/>
283  <xsl:param name="xrefstyle"/>
284  <xsl:param name="verbose" select="1"/>
285
286  <!-- if you xref to a title, xref to the parent... -->
287  <xsl:choose>
288    <!-- FIXME: how reliable is this? -->
289    <xsl:when test="contains(local-name(parent::*), 'info')">
290      <xsl:apply-templates select="parent::*[2]" mode="xref-to">
291        <xsl:with-param name="referrer" select="$referrer"/>
292        <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
293        <xsl:with-param name="verbose" select="$verbose"/>
294      </xsl:apply-templates>
295    </xsl:when>
296    <xsl:otherwise>
297      <xsl:apply-templates select="parent::*" mode="xref-to">
298        <xsl:with-param name="referrer" select="$referrer"/>
299        <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
300        <xsl:with-param name="verbose" select="$verbose"/>
301      </xsl:apply-templates>
302    </xsl:otherwise>
303  </xsl:choose>
304</xsl:template>
305
306<xsl:template match="abstract|article|authorblurb|bibliodiv|bibliomset
307                     |biblioset|blockquote|calloutlist|caution|colophon
308                     |constraintdef|formalpara|glossdiv|important|indexdiv
309                     |itemizedlist|legalnotice|lot|msg|msgexplan|msgmain
310                     |msgrel|msgset|msgsub|note|orderedlist|partintro
311                     |productionset|qandadiv|refsynopsisdiv|segmentedlist
312                     |set|setindex|sidebar|tip|toc|variablelist|warning"
313              mode="xref-to">
314  <xsl:param name="referrer"/>
315  <xsl:param name="xrefstyle"/>
316  <xsl:param name="verbose" select="1"/>
317
318  <!-- catch-all for things with (possibly optional) titles -->
319  <xsl:apply-templates select="." mode="object.xref.markup">
320    <xsl:with-param name="purpose" select="'xref'"/>
321    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
322    <xsl:with-param name="referrer" select="$referrer"/>
323    <xsl:with-param name="verbose" select="$verbose"/>
324  </xsl:apply-templates>
325</xsl:template>
326
327<xsl:template match="author|editor|othercredit|personname" mode="xref-to">
328  <xsl:param name="referrer"/>
329  <xsl:param name="xrefstyle"/>
330  <xsl:param name="verbose" select="1"/>
331
332  <xsl:call-template name="person.name"/>
333</xsl:template>
334
335<xsl:template match="authorgroup" mode="xref-to">
336  <xsl:param name="referrer"/>
337  <xsl:param name="xrefstyle"/>
338  <xsl:param name="verbose" select="1"/>
339
340  <xsl:call-template name="person.name.list"/>
341</xsl:template>
342
343<xsl:template match="figure|example|table|equation" mode="xref-to">
344  <xsl:param name="referrer"/>
345  <xsl:param name="xrefstyle"/>
346  <xsl:param name="verbose" select="1"/>
347
348  <xsl:apply-templates select="." mode="object.xref.markup">
349    <xsl:with-param name="purpose" select="'xref'"/>
350    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
351    <xsl:with-param name="referrer" select="$referrer"/>
352    <xsl:with-param name="verbose" select="$verbose"/>
353  </xsl:apply-templates>
354</xsl:template>
355
356<xsl:template match="procedure" mode="xref-to">
357  <xsl:param name="referrer"/>
358  <xsl:param name="xrefstyle"/>
359  <xsl:param name="verbose"/>
360
361  <xsl:apply-templates select="." mode="object.xref.markup">
362    <xsl:with-param name="purpose" select="'xref'"/>
363    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
364    <xsl:with-param name="referrer" select="$referrer"/>
365    <xsl:with-param name="verbose" select="$verbose"/>
366  </xsl:apply-templates>
367</xsl:template>
368
369<xsl:template match="task" mode="xref-to">
370  <xsl:param name="referrer"/>
371  <xsl:param name="xrefstyle"/>
372  <xsl:param name="verbose"/>
373
374  <xsl:apply-templates select="." mode="object.xref.markup">
375    <xsl:with-param name="purpose" select="'xref'"/>
376    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
377    <xsl:with-param name="referrer" select="$referrer"/>
378    <xsl:with-param name="verbose" select="$verbose"/>
379  </xsl:apply-templates>
380</xsl:template>
381
382<xsl:template match="cmdsynopsis" mode="xref-to">
383  <xsl:param name="referrer"/>
384  <xsl:param name="xrefstyle"/>
385  <xsl:param name="verbose" select="1"/>
386
387  <xsl:apply-templates select="(.//command)[1]" mode="xref"/>
388</xsl:template>
389
390<xsl:template match="funcsynopsis" mode="xref-to">
391  <xsl:param name="referrer"/>
392  <xsl:param name="xrefstyle"/>
393  <xsl:param name="verbose" select="1"/>
394
395  <xsl:apply-templates select="(.//function)[1]" mode="xref"/>
396</xsl:template>
397
398<xsl:template match="dedication|preface|chapter|appendix" mode="xref-to">
399  <xsl:param name="referrer"/>
400  <xsl:param name="xrefstyle"/>
401  <xsl:param name="verbose" select="1"/>
402
403  <xsl:apply-templates select="." mode="object.xref.markup">
404    <xsl:with-param name="purpose" select="'xref'"/>
405    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
406    <xsl:with-param name="referrer" select="$referrer"/>
407    <xsl:with-param name="verbose" select="$verbose"/>
408  </xsl:apply-templates>
409</xsl:template>
410
411<xsl:template match="bibliography" mode="xref-to">
412  <xsl:param name="referrer"/>
413  <xsl:param name="xrefstyle"/>
414  <xsl:param name="verbose" select="1"/>
415
416  <xsl:apply-templates select="." mode="object.xref.markup">
417    <xsl:with-param name="purpose" select="'xref'"/>
418    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
419    <xsl:with-param name="referrer" select="$referrer"/>
420    <xsl:with-param name="verbose" select="$verbose"/>
421  </xsl:apply-templates>
422</xsl:template>
423
424<xsl:template match="biblioentry|bibliomixed" mode="xref-to-prefix">
425  <xsl:text>[</xsl:text>
426</xsl:template>
427
428<xsl:template match="biblioentry|bibliomixed" mode="xref-to-suffix">
429  <xsl:text>]</xsl:text>
430</xsl:template>
431
432<xsl:template match="biblioentry|bibliomixed" mode="xref-to">
433  <xsl:param name="referrer"/>
434  <xsl:param name="xrefstyle"/>
435  <xsl:param name="verbose" select="1"/>
436
437  <!-- handles both biblioentry and bibliomixed -->
438  <xsl:choose>
439    <xsl:when test="string(.) = ''">
440      <xsl:variable name="bib" select="document($bibliography.collection,.)"/>
441      <xsl:variable name="id" select="(@id|@xml:id)[1]"/>
442      <xsl:variable name="entry" select="$bib/bibliography/
443                                         *[@id=$id or @xml:id=$id][1]"/>
444      <xsl:choose>
445        <xsl:when test="$entry">
446          <xsl:choose>
447            <xsl:when test="$bibliography.numbered != 0">
448              <xsl:number from="bibliography" count="biblioentry|bibliomixed"
449                          level="any" format="1"/>
450            </xsl:when>
451            <xsl:when test="local-name($entry/*[1]) = 'abbrev'">
452              <xsl:apply-templates select="$entry/*[1]"/>
453            </xsl:when>
454            <xsl:otherwise>
455              <xsl:value-of select="(@id|@xml:id)[1]"/>
456            </xsl:otherwise>
457          </xsl:choose>
458        </xsl:when>
459        <xsl:otherwise>
460          <xsl:message>
461            <xsl:text>No bibliography entry: </xsl:text>
462            <xsl:value-of select="$id"/>
463            <xsl:text> found in </xsl:text>
464            <xsl:value-of select="$bibliography.collection"/>
465          </xsl:message>
466          <xsl:value-of select="(@id|@xml:id)[1]"/>
467        </xsl:otherwise>
468      </xsl:choose>
469    </xsl:when>
470    <xsl:otherwise>
471      <xsl:choose>
472        <xsl:when test="$bibliography.numbered != 0">
473          <xsl:number from="bibliography" count="biblioentry|bibliomixed"
474                      level="any" format="1"/>
475        </xsl:when>
476        <xsl:when test="local-name(*[1]) = 'abbrev'">
477          <xsl:apply-templates select="*[1]"/>
478        </xsl:when>
479        <xsl:otherwise>
480          <xsl:value-of select="(@id|@xml:id)[1]"/>
481        </xsl:otherwise>
482      </xsl:choose>
483    </xsl:otherwise>
484  </xsl:choose>
485</xsl:template>
486
487<xsl:template match="glossary" mode="xref-to">
488  <xsl:param name="referrer"/>
489  <xsl:param name="xrefstyle"/>
490  <xsl:param name="verbose" select="1"/>
491
492  <xsl:apply-templates select="." mode="object.xref.markup">
493    <xsl:with-param name="purpose" select="'xref'"/>
494    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
495    <xsl:with-param name="referrer" select="$referrer"/>
496    <xsl:with-param name="verbose" select="$verbose"/>
497  </xsl:apply-templates>
498</xsl:template>
499
500<xsl:template match="glossentry" mode="xref-to">
501  <xsl:choose>
502    <xsl:when test="$glossentry.show.acronym = 'primary'">
503      <xsl:choose>
504        <xsl:when test="acronym|abbrev">
505          <xsl:apply-templates select="(acronym|abbrev)[1]"/>
506        </xsl:when>
507        <xsl:otherwise>
508          <xsl:apply-templates select="glossterm[1]" mode="xref-to"/>
509        </xsl:otherwise>
510      </xsl:choose>
511    </xsl:when>
512    <xsl:otherwise>
513      <xsl:apply-templates select="glossterm[1]" mode="xref-to"/>
514    </xsl:otherwise>
515  </xsl:choose>
516</xsl:template>
517
518<xsl:template match="glossterm" mode="xref-to">
519  <xsl:apply-templates/>
520</xsl:template>
521
522<xsl:template match="index" mode="xref-to">
523  <xsl:param name="referrer"/>
524  <xsl:param name="xrefstyle"/>
525  <xsl:param name="verbose" select="1"/>
526
527  <xsl:apply-templates select="." mode="object.xref.markup">
528    <xsl:with-param name="purpose" select="'xref'"/>
529    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
530    <xsl:with-param name="referrer" select="$referrer"/>
531    <xsl:with-param name="verbose" select="$verbose"/>
532  </xsl:apply-templates>
533</xsl:template>
534
535<xsl:template match="listitem" mode="xref-to">
536  <xsl:param name="referrer"/>
537  <xsl:param name="xrefstyle"/>
538  <xsl:param name="verbose" select="1"/>
539
540  <xsl:apply-templates select="." mode="object.xref.markup">
541    <xsl:with-param name="purpose" select="'xref'"/>
542    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
543    <xsl:with-param name="referrer" select="$referrer"/>
544    <xsl:with-param name="verbose" select="$verbose"/>
545  </xsl:apply-templates>
546</xsl:template>
547
548<xsl:template match="section|simplesect
549                     |sect1|sect2|sect3|sect4|sect5
550                     |refsect1|refsect2|refsect3|refsection" mode="xref-to">
551  <xsl:param name="referrer"/>
552  <xsl:param name="xrefstyle"/>
553  <xsl:param name="verbose" select="1"/>
554
555  <xsl:apply-templates select="." mode="object.xref.markup">
556    <xsl:with-param name="purpose" select="'xref'"/>
557    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
558    <xsl:with-param name="referrer" select="$referrer"/>
559    <xsl:with-param name="verbose" select="$verbose"/>
560  </xsl:apply-templates>
561  <!-- What about "in Chapter X"? -->
562</xsl:template>
563
564<xsl:template match="bridgehead" mode="xref-to">
565  <xsl:param name="referrer"/>
566  <xsl:param name="xrefstyle"/>
567  <xsl:param name="verbose" select="1"/>
568
569  <xsl:apply-templates select="." mode="object.xref.markup">
570    <xsl:with-param name="purpose" select="'xref'"/>
571    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
572    <xsl:with-param name="referrer" select="$referrer"/>
573    <xsl:with-param name="verbose" select="$verbose"/>
574  </xsl:apply-templates>
575  <!-- What about "in Chapter X"? -->
576</xsl:template>
577
578<xsl:template match="qandaset" mode="xref-to">
579  <xsl:param name="referrer"/>
580  <xsl:param name="xrefstyle"/>
581  <xsl:param name="verbose" select="1"/>
582
583  <xsl:apply-templates select="." mode="object.xref.markup">
584    <xsl:with-param name="purpose" select="'xref'"/>
585    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
586    <xsl:with-param name="referrer" select="$referrer"/>
587    <xsl:with-param name="verbose" select="$verbose"/>
588  </xsl:apply-templates>
589</xsl:template>
590
591<xsl:template match="qandadiv" mode="xref-to">
592  <xsl:param name="referrer"/>
593  <xsl:param name="xrefstyle"/>
594  <xsl:param name="verbose" select="1"/>
595
596  <xsl:apply-templates select="." mode="object.xref.markup">
597    <xsl:with-param name="purpose" select="'xref'"/>
598    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
599    <xsl:with-param name="referrer" select="$referrer"/>
600    <xsl:with-param name="verbose" select="$verbose"/>
601  </xsl:apply-templates>
602</xsl:template>
603
604<xsl:template match="qandaentry" mode="xref-to">
605  <xsl:param name="referrer"/>
606  <xsl:param name="xrefstyle"/>
607  <xsl:param name="verbose" select="1"/>
608
609  <xsl:apply-templates select="question[1]" mode="object.xref.markup">
610    <xsl:with-param name="purpose" select="'xref'"/>
611    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
612    <xsl:with-param name="referrer" select="$referrer"/>
613    <xsl:with-param name="verbose" select="$verbose"/>
614  </xsl:apply-templates>
615</xsl:template>
616
617<xsl:template match="question|answer" mode="xref-to">
618  <xsl:param name="referrer"/>
619  <xsl:param name="xrefstyle"/>
620  <xsl:param name="verbose" select="1"/>
621
622  <xsl:apply-templates select="." mode="object.xref.markup">
623    <xsl:with-param name="purpose" select="'xref'"/>
624    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
625    <xsl:with-param name="referrer" select="$referrer"/>
626    <xsl:with-param name="verbose" select="$verbose"/>
627  </xsl:apply-templates>
628</xsl:template>
629
630<xsl:template match="part|reference" mode="xref-to">
631  <xsl:param name="referrer"/>
632  <xsl:param name="xrefstyle"/>
633  <xsl:param name="verbose" select="1"/>
634
635  <xsl:apply-templates select="." mode="object.xref.markup">
636    <xsl:with-param name="purpose" select="'xref'"/>
637    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
638    <xsl:with-param name="referrer" select="$referrer"/>
639    <xsl:with-param name="verbose" select="$verbose"/>
640  </xsl:apply-templates>
641</xsl:template>
642
643<xsl:template match="refentry" mode="xref-to">
644  <xsl:param name="referrer"/>
645  <xsl:param name="xrefstyle"/>
646  <xsl:param name="verbose" select="1"/>
647
648  <xsl:choose>
649    <xsl:when test="refmeta/refentrytitle">
650      <xsl:apply-templates select="refmeta/refentrytitle"/>
651    </xsl:when>
652    <xsl:otherwise>
653      <xsl:apply-templates select="refnamediv/refname[1]"/>
654    </xsl:otherwise>
655  </xsl:choose>
656  <xsl:apply-templates select="refmeta/manvolnum"/>
657</xsl:template>
658
659<xsl:template match="refnamediv" mode="xref-to">
660  <xsl:param name="referrer"/>
661  <xsl:param name="xrefstyle"/>
662  <xsl:param name="verbose" select="1"/>
663
664  <xsl:apply-templates select="refname[1]" mode="xref-to">
665    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
666    <xsl:with-param name="referrer" select="$referrer"/>
667    <xsl:with-param name="verbose" select="$verbose"/>
668  </xsl:apply-templates>
669</xsl:template>
670
671<xsl:template match="refname" mode="xref-to">
672  <xsl:param name="referrer"/>
673  <xsl:param name="xrefstyle"/>
674  <xsl:param name="verbose" select="1"/>
675
676  <xsl:apply-templates mode="xref-to">
677    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
678    <xsl:with-param name="referrer" select="$referrer"/>
679    <xsl:with-param name="verbose" select="$verbose"/>
680  </xsl:apply-templates>
681</xsl:template>
682
683<xsl:template match="step" mode="xref-to">
684  <xsl:param name="referrer"/>
685  <xsl:param name="xrefstyle"/>
686  <xsl:param name="verbose" select="1"/>
687
688  <xsl:call-template name="gentext">
689    <xsl:with-param name="key" select="'Step'"/>
690  </xsl:call-template>
691  <xsl:text> </xsl:text>
692  <xsl:apply-templates select="." mode="number"/>
693</xsl:template>
694
695<xsl:template match="varlistentry" mode="xref-to">
696  <xsl:param name="referrer"/>
697  <xsl:param name="xrefstyle"/>
698  <xsl:param name="verbose" select="1"/>
699
700  <xsl:apply-templates select="term[1]" mode="xref-to">
701    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
702    <xsl:with-param name="referrer" select="$referrer"/>
703    <xsl:with-param name="verbose" select="$verbose"/>
704  </xsl:apply-templates>
705</xsl:template>
706
707<xsl:template match="varlistentry/term" mode="xref-to">
708  <xsl:param name="verbose" select="1"/>
709  <!-- to avoid the comma that will be generated if there are several terms -->
710  <xsl:apply-templates/>
711</xsl:template>
712
713<xsl:template match="co" mode="xref-to">
714  <xsl:param name="referrer"/>
715  <xsl:param name="xrefstyle"/>
716  <xsl:param name="verbose" select="1"/>
717
718  <xsl:apply-templates select="." mode="callout-bug"/>
719</xsl:template>
720
721<xsl:template match="book" mode="xref-to">
722  <xsl:param name="referrer"/>
723  <xsl:param name="xrefstyle"/>
724  <xsl:param name="verbose" select="1"/>
725
726  <xsl:apply-templates select="." mode="object.xref.markup">
727    <xsl:with-param name="purpose" select="'xref'"/>
728    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
729    <xsl:with-param name="referrer" select="$referrer"/>
730    <xsl:with-param name="verbose" select="$verbose"/>
731  </xsl:apply-templates>
732</xsl:template>
733
734<xsl:template match="para" mode="xref-to">
735  <xsl:param name="referrer"/>
736  <xsl:param name="xrefstyle"/>
737  <xsl:param name="verbose"/>
738
739  <xsl:variable name="context" select="(ancestor::simplesect
740                                       |ancestor::section
741                                       |ancestor::sect1
742                                       |ancestor::sect2
743                                       |ancestor::sect3
744                                       |ancestor::sect4
745                                       |ancestor::sect5
746                                       |ancestor::refsection
747                                       |ancestor::refsect1
748                                       |ancestor::refsect2
749                                       |ancestor::refsect3
750                                       |ancestor::chapter
751                                       |ancestor::appendix
752                                       |ancestor::preface
753                                       |ancestor::partintro
754                                       |ancestor::dedication
755                                       |ancestor::colophon
756                                       |ancestor::bibliography
757                                       |ancestor::index
758                                       |ancestor::glossary
759                                       |ancestor::glossentry
760                                       |ancestor::listitem
761                                       |ancestor::varlistentry)[last()]"/>
762
763  <xsl:apply-templates select="$context" mode="xref-to">
764    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
765    <xsl:with-param name="referrer" select="$referrer"/>
766    <xsl:with-param name="verbose" select="$verbose"/>
767  </xsl:apply-templates>
768</xsl:template>
769
770<!-- ==================================================================== -->
771
772<xsl:template match="link" name="link">
773  <xsl:param name="linkend" select="@linkend"/>
774  <xsl:param name="targets" select="key('id',$linkend)"/>
775  <xsl:param name="target" select="$targets[1]"/>
776
777  <xsl:variable name="xrefstyle">
778    <xsl:choose>
779      <xsl:when test="@role and not(@xrefstyle)
780                      and $use.role.as.xrefstyle != 0">
781        <xsl:value-of select="@role"/>
782      </xsl:when>
783      <xsl:otherwise>
784        <xsl:value-of select="@xrefstyle"/>
785      </xsl:otherwise>
786    </xsl:choose>
787  </xsl:variable>
788
789  <xsl:variable name="content">
790    <fo:inline xsl:use-attribute-sets="xref.properties">
791      <xsl:choose>
792        <xsl:when test="count(child::node()) &gt; 0">
793          <!-- If it has content, use it -->
794          <xsl:apply-templates/>
795        </xsl:when>
796        <!-- look for an endterm -->
797        <xsl:when test="@endterm">
798          <xsl:variable name="etargets" select="key('id',@endterm)"/>
799          <xsl:variable name="etarget" select="$etargets[1]"/>
800          <xsl:choose>
801            <xsl:when test="count($etarget) = 0">
802              <xsl:message>
803                <xsl:value-of select="count($etargets)"/>
804                <xsl:text>Endterm points to nonexistent ID: </xsl:text>
805                <xsl:value-of select="@endterm"/>
806              </xsl:message>
807              <xsl:text>???</xsl:text>
808            </xsl:when>
809            <xsl:otherwise>
810                <xsl:apply-templates select="$etarget" mode="endterm"/>
811            </xsl:otherwise>
812          </xsl:choose>
813        </xsl:when>
814        <!-- Use the xlink:href if no other text -->
815        <xsl:when test="@xlink:href">
816          <xsl:value-of select="@xlink:href"/>
817        </xsl:when>
818        <xsl:otherwise>
819          <xsl:message>
820            <xsl:text>Link element has no content and no Endterm. </xsl:text>
821            <xsl:text>Nothing to show in the link to </xsl:text>
822            <xsl:value-of select="$target"/>
823          </xsl:message>
824          <xsl:text>???</xsl:text>
825        </xsl:otherwise>
826      </xsl:choose>
827    </fo:inline>
828  </xsl:variable>
829
830  <xsl:call-template name="simple.xlink">
831    <xsl:with-param name="node" select="."/>
832    <xsl:with-param name="linkend" select="$linkend"/>
833    <xsl:with-param name="content" select="$content"/>
834  </xsl:call-template>
835
836  <!-- Add standard page reference? -->
837  <xsl:choose>
838    <!-- page numbering on link only enabled for @linkend -->
839    <!-- There is no link element in DB5 with xlink:href -->
840    <xsl:when test="not($linkend)">
841    </xsl:when>
842    <!-- negative xrefstyle in instance turns it off -->
843    <xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')
844                  and contains($xrefstyle, 'nopage')">
845    </xsl:when>
846    <xsl:when test="(starts-with(normalize-space($xrefstyle), 'select:')
847                  and $insert.link.page.number = 'maybe' 
848                  and (contains($xrefstyle, 'page')
849                       or contains($xrefstyle, 'Page')))
850                  or ( $insert.link.page.number = 'yes'
851                     or $insert.link.page.number = '1')
852                  or local-name($target) = 'para'">
853      <xsl:apply-templates select="$target" mode="page.citation">
854        <xsl:with-param name="id" select="$linkend"/>
855      </xsl:apply-templates>
856    </xsl:when>
857  </xsl:choose>
858</xsl:template>
859
860<xsl:template match="ulink" name="ulink">
861  <xsl:param name="url" select="@url"/>
862
863  <xsl:variable name ="ulink.url">
864    <xsl:call-template name="fo-external-image">
865      <xsl:with-param name="filename" select="$url"/>
866    </xsl:call-template>
867  </xsl:variable>
868
869  <fo:basic-link xsl:use-attribute-sets="xref.properties"
870                 external-destination="{$ulink.url}">
871    <xsl:choose>
872      <xsl:when test="count(child::node())=0">
873        <xsl:call-template name="hyphenate-url">
874          <xsl:with-param name="url" select="$url"/>
875        </xsl:call-template>
876      </xsl:when>
877      <xsl:otherwise>
878        <xsl:apply-templates/>
879      </xsl:otherwise>
880    </xsl:choose>
881  </fo:basic-link>
882
883  <xsl:if test="count(child::node()) != 0
884                and string(.) != $url
885                and $ulink.show != 0">
886    <!-- yes, show the URI -->
887    <xsl:choose>
888      <xsl:when test="$ulink.footnotes != 0 and not(ancestor::footnote)">
889        <fo:footnote>
890          <xsl:call-template name="ulink.footnote.number"/>
891          <fo:footnote-body xsl:use-attribute-sets="footnote.properties">
892            <fo:block>
893              <xsl:call-template name="ulink.footnote.number"/>
894              <xsl:text> </xsl:text>
895              <fo:basic-link external-destination="{$ulink.url}">
896                <xsl:value-of select="$url"/>
897              </fo:basic-link>
898            </fo:block>
899          </fo:footnote-body>
900        </fo:footnote>
901      </xsl:when>
902      <xsl:otherwise>
903        <fo:inline hyphenate="false">
904          <xsl:text> [</xsl:text>
905          <fo:basic-link external-destination="{$ulink.url}">
906            <xsl:call-template name="hyphenate-url">
907              <xsl:with-param name="url" select="$url"/>
908            </xsl:call-template>
909          </fo:basic-link>
910          <xsl:text>]</xsl:text>
911        </fo:inline>
912      </xsl:otherwise>
913    </xsl:choose>
914  </xsl:if>
915
916</xsl:template>
917
918<xsl:template name="ulink.footnote.number">
919  <fo:inline xsl:use-attribute-sets="footnote.mark.properties">
920    <xsl:choose>
921      <xsl:when test="$fop.extensions != 0">
922        <xsl:attribute name="vertical-align">super</xsl:attribute>
923      </xsl:when>
924      <xsl:otherwise>
925        <xsl:attribute name="baseline-shift">super</xsl:attribute>
926      </xsl:otherwise>
927    </xsl:choose>
928    <xsl:variable name="fnum">
929      <!-- FIXME: list in @from is probably not complete -->
930      <xsl:number level="any" 
931                  from="chapter|appendix|preface|article|refentry|bibliography[not(parent::article)]" 
932                  count="footnote[not(@label)][not(ancestor::tgroup)]|ulink[node()][@url != .][not(ancestor::footnote)]" 
933                  format="1"/>
934    </xsl:variable>
935    <xsl:choose>
936      <xsl:when test="string-length($footnote.number.symbols) &gt;= $fnum">
937        <xsl:value-of select="substring($footnote.number.symbols, $fnum, 1)"/>
938      </xsl:when>
939      <xsl:otherwise>
940        <xsl:number value="$fnum" format="{$footnote.number.format}"/>
941      </xsl:otherwise>
942    </xsl:choose>
943  </fo:inline>
944</xsl:template>
945
946<xsl:template name="hyphenate-url">
947  <xsl:param name="url" select="''"/>
948  <xsl:choose>
949    <xsl:when test="$ulink.hyphenate = ''">
950      <xsl:value-of select="$url"/>
951    </xsl:when>
952    <xsl:when test="string-length($url) &gt; 1">
953      <xsl:variable name="char" select="substring($url, 1, 1)"/>
954      <xsl:value-of select="$char"/>
955      <xsl:if test="contains($ulink.hyphenate.chars, $char)">
956        <!-- Do not hyphen in-between // -->
957        <xsl:if test="not($char = '/' and substring($url,2,1) = '/')">
958          <xsl:copy-of select="$ulink.hyphenate"/>
959        </xsl:if>
960      </xsl:if>
961      <!-- recurse to the next character -->
962      <xsl:call-template name="hyphenate-url">
963        <xsl:with-param name="url" select="substring($url, 2)"/>
964      </xsl:call-template>
965    </xsl:when>
966    <xsl:otherwise>
967      <xsl:value-of select="$url"/>
968    </xsl:otherwise>
969  </xsl:choose>
970</xsl:template>
971
972<xsl:template match="olink" name="olink">
973  <!-- olink content may be passed in from xlink olink -->
974  <xsl:param name="content" select="NOTANELEMENT"/>
975
976  <xsl:call-template name="anchor"/>
977
978  <xsl:variable name="localinfo" select="@localinfo"/>
979
980  <xsl:choose>
981    <!-- olinks resolved by stylesheet and target database -->
982    <xsl:when test="@targetdoc or @targetptr or
983                    (@xlink:role=$xolink.role and
984                     contains(@xlink:href, '#') )" >
985
986      <xsl:variable name="targetdoc.att">
987        <xsl:choose>
988          <xsl:when test="@targetdoc != ''">
989            <xsl:value-of select="@targetdoc"/>
990          </xsl:when>
991          <xsl:when test="@xlink:role=$xolink.role and
992                       contains(@xlink:href, '#')" >
993            <xsl:value-of select="substring-before(@xlink:href, '#')"/>
994          </xsl:when>
995        </xsl:choose>
996      </xsl:variable>
997
998      <xsl:variable name="targetptr.att">
999        <xsl:choose>
1000          <xsl:when test="@targetptr != ''">
1001            <xsl:value-of select="@targetptr"/>
1002          </xsl:when>
1003          <xsl:when test="@xlink:role=$xolink.role and
1004                       contains(@xlink:href, '#')" >
1005            <xsl:value-of select="substring-after(@xlink:href, '#')"/>
1006          </xsl:when>
1007        </xsl:choose>
1008      </xsl:variable>
1009
1010      <xsl:variable name="olink.lang">
1011        <xsl:call-template name="l10n.language">
1012          <xsl:with-param name="xref-context" select="true()"/>
1013        </xsl:call-template>
1014      </xsl:variable>
1015   
1016      <xsl:variable name="target.database.filename">
1017        <xsl:call-template name="select.target.database">
1018          <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
1019          <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
1020          <xsl:with-param name="olink.lang" select="$olink.lang"/>
1021        </xsl:call-template>
1022      </xsl:variable>
1023   
1024      <xsl:variable name="target.database" 
1025          select="document($target.database.filename, /)"/>
1026   
1027      <xsl:if test="$olink.debug != 0">
1028        <xsl:message>
1029          <xsl:text>Olink debug: root element of target.database is '</xsl:text>
1030          <xsl:value-of select="local-name($target.database/*[1])"/>
1031          <xsl:text>'.</xsl:text>
1032        </xsl:message>
1033      </xsl:if>
1034   
1035      <xsl:variable name="olink.key">
1036        <xsl:call-template name="select.olink.key">
1037          <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
1038          <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
1039          <xsl:with-param name="olink.lang" select="$olink.lang"/>
1040          <xsl:with-param name="target.database" select="$target.database"/>
1041        </xsl:call-template>
1042      </xsl:variable>
1043   
1044      <xsl:if test="string-length($olink.key) = 0">
1045        <xsl:message>
1046          <xsl:text>Error: unresolved olink: </xsl:text>
1047          <xsl:text>targetdoc/targetptr = '</xsl:text>
1048          <xsl:value-of select="$targetdoc.att"/>
1049          <xsl:text>/</xsl:text>
1050          <xsl:value-of select="$targetptr.att"/>
1051          <xsl:text>'.</xsl:text>
1052        </xsl:message>
1053      </xsl:if>
1054
1055      <xsl:variable name="href">
1056        <xsl:call-template name="make.olink.href">
1057          <xsl:with-param name="olink.key" select="$olink.key"/>
1058          <xsl:with-param name="target.database" select="$target.database"/>
1059        </xsl:call-template>
1060      </xsl:variable>
1061
1062      <!-- Olink that points to internal id can be a link -->
1063      <xsl:variable name="linkend">
1064        <xsl:call-template name="olink.as.linkend">
1065          <xsl:with-param name="olink.key" select="$olink.key"/>
1066          <xsl:with-param name="olink.lang" select="$olink.lang"/>
1067          <xsl:with-param name="target.database" select="$target.database"/>
1068        </xsl:call-template>
1069      </xsl:variable>
1070
1071      <xsl:variable name="hottext">
1072        <xsl:choose>
1073          <xsl:when test="$content">
1074            <xsl:copy-of select="$content"/>
1075          </xsl:when>
1076          <xsl:otherwise>
1077            <xsl:call-template name="olink.hottext">
1078              <xsl:with-param name="olink.key" select="$olink.key"/>
1079              <xsl:with-param name="olink.lang" select="$olink.lang"/>
1080              <xsl:with-param name="target.database" select="$target.database"/>
1081            </xsl:call-template>
1082          </xsl:otherwise>
1083        </xsl:choose>
1084      </xsl:variable>
1085
1086      <xsl:variable name="olink.docname.citation">
1087        <xsl:call-template name="olink.document.citation">
1088          <xsl:with-param name="olink.key" select="$olink.key"/>
1089          <xsl:with-param name="target.database" select="$target.database"/>
1090          <xsl:with-param name="olink.lang" select="$olink.lang"/>
1091        </xsl:call-template>
1092      </xsl:variable>
1093
1094      <xsl:variable name="olink.page.citation">
1095        <xsl:call-template name="olink.page.citation">
1096          <xsl:with-param name="olink.key" select="$olink.key"/>
1097          <xsl:with-param name="target.database" select="$target.database"/>
1098          <xsl:with-param name="olink.lang" select="$olink.lang"/>
1099          <xsl:with-param name="linkend" select="$linkend"/>
1100        </xsl:call-template>
1101      </xsl:variable>
1102
1103      <xsl:choose>
1104        <xsl:when test="$linkend != ''">
1105          <fo:basic-link internal-destination="{$linkend}"
1106                       xsl:use-attribute-sets="xref.properties">
1107            <xsl:copy-of select="$hottext"/>
1108            <xsl:copy-of select="$olink.page.citation"/>
1109          </fo:basic-link>
1110        </xsl:when>
1111        <xsl:when test="$href != ''">
1112          <xsl:choose>
1113            <xsl:when test="$xep.extensions != 0">
1114              <fo:basic-link external-destination="url({$href})"
1115                             xsl:use-attribute-sets="olink.properties">
1116                <xsl:copy-of select="$hottext"/>
1117              </fo:basic-link>
1118              <xsl:copy-of select="$olink.page.citation"/>
1119              <xsl:copy-of select="$olink.docname.citation"/>
1120            </xsl:when>
1121            <xsl:when test="$axf.extensions != 0">
1122              <fo:basic-link external-destination="{$href}"
1123                             xsl:use-attribute-sets="olink.properties">
1124                <xsl:copy-of select="$hottext"/>
1125              </fo:basic-link>
1126              <xsl:copy-of select="$olink.page.citation"/>
1127              <xsl:copy-of select="$olink.docname.citation"/>
1128            </xsl:when>
1129            <xsl:otherwise>
1130              <fo:basic-link external-destination="{$href}"
1131                             xsl:use-attribute-sets="olink.properties">
1132                <xsl:copy-of select="$hottext"/>
1133              </fo:basic-link>
1134              <xsl:copy-of select="$olink.page.citation"/>
1135              <xsl:copy-of select="$olink.docname.citation"/>
1136            </xsl:otherwise>
1137          </xsl:choose>
1138        </xsl:when>
1139        <xsl:otherwise>
1140          <xsl:copy-of select="$hottext"/>
1141          <xsl:copy-of select="$olink.page.citation"/>
1142          <xsl:copy-of select="$olink.docname.citation"/>
1143        </xsl:otherwise>
1144      </xsl:choose>
1145    </xsl:when>
1146
1147    <!-- olink never implemented in FO for old olink entity syntax -->
1148    <xsl:otherwise>
1149      <xsl:apply-templates/>
1150    </xsl:otherwise>
1151  </xsl:choose>
1152</xsl:template>
1153
1154<xsl:template match="*" mode="insert.olink.docname.markup">
1155  <xsl:param name="docname" select="''"/>
1156 
1157  <fo:inline font-style="italic">
1158    <xsl:value-of select="$docname"/>
1159  </fo:inline>
1160
1161</xsl:template>
1162
1163<!-- This prevents error message when processing olinks with xrefstyle -->
1164<xsl:template match="olink" mode="object.xref.template"/>
1165
1166
1167<xsl:template name="olink.as.linkend">
1168  <xsl:param name="olink.key" select="''"/>
1169  <xsl:param name="olink.lang" select="''"/>
1170  <xsl:param name="target.database" select="NotANode"/>
1171
1172  <xsl:variable name="targetdoc">
1173    <xsl:value-of select="substring-before($olink.key, '/')"/>
1174  </xsl:variable>
1175
1176  <xsl:variable name="targetptr">
1177    <xsl:value-of 
1178       select="substring-before(substring-after($olink.key, '/'), '/')"/>
1179  </xsl:variable>
1180
1181  <xsl:variable name="target.lang">
1182    <xsl:variable name="candidate">
1183      <xsl:for-each select="$target.database" >
1184        <xsl:value-of 
1185                  select="key('targetptr-key', $olink.key)/@lang" />
1186      </xsl:for-each>
1187    </xsl:variable>
1188    <xsl:choose>
1189      <xsl:when test="$candidate != ''">
1190        <xsl:value-of select="$candidate"/>
1191      </xsl:when>
1192      <xsl:otherwise>
1193        <xsl:value-of select="$olink.lang"/>
1194      </xsl:otherwise>
1195    </xsl:choose>
1196  </xsl:variable>
1197
1198  <xsl:if test="$current.docid = $targetdoc and
1199                $olink.lang = $target.lang">
1200    <xsl:variable name="targets" select="key('id',$targetptr)"/>
1201    <xsl:variable name="target" select="$targets[1]"/>
1202    <xsl:if test="$target">
1203      <xsl:value-of select="$targetptr"/>
1204    </xsl:if>
1205  </xsl:if>
1206
1207</xsl:template>
1208
1209
1210<xsl:template name="olink.outline">
1211  <xsl:param name="outline.base.uri"/>
1212  <xsl:param name="localinfo"/>
1213  <xsl:param name="return" select="href"/>
1214
1215  <xsl:message terminate="yes">Fatal error: olink.outline template: what is this supposed to do?</xsl:message>
1216</xsl:template>
1217
1218<!-- ==================================================================== -->
1219
1220<xsl:template name="title.xref">
1221  <xsl:param name="target" select="."/>
1222  <xsl:choose>
1223    <xsl:when test="local-name($target) = 'figure'
1224                    or local-name($target) = 'example'
1225                    or local-name($target) = 'equation'
1226                    or local-name($target) = 'table'
1227                    or local-name($target) = 'dedication'
1228                    or local-name($target) = 'preface'
1229                    or local-name($target) = 'bibliography'
1230                    or local-name($target) = 'glossary'
1231                    or local-name($target) = 'index'
1232                    or local-name($target) = 'setindex'
1233                    or local-name($target) = 'colophon'">
1234      <xsl:call-template name="gentext.startquote"/>
1235      <xsl:apply-templates select="$target" mode="title.markup"/>
1236      <xsl:call-template name="gentext.endquote"/>
1237    </xsl:when>
1238    <xsl:otherwise>
1239      <fo:inline font-style="italic">
1240        <xsl:apply-templates select="$target" mode="title.markup"/>
1241      </fo:inline>
1242    </xsl:otherwise>
1243  </xsl:choose>
1244</xsl:template>
1245
1246<xsl:template name="number.xref">
1247  <xsl:param name="target" select="."/>
1248  <xsl:apply-templates select="$target" mode="label.markup"/>
1249</xsl:template>
1250
1251<!-- ==================================================================== -->
1252
1253<xsl:template name="xref.xreflabel">
1254  <!-- called to process an xreflabel...you might use this to make  -->
1255  <!-- xreflabels come out in the right font for different targets, -->
1256  <!-- for example. -->
1257  <xsl:param name="target" select="."/>
1258  <xsl:value-of select="$target/@xreflabel"/>
1259</xsl:template>
1260
1261<!-- ==================================================================== -->
1262
1263<xsl:template match="title" mode="xref">
1264  <xsl:apply-templates/>
1265</xsl:template>
1266
1267<xsl:template match="command" mode="xref">
1268  <xsl:call-template name="inline.boldseq"/>
1269</xsl:template>
1270
1271<xsl:template match="function" mode="xref">
1272  <xsl:call-template name="inline.monoseq"/>
1273</xsl:template>
1274
1275<xsl:template match="*" mode="page.citation">
1276  <xsl:param name="id" select="'???'"/>
1277
1278  <fo:basic-link internal-destination="{$id}"
1279                 xsl:use-attribute-sets="xref.properties">
1280    <fo:inline keep-together.within-line="always">
1281      <xsl:call-template name="substitute-markup">
1282        <xsl:with-param name="template">
1283          <xsl:call-template name="gentext.template">
1284            <xsl:with-param name="name" select="'page.citation'"/>
1285            <xsl:with-param name="context" select="'xref'"/>
1286          </xsl:call-template>
1287        </xsl:with-param>
1288      </xsl:call-template>
1289    </fo:inline>
1290  </fo:basic-link>
1291</xsl:template>
1292
1293<xsl:template match="*" mode="pagenumber.markup">
1294  <xsl:variable name="id">
1295    <xsl:call-template name="object.id"/>
1296  </xsl:variable>
1297  <fo:page-number-citation ref-id="{$id}"/>
1298</xsl:template>
1299
1300<!-- ==================================================================== -->
1301
1302<xsl:template match="*" mode="insert.title.markup">
1303  <xsl:param name="purpose"/>
1304  <xsl:param name="xrefstyle"/>
1305  <xsl:param name="title"/>
1306
1307  <xsl:choose>
1308    <!-- FIXME: what about the case where titleabbrev is inside the info? -->
1309    <xsl:when test="$purpose = 'xref' and titleabbrev">
1310      <xsl:apply-templates select="." mode="titleabbrev.markup"/>
1311    </xsl:when>
1312    <xsl:otherwise>
1313      <xsl:copy-of select="$title"/>
1314    </xsl:otherwise>
1315  </xsl:choose>
1316</xsl:template>
1317
1318<xsl:template match="chapter|appendix" mode="insert.title.markup">
1319  <xsl:param name="purpose"/>
1320  <xsl:param name="xrefstyle"/>
1321  <xsl:param name="title"/>
1322
1323  <xsl:choose>
1324    <xsl:when test="$purpose = 'xref'">
1325      <fo:inline font-style="italic">
1326        <xsl:copy-of select="$title"/>
1327      </fo:inline>
1328    </xsl:when>
1329    <xsl:otherwise>
1330      <xsl:copy-of select="$title"/>
1331    </xsl:otherwise>
1332  </xsl:choose>
1333</xsl:template>
1334
1335<xsl:template match="*" mode="insert.subtitle.markup">
1336  <xsl:param name="purpose"/>
1337  <xsl:param name="xrefstyle"/>
1338  <xsl:param name="subtitle"/>
1339
1340  <xsl:copy-of select="$subtitle"/>
1341</xsl:template>
1342
1343<xsl:template match="*" mode="insert.label.markup">
1344  <xsl:param name="purpose"/>
1345  <xsl:param name="xrefstyle"/>
1346  <xsl:param name="label"/>
1347
1348  <xsl:copy-of select="$label"/>
1349</xsl:template>
1350
1351<xsl:template match="*" mode="insert.pagenumber.markup">
1352  <xsl:param name="purpose"/>
1353  <xsl:param name="xrefstyle"/>
1354  <xsl:param name="pagenumber"/>
1355
1356  <xsl:copy-of select="$pagenumber"/>
1357</xsl:template>
1358
1359<xsl:template match="*" mode="insert.direction.markup">
1360  <xsl:param name="purpose"/>
1361  <xsl:param name="xrefstyle"/>
1362  <xsl:param name="direction"/>
1363
1364  <xsl:copy-of select="$direction"/>
1365</xsl:template>
1366
1367<xsl:template match="olink" mode="pagenumber.markup">
1368  <!-- Local olinks can use page-citation -->
1369  <xsl:variable name="targetdoc.att" select="@targetdoc"/>
1370  <xsl:variable name="targetptr.att" select="@targetptr"/>
1371
1372  <xsl:variable name="olink.lang">
1373    <xsl:call-template name="l10n.language">
1374      <xsl:with-param name="xref-context" select="true()"/>
1375    </xsl:call-template>
1376  </xsl:variable>
1377
1378  <xsl:variable name="target.database.filename">
1379    <xsl:call-template name="select.target.database">
1380      <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
1381      <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
1382      <xsl:with-param name="olink.lang" select="$olink.lang"/>
1383    </xsl:call-template>
1384  </xsl:variable>
1385
1386  <xsl:variable name="target.database" 
1387      select="document($target.database.filename, /)"/>
1388
1389  <xsl:if test="$olink.debug != 0">
1390    <xsl:message>
1391      <xsl:text>Olink debug: root element of target.database is '</xsl:text>
1392      <xsl:value-of select="local-name($target.database/*[1])"/>
1393      <xsl:text>'.</xsl:text>
1394    </xsl:message>
1395  </xsl:if>
1396
1397  <xsl:variable name="olink.key">
1398    <xsl:call-template name="select.olink.key">
1399      <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
1400      <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
1401      <xsl:with-param name="olink.lang" select="$olink.lang"/>
1402      <xsl:with-param name="target.database" select="$target.database"/>
1403    </xsl:call-template>
1404  </xsl:variable>
1405
1406  <!-- Olink that points to internal id can be a link -->
1407  <xsl:variable name="linkend">
1408    <xsl:call-template name="olink.as.linkend">
1409      <xsl:with-param name="olink.key" select="$olink.key"/>
1410      <xsl:with-param name="olink.lang" select="$olink.lang"/>
1411      <xsl:with-param name="target.database" select="$target.database"/>
1412    </xsl:call-template>
1413  </xsl:variable>
1414
1415  <xsl:choose>
1416    <xsl:when test="$linkend != ''">
1417      <fo:page-number-citation ref-id="{$linkend}"/>
1418    </xsl:when>
1419    <xsl:otherwise>
1420      <xsl:message>
1421        <xsl:text>Olink error: no page number linkend for local olink '</xsl:text>
1422        <xsl:value-of select="$olink.key"/>
1423        <xsl:text>'</xsl:text>
1424      </xsl:message>
1425    </xsl:otherwise>
1426  </xsl:choose>
1427</xsl:template>
1428
1429</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.