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