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