]> git.stg.codes - stg.git/blob - doc/xslt/fo/xref.xsl
Set output encoding to utf-8.
[stg.git] / doc / xslt / 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 8913 2010-10-01 04:44:57Z bobstayton $
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:if test="$verbose != 0">
795         <xsl:message>
796           <xsl:text>WARNING: xref to &lt;</xsl:text>
797           <xsl:value-of select="local-name()"/>
798           <xsl:text> id="</xsl:text>
799           <xsl:value-of select="@id|@xml:id"/>
800           <xsl:text>"&gt; has no generated text. Trying its ancestor elements.</xsl:text>
801         </xsl:message>
802       </xsl:if>
803       <xsl:apply-templates select="$context" mode="xref-to">
804         <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
805         <xsl:with-param name="referrer" select="$referrer"/>
806         <xsl:with-param name="verbose" select="$verbose"/>
807       </xsl:apply-templates>
808     </xsl:otherwise>
809   </xsl:choose>
810 </xsl:template>
811
812 <xsl:template match="indexterm" mode="xref-to">
813   <xsl:value-of select="primary"/>
814 </xsl:template>
815
816 <xsl:template match="primary|secondary|tertiary" mode="xref-to">
817   <xsl:value-of select="."/>
818 </xsl:template>
819
820 <!-- ==================================================================== -->
821
822 <xsl:template match="link" name="link">
823   <xsl:param name="linkend" select="@linkend"/>
824   <xsl:param name="targets" select="key('id',$linkend)"/>
825   <xsl:param name="target" select="$targets[1]"/>
826
827   <xsl:variable name="xrefstyle">
828     <xsl:choose>
829       <xsl:when test="@role and not(@xrefstyle) 
830                       and $use.role.as.xrefstyle != 0">
831         <xsl:value-of select="@role"/>
832       </xsl:when>
833       <xsl:otherwise>
834         <xsl:value-of select="@xrefstyle"/>
835       </xsl:otherwise>
836     </xsl:choose>
837   </xsl:variable>
838
839   <xsl:variable name="content">
840     <fo:inline xsl:use-attribute-sets="xref.properties">
841       <xsl:choose>
842         <xsl:when test="count(child::node()) &gt; 0">
843           <!-- If it has content, use it -->
844           <xsl:apply-templates/>
845         </xsl:when>
846         <!-- look for an endterm -->
847         <xsl:when test="@endterm">
848           <xsl:variable name="etargets" select="key('id',@endterm)"/>
849           <xsl:variable name="etarget" select="$etargets[1]"/>
850           <xsl:choose>
851             <xsl:when test="count($etarget) = 0">
852               <xsl:message>
853                 <xsl:value-of select="count($etargets)"/>
854                 <xsl:text>Endterm points to nonexistent ID: </xsl:text>
855                 <xsl:value-of select="@endterm"/>
856               </xsl:message>
857               <xsl:text>???</xsl:text>
858             </xsl:when>
859             <xsl:otherwise>
860                 <xsl:apply-templates select="$etarget" mode="endterm"/>
861             </xsl:otherwise>
862           </xsl:choose>
863         </xsl:when>
864         <!-- Use the xlink:href if no other text -->
865         <xsl:when test="@xlink:href">
866           <xsl:call-template name="hyphenate-url">
867             <xsl:with-param name="url" select="@xlink:href"/>
868           </xsl:call-template>
869         </xsl:when>
870         <xsl:otherwise>
871           <xsl:message>
872             <xsl:text>Link element has no content and no Endterm. </xsl:text>
873             <xsl:text>Nothing to show in the link to </xsl:text>
874             <xsl:value-of select="$target"/>
875           </xsl:message>
876           <xsl:text>???</xsl:text>
877         </xsl:otherwise>
878       </xsl:choose>
879     </fo:inline>
880   </xsl:variable>
881
882   <xsl:call-template name="simple.xlink">
883     <xsl:with-param name="node" select="."/>
884     <xsl:with-param name="linkend" select="$linkend"/>
885     <xsl:with-param name="content" select="$content"/>
886   </xsl:call-template>
887
888   <!-- Add standard page reference? -->
889   <xsl:choose>
890     <!-- page numbering on link only enabled for @linkend -->
891     <!-- There is no link element in DB5 with xlink:href -->
892     <xsl:when test="not($linkend)">
893     </xsl:when>
894     <!-- negative xrefstyle in instance turns it off -->
895     <xsl:when test="starts-with(normalize-space($xrefstyle), 'select:') 
896                   and contains($xrefstyle, 'nopage')">
897     </xsl:when>
898     <xsl:when test="(starts-with(normalize-space($xrefstyle), 'select:') 
899                   and $insert.link.page.number = 'maybe'  
900                   and (contains($xrefstyle, 'page')
901                        or contains($xrefstyle, 'Page')))
902                   or ( $insert.link.page.number = 'yes' 
903                      or $insert.link.page.number = '1')
904                   or local-name($target) = 'para'">
905       <xsl:apply-templates select="$target" mode="page.citation">
906         <xsl:with-param name="id" select="$linkend"/>
907       </xsl:apply-templates>
908     </xsl:when>
909   </xsl:choose>
910 </xsl:template>
911
912 <xsl:template match="ulink" name="ulink">
913   <xsl:param name="url" select="@url"/>
914
915   <xsl:variable name ="ulink.url">
916     <xsl:call-template name="fo-external-image">
917       <xsl:with-param name="filename" select="$url"/>
918     </xsl:call-template>
919   </xsl:variable>
920
921   <fo:basic-link xsl:use-attribute-sets="xref.properties"
922                  external-destination="{$ulink.url}">
923     <xsl:choose>
924       <xsl:when test="count(child::node())=0 or (string(.) = $url)">
925         <xsl:call-template name="hyphenate-url">
926           <xsl:with-param name="url" select="$url"/>
927         </xsl:call-template>
928       </xsl:when>
929       <xsl:otherwise>
930         <xsl:apply-templates/>
931       </xsl:otherwise>
932     </xsl:choose>
933   </fo:basic-link>
934   <!-- * Call the template for determining whether the URL for this -->
935   <!-- * hyperlink is displayed, and how to display it (either inline or -->
936   <!-- * as a numbered footnote). -->
937   <xsl:call-template name="hyperlink.url.display">
938     <xsl:with-param name="url" select="$url"/>
939     <xsl:with-param name="ulink.url" select="$ulink.url"/>
940   </xsl:call-template>
941 </xsl:template>
942
943 <xsl:template name="hyperlink.url.display">
944   <!-- * This template is called for all external hyperlinks (ulinks and -->
945   <!-- * for all simple xlinks); it determines whether the URL for the -->
946   <!-- * hyperlink is displayed, and how to display it (either inline or -->
947   <!-- * as a numbered footnote). -->
948   <xsl:param name="url"/>
949   <xsl:param name="ulink.url">
950     <!-- * ulink.url is just the value of the URL wrapped in 'url(...)' -->
951     <xsl:call-template name="fo-external-image">
952       <xsl:with-param name="filename" select="$url"/>
953     </xsl:call-template>
954   </xsl:param>
955
956   <xsl:if test="count(child::node()) != 0
957                 and string(.) != $url
958                 and $ulink.show != 0">
959     <!-- * Display the URL for this hyperlink only if it is non-empty, -->
960     <!-- * and the value of its content is not a URL that is the same as -->
961     <!-- * URL it links to, and if ulink.show is non-zero. -->
962     <xsl:choose>
963       <xsl:when test="$ulink.footnotes != 0 and not(ancestor::footnote)">
964         <!-- * ulink.show and ulink.footnote are both non-zero; that -->
965         <!-- * means we display the URL as a footnote (instead of inline) -->
966         <fo:footnote>
967           <xsl:call-template name="ulink.footnote.number"/>
968           <fo:footnote-body xsl:use-attribute-sets="footnote.properties">
969             <fo:block>
970               <xsl:call-template name="ulink.footnote.number"/>
971               <xsl:text> </xsl:text>
972               <fo:basic-link external-destination="{$ulink.url}">
973                 <xsl:value-of select="$url"/>
974               </fo:basic-link>
975             </fo:block>
976           </fo:footnote-body>
977         </fo:footnote>
978       </xsl:when>
979       <xsl:otherwise>
980         <!-- * ulink.show is non-zero, but ulink.footnote is not; that -->
981         <!-- * means we display the URL inline -->
982         <fo:inline hyphenate="false">
983           <!-- * put square brackets around the URL -->
984           <xsl:text> [</xsl:text>
985           <fo:basic-link external-destination="{$ulink.url}">
986             <xsl:call-template name="hyphenate-url">
987               <xsl:with-param name="url" select="$url"/>
988             </xsl:call-template>
989           </fo:basic-link>
990           <xsl:text>]</xsl:text>
991         </fo:inline>
992       </xsl:otherwise>
993     </xsl:choose>
994   </xsl:if>
995
996 </xsl:template>
997
998 <xsl:template name="ulink.footnote.number">
999   <fo:inline xsl:use-attribute-sets="footnote.mark.properties">
1000     <xsl:choose>
1001       <xsl:when test="$fop.extensions != 0">
1002         <xsl:attribute name="vertical-align">super</xsl:attribute>
1003       </xsl:when>
1004       <xsl:otherwise>
1005         <xsl:attribute name="baseline-shift">super</xsl:attribute>
1006       </xsl:otherwise>
1007     </xsl:choose>
1008     <xsl:variable name="fnum">
1009       <!-- * Determine the footnote number to display for this hyperlink, -->
1010       <!-- * by counting all foonotes, ulinks, and any elements that have -->
1011       <!-- * an xlink:href attribute that meets the following criteria: -->
1012       <!-- * -->
1013       <!-- * - the content of the element is not a URI that is the same -->
1014       <!-- *   URI as the value of the href attribute -->
1015       <!-- * - the href attribute is not an internal ID reference (does -->
1016       <!-- *   not start with a hash sign) -->
1017       <!-- * - the href is not part of an olink reference (the element -->
1018       <!-- * - does not have an xlink:role attribute that indicates it is -->
1019       <!-- *   an olink, and the href does not contain a hash sign) -->
1020       <!-- * - the element either has no xlink:type attribute or has -->
1021       <!-- *   an xlink:type attribute whose value is 'simple' -->
1022       <!-- FIXME: list in @from is probably not complete -->
1023       <xsl:number level="any" 
1024                   from="chapter|appendix|preface|article|refentry|bibliography[not(parent::article)]"
1025                   count="footnote[not(@label)][not(ancestor::tgroup)]
1026                   |ulink[node()][@url != .][not(ancestor::footnote)]
1027                   |*[node()][@xlink:href][not(@xlink:href = .)][not(starts-with(@xlink:href,'#'))]
1028                     [not(contains(@xlink:href,'#') and @xlink:role = $xolink.role)]
1029                     [not(@xlink:type) or @xlink:type='simple']
1030                     [not(ancestor::footnote)]"
1031                   format="1"/>
1032     </xsl:variable>
1033     <xsl:choose>
1034       <xsl:when test="string-length($footnote.number.symbols) &gt;= $fnum">
1035         <xsl:value-of select="substring($footnote.number.symbols, $fnum, 1)"/>
1036       </xsl:when>
1037       <xsl:otherwise>
1038         <xsl:number value="$fnum" format="{$footnote.number.format}"/>
1039       </xsl:otherwise>
1040     </xsl:choose>
1041   </fo:inline>
1042 </xsl:template>
1043
1044 <xsl:template name="hyphenate-url">
1045   <xsl:param name="url" select="''"/>
1046   <xsl:choose>
1047     <xsl:when test="$ulink.hyphenate = ''">
1048       <xsl:value-of select="$url"/>
1049     </xsl:when>
1050     <xsl:when test="string-length($url) &gt; 1">
1051       <xsl:variable name="char" select="substring($url, 1, 1)"/>
1052       <xsl:value-of select="$char"/>
1053       <xsl:if test="contains($ulink.hyphenate.chars, $char)">
1054         <!-- Do not hyphen in-between // -->
1055         <xsl:if test="not($char = '/' and substring($url,2,1) = '/')">
1056           <xsl:copy-of select="$ulink.hyphenate"/>
1057         </xsl:if>
1058       </xsl:if>
1059       <!-- recurse to the next character -->
1060       <xsl:call-template name="hyphenate-url">
1061         <xsl:with-param name="url" select="substring($url, 2)"/>
1062       </xsl:call-template>
1063     </xsl:when>
1064     <xsl:otherwise>
1065       <xsl:value-of select="$url"/>
1066     </xsl:otherwise>
1067   </xsl:choose>
1068 </xsl:template>
1069
1070 <xsl:template match="olink" name="olink">
1071   <!-- olink content may be passed in from xlink olink -->
1072   <xsl:param name="content" select="NOTANELEMENT"/>
1073
1074   <xsl:variable name="localinfo" select="@localinfo"/>
1075
1076   <xsl:choose>
1077     <!-- olinks resolved by stylesheet and target database -->
1078     <xsl:when test="@targetdoc or @targetptr or
1079                     (@xlink:role=$xolink.role and
1080                      contains(@xlink:href, '#') )" >
1081
1082       <xsl:variable name="targetdoc.att">
1083         <xsl:choose>
1084           <xsl:when test="@targetdoc != ''">
1085             <xsl:value-of select="@targetdoc"/>
1086           </xsl:when>
1087           <xsl:when test="@xlink:role=$xolink.role and
1088                        contains(@xlink:href, '#')" >
1089             <xsl:value-of select="substring-before(@xlink:href, '#')"/>
1090           </xsl:when>
1091         </xsl:choose>
1092       </xsl:variable>
1093
1094       <xsl:variable name="targetptr.att">
1095         <xsl:choose>
1096           <xsl:when test="@targetptr != ''">
1097             <xsl:value-of select="@targetptr"/>
1098           </xsl:when>
1099           <xsl:when test="@xlink:role=$xolink.role and
1100                        contains(@xlink:href, '#')" >
1101             <xsl:value-of select="substring-after(@xlink:href, '#')"/>
1102           </xsl:when>
1103         </xsl:choose>
1104       </xsl:variable>
1105
1106       <xsl:variable name="olink.lang">
1107         <xsl:call-template name="l10n.language">
1108           <xsl:with-param name="xref-context" select="true()"/>
1109         </xsl:call-template>
1110       </xsl:variable>
1111     
1112       <xsl:variable name="target.database.filename">
1113         <xsl:call-template name="select.target.database">
1114           <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
1115           <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
1116           <xsl:with-param name="olink.lang" select="$olink.lang"/>
1117         </xsl:call-template>
1118       </xsl:variable>
1119     
1120       <xsl:variable name="target.database" 
1121           select="document($target.database.filename, /)"/>
1122     
1123       <xsl:if test="$olink.debug != 0">
1124         <xsl:message>
1125           <xsl:text>Olink debug: root element of target.database is '</xsl:text>
1126           <xsl:value-of select="local-name($target.database/*[1])"/>
1127           <xsl:text>'.</xsl:text>
1128         </xsl:message>
1129       </xsl:if>
1130     
1131       <xsl:variable name="olink.key">
1132         <xsl:call-template name="select.olink.key">
1133           <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
1134           <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
1135           <xsl:with-param name="olink.lang" select="$olink.lang"/>
1136           <xsl:with-param name="target.database" select="$target.database"/>
1137         </xsl:call-template>
1138       </xsl:variable>
1139     
1140       <xsl:if test="string-length($olink.key) = 0">
1141         <xsl:message>
1142           <xsl:text>Error: unresolved olink: </xsl:text>
1143           <xsl:text>targetdoc/targetptr = '</xsl:text>
1144           <xsl:value-of select="$targetdoc.att"/>
1145           <xsl:text>/</xsl:text>
1146           <xsl:value-of select="$targetptr.att"/>
1147           <xsl:text>'.</xsl:text>
1148         </xsl:message>
1149       </xsl:if>
1150
1151       <xsl:variable name="href">
1152         <xsl:call-template name="make.olink.href">
1153           <xsl:with-param name="olink.key" select="$olink.key"/>
1154           <xsl:with-param name="target.database" select="$target.database"/>
1155         </xsl:call-template>
1156       </xsl:variable>
1157
1158       <!-- Olink that points to internal id can be a link -->
1159       <xsl:variable name="linkend">
1160         <xsl:call-template name="olink.as.linkend">
1161           <xsl:with-param name="olink.key" select="$olink.key"/>
1162           <xsl:with-param name="olink.lang" select="$olink.lang"/>
1163           <xsl:with-param name="target.database" select="$target.database"/>
1164         </xsl:call-template>
1165       </xsl:variable>
1166
1167       <xsl:variable name="hottext">
1168         <xsl:choose>
1169           <xsl:when test="string-length($content) != 0">
1170             <xsl:copy-of select="$content"/>
1171           </xsl:when>
1172           <xsl:otherwise>
1173             <xsl:call-template name="olink.hottext">
1174               <xsl:with-param name="olink.key" select="$olink.key"/>
1175               <xsl:with-param name="olink.lang" select="$olink.lang"/>
1176               <xsl:with-param name="target.database" select="$target.database"/>
1177             </xsl:call-template>
1178           </xsl:otherwise>
1179         </xsl:choose>
1180       </xsl:variable>
1181
1182       <xsl:variable name="olink.docname.citation">
1183         <xsl:call-template name="olink.document.citation">
1184           <xsl:with-param name="olink.key" select="$olink.key"/>
1185           <xsl:with-param name="target.database" select="$target.database"/>
1186           <xsl:with-param name="olink.lang" select="$olink.lang"/>
1187         </xsl:call-template>
1188       </xsl:variable>
1189
1190       <xsl:variable name="olink.page.citation">
1191         <xsl:call-template name="olink.page.citation">
1192           <xsl:with-param name="olink.key" select="$olink.key"/>
1193           <xsl:with-param name="target.database" select="$target.database"/>
1194           <xsl:with-param name="olink.lang" select="$olink.lang"/>
1195           <xsl:with-param name="linkend" select="$linkend"/>
1196         </xsl:call-template>
1197       </xsl:variable>
1198
1199       <xsl:choose>
1200         <xsl:when test="$linkend != ''">
1201           <fo:basic-link internal-destination="{$linkend}"
1202                        xsl:use-attribute-sets="xref.properties">
1203             <xsl:call-template name="anchor"/>
1204             <xsl:copy-of select="$hottext"/>
1205             <xsl:copy-of select="$olink.page.citation"/>
1206           </fo:basic-link>
1207         </xsl:when>
1208         <xsl:when test="$href != ''">
1209           <xsl:choose>
1210             <xsl:when test="$fop1.extensions != 0">
1211               <xsl:variable name="mybeg" select="substring-before($href,'#')"/>
1212               <xsl:variable name="myend" select="substring-after($href,'#')"/>
1213               <fo:basic-link external-destination="url({concat($mybeg,'#dest=',$myend)})"
1214                              xsl:use-attribute-sets="olink.properties">
1215                 <xsl:copy-of select="$hottext"/>
1216               </fo:basic-link>
1217               <xsl:copy-of select="$olink.page.citation"/>
1218               <xsl:copy-of select="$olink.docname.citation"/>
1219             </xsl:when>
1220             <xsl:when test="$xep.extensions != 0">
1221               <fo:basic-link external-destination="url({$href})"
1222                              xsl:use-attribute-sets="olink.properties">
1223                 <xsl:call-template name="anchor"/>
1224                 <xsl:copy-of select="$hottext"/>
1225               </fo:basic-link>
1226               <xsl:copy-of select="$olink.page.citation"/>
1227               <xsl:copy-of select="$olink.docname.citation"/>
1228             </xsl:when>
1229             <xsl:when test="$axf.extensions != 0">
1230               <fo:basic-link external-destination="{$href}"
1231                              xsl:use-attribute-sets="olink.properties">
1232                 <xsl:copy-of select="$hottext"/>
1233               </fo:basic-link>
1234               <xsl:copy-of select="$olink.page.citation"/>
1235               <xsl:copy-of select="$olink.docname.citation"/>
1236             </xsl:when>
1237             <xsl:otherwise>
1238               <fo:basic-link external-destination="{$href}"
1239                              xsl:use-attribute-sets="olink.properties">
1240                 <xsl:copy-of select="$hottext"/>
1241               </fo:basic-link>
1242               <xsl:copy-of select="$olink.page.citation"/>
1243               <xsl:copy-of select="$olink.docname.citation"/>
1244             </xsl:otherwise>
1245           </xsl:choose>
1246         </xsl:when>
1247         <xsl:otherwise>
1248           <xsl:copy-of select="$hottext"/>
1249           <xsl:copy-of select="$olink.page.citation"/>
1250           <xsl:copy-of select="$olink.docname.citation"/>
1251         </xsl:otherwise>
1252       </xsl:choose>
1253     </xsl:when>
1254
1255     <!-- olink never implemented in FO for old olink entity syntax -->
1256     <xsl:otherwise>
1257       <xsl:apply-templates/>
1258     </xsl:otherwise>
1259   </xsl:choose>
1260 </xsl:template>
1261
1262 <xsl:template match="*" mode="insert.olink.docname.markup">
1263   <xsl:param name="docname" select="''"/>
1264   
1265   <fo:inline font-style="italic">
1266     <xsl:value-of select="$docname"/>
1267   </fo:inline>
1268
1269 </xsl:template>
1270
1271 <!-- This prevents error message when processing olinks with xrefstyle -->
1272 <xsl:template match="olink" mode="object.xref.template"/>
1273
1274
1275 <xsl:template name="olink.as.linkend">
1276   <xsl:param name="olink.key" select="''"/>
1277   <xsl:param name="olink.lang" select="''"/>
1278   <xsl:param name="target.database" select="NotANode"/>
1279
1280   <xsl:variable name="targetdoc">
1281     <xsl:value-of select="substring-before($olink.key, '/')"/>
1282   </xsl:variable>
1283
1284   <xsl:variable name="targetptr">
1285     <xsl:value-of 
1286        select="substring-before(substring-after($olink.key, '/'), '/')"/>
1287   </xsl:variable>
1288
1289   <xsl:variable name="target.lang">
1290     <xsl:variable name="candidate">
1291       <xsl:for-each select="$target.database" >
1292         <xsl:value-of 
1293                   select="key('targetptr-key', $olink.key)[1]/@lang" />
1294       </xsl:for-each>
1295     </xsl:variable>
1296     <xsl:choose>
1297       <xsl:when test="$candidate != ''">
1298         <xsl:value-of select="$candidate"/>
1299       </xsl:when>
1300       <xsl:otherwise>
1301         <xsl:value-of select="$olink.lang"/>
1302       </xsl:otherwise>
1303     </xsl:choose>
1304   </xsl:variable>
1305
1306   <xsl:if test="$current.docid = $targetdoc and 
1307                 $olink.lang = $target.lang">
1308     <xsl:variable name="targets" select="key('id',$targetptr)"/>
1309     <xsl:variable name="target" select="$targets[1]"/>
1310     <xsl:if test="$target">
1311       <xsl:value-of select="$targetptr"/>
1312     </xsl:if>
1313   </xsl:if>
1314
1315 </xsl:template>
1316
1317
1318 <xsl:template name="olink.outline">
1319   <xsl:param name="outline.base.uri"/>
1320   <xsl:param name="localinfo"/>
1321   <xsl:param name="return" select="href"/>
1322
1323   <xsl:message terminate="yes">Fatal error: olink.outline template: what is this supposed to do?</xsl:message>
1324 </xsl:template>
1325
1326 <!-- ==================================================================== -->
1327
1328 <xsl:template name="title.xref">
1329   <xsl:param name="target" select="."/>
1330   <xsl:choose>
1331     <xsl:when test="local-name($target) = 'figure'
1332                     or local-name($target) = 'example'
1333                     or local-name($target) = 'equation'
1334                     or local-name($target) = 'table'
1335                     or local-name($target) = 'dedication'
1336                     or local-name($target) = 'acknowledgements'
1337                     or local-name($target) = 'preface'
1338                     or local-name($target) = 'bibliography'
1339                     or local-name($target) = 'glossary'
1340                     or local-name($target) = 'index'
1341                     or local-name($target) = 'setindex'
1342                     or local-name($target) = 'colophon'">
1343       <xsl:call-template name="gentext.startquote"/>
1344       <xsl:apply-templates select="$target" mode="title.markup"/>
1345       <xsl:call-template name="gentext.endquote"/>
1346     </xsl:when>
1347     <xsl:otherwise>
1348       <fo:inline font-style="italic">
1349         <xsl:apply-templates select="$target" mode="title.markup"/>
1350       </fo:inline>
1351     </xsl:otherwise>
1352   </xsl:choose>
1353 </xsl:template>
1354
1355 <xsl:template name="number.xref">
1356   <xsl:param name="target" select="."/>
1357   <xsl:apply-templates select="$target" mode="label.markup"/>
1358 </xsl:template>
1359
1360 <!-- ==================================================================== -->
1361
1362 <xsl:template name="xref.xreflabel">
1363   <!-- called to process an xreflabel...you might use this to make  -->
1364   <!-- xreflabels come out in the right font for different targets, -->
1365   <!-- for example. -->
1366   <xsl:param name="target" select="."/>
1367   <xsl:value-of select="$target/@xreflabel"/>
1368 </xsl:template>
1369
1370 <!-- ==================================================================== -->
1371
1372 <xsl:template match="title" mode="xref">
1373   <xsl:apply-templates/>
1374 </xsl:template>
1375
1376 <xsl:template match="command" mode="xref">
1377   <xsl:call-template name="inline.boldseq"/>
1378 </xsl:template>
1379
1380 <xsl:template match="function" mode="xref">
1381   <xsl:call-template name="inline.monoseq"/>
1382 </xsl:template>
1383
1384 <xsl:template match="*" mode="page.citation">
1385   <xsl:param name="id" select="'???'"/>
1386
1387   <fo:basic-link internal-destination="{$id}"
1388                  xsl:use-attribute-sets="xref.properties">
1389     <fo:inline keep-together.within-line="always">
1390       <xsl:call-template name="substitute-markup">
1391         <xsl:with-param name="template">
1392           <xsl:call-template name="gentext.template">
1393             <xsl:with-param name="name" select="'page.citation'"/>
1394             <xsl:with-param name="context" select="'xref'"/>
1395           </xsl:call-template>
1396         </xsl:with-param>
1397       </xsl:call-template>
1398     </fo:inline>
1399   </fo:basic-link>
1400 </xsl:template>
1401
1402 <xsl:template match="*" mode="pagenumber.markup">
1403   <xsl:variable name="id">
1404     <xsl:call-template name="object.id"/>
1405   </xsl:variable>
1406   <fo:page-number-citation ref-id="{$id}"/>
1407 </xsl:template>
1408
1409 <!-- ==================================================================== -->
1410
1411 <xsl:template match="*" mode="insert.title.markup">
1412   <xsl:param name="purpose"/>
1413   <xsl:param name="xrefstyle"/>
1414   <xsl:param name="title"/>
1415
1416   <xsl:choose>
1417     <!-- FIXME: what about the case where titleabbrev is inside the info? -->
1418     <xsl:when test="$purpose = 'xref' and titleabbrev">
1419       <xsl:apply-templates select="." mode="titleabbrev.markup"/>
1420     </xsl:when>
1421     <xsl:otherwise>
1422       <xsl:copy-of select="$title"/>
1423     </xsl:otherwise>
1424   </xsl:choose>
1425 </xsl:template>
1426
1427 <xsl:template match="chapter|appendix" mode="insert.title.markup">
1428   <xsl:param name="purpose"/>
1429   <xsl:param name="xrefstyle"/>
1430   <xsl:param name="title"/>
1431
1432   <xsl:choose>
1433     <xsl:when test="$purpose = 'xref'">
1434       <fo:inline font-style="italic">
1435         <xsl:copy-of select="$title"/>
1436       </fo:inline>
1437     </xsl:when>
1438     <xsl:otherwise>
1439       <xsl:copy-of select="$title"/>
1440     </xsl:otherwise>
1441   </xsl:choose>
1442 </xsl:template>
1443
1444 <xsl:template match="*" mode="insert.subtitle.markup">
1445   <xsl:param name="purpose"/>
1446   <xsl:param name="xrefstyle"/>
1447   <xsl:param name="subtitle"/>
1448
1449   <xsl:copy-of select="$subtitle"/>
1450 </xsl:template>
1451
1452 <xsl:template match="*" mode="insert.label.markup">
1453   <xsl:param name="purpose"/>
1454   <xsl:param name="xrefstyle"/>
1455   <xsl:param name="label"/>
1456
1457   <xsl:copy-of select="$label"/>
1458 </xsl:template>
1459
1460 <xsl:template match="*" mode="insert.pagenumber.markup">
1461   <xsl:param name="purpose"/>
1462   <xsl:param name="xrefstyle"/>
1463   <xsl:param name="pagenumber"/>
1464
1465   <xsl:copy-of select="$pagenumber"/>
1466 </xsl:template>
1467
1468 <xsl:template match="*" mode="insert.direction.markup">
1469   <xsl:param name="purpose"/>
1470   <xsl:param name="xrefstyle"/>
1471   <xsl:param name="direction"/>
1472
1473   <xsl:copy-of select="$direction"/>
1474 </xsl:template>
1475
1476 <xsl:template match="olink" mode="pagenumber.markup">
1477   <!-- Local olinks can use page-citation -->
1478   <xsl:variable name="targetdoc.att" select="@targetdoc"/>
1479   <xsl:variable name="targetptr.att" select="@targetptr"/>
1480
1481   <xsl:variable name="olink.lang">
1482     <xsl:call-template name="l10n.language">
1483       <xsl:with-param name="xref-context" select="true()"/>
1484     </xsl:call-template>
1485   </xsl:variable>
1486
1487   <xsl:variable name="target.database.filename">
1488     <xsl:call-template name="select.target.database">
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:call-template>
1493   </xsl:variable>
1494
1495   <xsl:variable name="target.database" 
1496       select="document($target.database.filename, /)"/>
1497
1498   <xsl:if test="$olink.debug != 0">
1499     <xsl:message>
1500       <xsl:text>Olink debug: root element of target.database is '</xsl:text>
1501       <xsl:value-of select="local-name($target.database/*[1])"/>
1502       <xsl:text>'.</xsl:text>
1503     </xsl:message>
1504   </xsl:if>
1505
1506   <xsl:variable name="olink.key">
1507     <xsl:call-template name="select.olink.key">
1508       <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
1509       <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
1510       <xsl:with-param name="olink.lang" select="$olink.lang"/>
1511       <xsl:with-param name="target.database" select="$target.database"/>
1512     </xsl:call-template>
1513   </xsl:variable>
1514
1515   <!-- Olink that points to internal id can be a link -->
1516   <xsl:variable name="linkend">
1517     <xsl:call-template name="olink.as.linkend">
1518       <xsl:with-param name="olink.key" select="$olink.key"/>
1519       <xsl:with-param name="olink.lang" select="$olink.lang"/>
1520       <xsl:with-param name="target.database" select="$target.database"/>
1521     </xsl:call-template>
1522   </xsl:variable>
1523
1524   <xsl:choose>
1525     <xsl:when test="$linkend != ''">
1526       <fo:page-number-citation ref-id="{$linkend}"/>
1527     </xsl:when>
1528     <xsl:otherwise>
1529       <xsl:message>
1530         <xsl:text>Olink error: no page number linkend for local olink '</xsl:text>
1531         <xsl:value-of select="$olink.key"/>
1532         <xsl:text>'</xsl:text>
1533       </xsl:message>
1534     </xsl:otherwise>
1535   </xsl:choose>
1536 </xsl:template>
1537
1538 </xsl:stylesheet>