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