2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5 <!-- ********************************************************************
6 $Id: olink.xsl 8592 2010-03-16 16:40:43Z bobstayton $
7 ********************************************************************
9 This file is part of the DocBook XSL Stylesheet distribution.
10 See ../README or http://docbook.sf.net/ for copyright
11 copyright and other information.
13 ******************************************************************** -->
15 <!-- Create keys for quickly looking up olink targets -->
16 <xsl:key name="targetdoc-key" match="document" use="@targetdoc" />
17 <xsl:key name="targetptr-key" match="div|obj"
18 use="concat(ancestor::document/@targetdoc, '/',
19 @targetptr, '/', ancestor::document/@lang)" />
21 <!-- Return filename of database -->
22 <xsl:template name="select.target.database">
23 <xsl:param name="targetdoc.att" select="''"/>
24 <xsl:param name="targetptr.att" select="''"/>
25 <xsl:param name="olink.lang" select="''"/>
27 <!-- use root's xml:base if exists -->
28 <xsl:variable name="xml.base" select="/*/@xml:base"/>
30 <!-- This selection can be customized if needed -->
31 <xsl:variable name="target.database.filename">
33 <xsl:when test="$xml.base != '' and
34 not(starts-with($target.database.document, 'file:/')) and
35 not(starts-with($target.database.document, '/'))">
36 <xsl:call-template name="systemIdToBaseURI">
37 <xsl:with-param name="systemId" select="$xml.base"/>
39 <xsl:value-of select="$target.database.document"/>
42 <xsl:value-of select="$target.database.document"/>
47 <xsl:variable name="target.database"
48 select="document($target.database.filename,/)"/>
51 <!-- Was the database document parameter not set? -->
52 <xsl:when test="$target.database.document = ''">
54 <xsl:text>Olinks not processed: must specify a </xsl:text>
55 <xsl:text>$target.database.document parameter </xsl:text>
56 <xsl:text>when using olinks with targetdoc </xsl:text>
57 <xsl:text>and targetptr attributes.</xsl:text>
60 <!-- Did it not open? Should be a targetset element -->
61 <xsl:when test="not($target.database/*)">
63 <xsl:text>Olink error: could not open target database '</xsl:text>
64 <xsl:value-of select="$target.database.filename"/>
65 <xsl:text>'.</xsl:text>
69 <xsl:value-of select="$target.database.filename"/>
74 <xsl:template name="select.olink.key">
75 <xsl:param name="targetdoc.att" select="''"/>
76 <xsl:param name="targetptr.att" select="''"/>
77 <xsl:param name="olink.lang" select="''"/>
78 <xsl:param name="target.database"/>
80 <xsl:if test="$target.database/*">
81 <xsl:variable name="olink.fallback.sequence">
82 <xsl:call-template name="select.olink.lang.fallback">
83 <xsl:with-param name="olink.lang" select="$olink.lang"/>
87 <!-- Recurse through the languages until you find a match -->
88 <xsl:call-template name="select.olink.key.in.lang">
89 <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
90 <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
91 <xsl:with-param name="olink.lang" select="$olink.lang"/>
92 <xsl:with-param name="target.database" select="$target.database"/>
93 <xsl:with-param name="fallback.index" select="1"/>
94 <xsl:with-param name="olink.fallback.sequence"
95 select="$olink.fallback.sequence"/>
101 <!-- Locate olink key in a particular language -->
102 <xsl:template name="select.olink.key.in.lang">
103 <xsl:param name="targetdoc.att" select="''"/>
104 <xsl:param name="targetptr.att" select="''"/>
105 <xsl:param name="olink.lang" select="''"/>
106 <xsl:param name="target.database"/>
107 <xsl:param name="fallback.index" select="1"/>
108 <xsl:param name="olink.fallback.sequence" select="''"/>
110 <xsl:variable name="target.lang">
111 <xsl:call-template name="select.target.lang">
112 <xsl:with-param name="fallback.index" select="$fallback.index"/>
113 <xsl:with-param name="olink.fallback.sequence"
114 select="$olink.fallback.sequence"/>
118 <xsl:if test="$olink.debug != 0">
119 <xsl:message><xsl:text>Olink debug: cases for targetdoc='</xsl:text>
120 <xsl:value-of select="$targetdoc.att"/>
121 <xsl:text>' and targetptr='</xsl:text>
122 <xsl:value-of select="$targetptr.att"/>
123 <xsl:text>' in language '</xsl:text>
124 <xsl:value-of select="$target.lang"/>
125 <xsl:text>'.</xsl:text>
129 <!-- Customize these cases if you want different selection logic -->
130 <xsl:variable name="CaseA">
131 <!-- targetdoc.att = not blank
132 targetptr.att = not blank
134 <xsl:if test="$targetdoc.att != '' and
135 $targetptr.att != ''">
136 <xsl:for-each select="$target.database">
137 <xsl:variable name="key"
138 select="concat($targetdoc.att, '/',
142 <xsl:when test="key('targetptr-key', $key)[1]/@href != ''">
143 <xsl:value-of select="$key"/>
144 <xsl:if test="$olink.debug != 0">
145 <xsl:message>Olink debug: CaseA matched.</xsl:message>
148 <xsl:when test="$olink.debug != 0">
149 <xsl:message>Olink debug: CaseA NOT matched</xsl:message>
156 <xsl:variable name="CaseB">
157 <!-- targetdoc.att = not blank
158 targetptr.att = not blank
159 prefer.internal.olink = not zero
160 current.docid = not blank
162 <xsl:if test="$targetdoc.att != '' and
163 $targetptr.att != '' and
164 $current.docid != '' and
165 $prefer.internal.olink != 0">
166 <xsl:for-each select="$target.database">
167 <xsl:variable name="key"
168 select="concat($current.docid, '/',
172 <xsl:when test="key('targetptr-key', $key)[1]/@href != ''">
173 <xsl:value-of select="$key"/>
174 <xsl:if test="$olink.debug != 0">
175 <xsl:message>Olink debug: CaseB matched.</xsl:message>
178 <xsl:when test="$olink.debug != 0">
179 <xsl:message>Olink debug: CaseB NOT matched</xsl:message>
186 <xsl:variable name="CaseC">
187 <!-- targetdoc.att = blank
188 targetptr.att = not blank
189 current.docid = not blank
191 <xsl:if test="string-length($targetdoc.att) = 0 and
192 $targetptr.att != '' and
193 $current.docid != ''">
194 <!-- Must use a for-each to change context for keys to work -->
195 <xsl:for-each select="$target.database">
196 <xsl:variable name="key"
197 select="concat($current.docid, '/',
201 <xsl:when test="key('targetptr-key', $key)[1]/@href != ''">
202 <xsl:value-of select="$key"/>
203 <xsl:if test="$olink.debug != 0">
204 <xsl:message>Olink debug: CaseC matched.</xsl:message>
207 <xsl:when test="$olink.debug != 0">
208 <xsl:message>Olink debug: CaseC NOT matched.</xsl:message>
215 <xsl:variable name="CaseD">
216 <!-- targetdoc.att = blank
217 targetptr.att = not blank
218 current.docid = blank
220 <!-- This is possible if only one document in the database -->
221 <xsl:if test="string-length($targetdoc.att) = 0 and
222 $targetptr.att != '' and
223 string-length($current.docid) = 0 and
224 count($target.database//document) = 1">
225 <xsl:for-each select="$target.database">
226 <xsl:variable name="key"
227 select="concat(.//document/@targetdoc, '/',
231 <xsl:when test="key('targetptr-key', $key)[1]/@href != ''">
232 <xsl:value-of select="$key"/>
233 <xsl:if test="$olink.debug != 0">
234 <xsl:message>Olink debug: CaseD matched.</xsl:message>
237 <xsl:when test="$olink.debug != 0">
238 <xsl:message>Olink debug: CaseD NOT matched</xsl:message>
245 <xsl:variable name="CaseE">
246 <!-- targetdoc.att = not blank
247 targetptr.att = blank
249 <xsl:if test="$targetdoc.att != '' and
250 string-length($targetptr.att) = 0">
252 <!-- Try the document's root element id -->
253 <xsl:variable name="rootid">
255 <xsl:when test="$target.lang != ''">
256 <xsl:value-of select="$target.database//document[@targetdoc = $targetdoc.att and @lang = $target.lang]/*[1]/@targetptr"/>
259 <xsl:value-of select="$target.database//document[@targetdoc = $targetdoc.att and not(@lang)]/*[1]/@targetptr"/>
264 <xsl:for-each select="$target.database">
265 <xsl:variable name="key"
266 select="concat($targetdoc.att, '/',
270 <xsl:when test="key('targetptr-key', $key)[1]/@href != ''">
271 <xsl:value-of select="$key"/>
272 <xsl:if test="$olink.debug != 0">
273 <xsl:message>Olink debug: CaseE matched.</xsl:message>
276 <xsl:when test="$olink.debug != 0">
277 <xsl:message>Olink debug: CaseE NOT matched.</xsl:message>
284 <xsl:variable name="CaseF">
285 <!-- targetdoc.att = not blank
286 targetptr.att = blank
287 prefer.internal.olink = not zero
288 current.docid = not blank
290 <xsl:if test="$targetdoc.att != '' and
291 string-length($targetptr.att) = 0 and
292 $current.docid != '' and
293 $prefer.internal.olink != 0">
294 <!-- Try the document's root element id -->
295 <xsl:variable name="rootid">
297 <xsl:when test="$target.lang != ''">
298 <xsl:value-of select="$target.database//document[@targetdoc = $current.docid and @lang = $target.lang]/*[1]/@targetptr"/>
301 <xsl:value-of select="$target.database//document[@targetdoc = $current.docid and not(@lang)]/*[1]/@targetptr"/>
306 <xsl:for-each select="$target.database">
307 <xsl:variable name="key"
308 select="concat($current.docid, '/',
312 <xsl:when test="key('targetptr-key', $key)[1]/@href != ''">
313 <xsl:value-of select="$key"/>
314 <xsl:if test="$olink.debug != 0">
315 <xsl:message>Olink debug: CaseF matched.</xsl:message>
318 <xsl:when test="$olink.debug != 0">
319 <xsl:message>Olink debug: CaseF NOT matched.</xsl:message>
326 <!-- Now select the best match. Customize the order if needed -->
327 <xsl:variable name="selected.key">
329 <xsl:when test="$CaseB != ''">
330 <xsl:value-of select="$CaseB"/>
331 <xsl:if test="$olink.debug != 0">
333 <xsl:text>Olink debug: CaseB key is the final selection: </xsl:text>
334 <xsl:value-of select="$CaseB"/>
338 <xsl:when test="$CaseA != ''">
339 <xsl:value-of select="$CaseA"/>
340 <xsl:if test="$olink.debug != 0">
342 <xsl:text>Olink debug: CaseA key is the final selection: </xsl:text>
343 <xsl:value-of select="$CaseA"/>
347 <xsl:when test="$CaseC != ''">
348 <xsl:value-of select="$CaseC"/>
349 <xsl:if test="$olink.debug != 0">
351 <xsl:text>Olink debug: CaseC key is the final selection: </xsl:text>
352 <xsl:value-of select="$CaseC"/>
356 <xsl:when test="$CaseD != ''">
357 <xsl:value-of select="$CaseD"/>
358 <xsl:if test="$olink.debug != 0">
360 <xsl:text>Olink debug: CaseD key is the final selection: </xsl:text>
361 <xsl:value-of select="$CaseD"/>
365 <xsl:when test="$CaseF != ''">
366 <xsl:value-of select="$CaseF"/>
367 <xsl:if test="$olink.debug != 0">
369 <xsl:text>Olink debug: CaseF key is the final selection: </xsl:text>
370 <xsl:value-of select="$CaseF"/>
374 <xsl:when test="$CaseE != ''">
375 <xsl:value-of select="$CaseE"/>
376 <xsl:if test="$olink.debug != 0">
378 <xsl:text>Olink debug: CaseE key is the final selection: </xsl:text>
379 <xsl:value-of select="$CaseE"/>
384 <xsl:if test="$olink.debug != 0">
386 <xsl:text>Olink debug: No case matched for lang '</xsl:text>
387 <xsl:value-of select="$target.lang"/>
388 <xsl:text>'.</xsl:text>
396 <xsl:when test="$selected.key != ''">
397 <xsl:value-of select="$selected.key"/>
399 <xsl:when test="string-length($selected.key) = 0 and
400 string-length($target.lang) = 0">
401 <!-- No match on last try, and we are done -->
404 <!-- Recurse through next language -->
405 <xsl:call-template name="select.olink.key.in.lang">
406 <xsl:with-param name="targetdoc.att" select="$targetdoc.att"/>
407 <xsl:with-param name="targetptr.att" select="$targetptr.att"/>
408 <xsl:with-param name="olink.lang" select="$olink.lang"/>
409 <xsl:with-param name="target.database" select="$target.database"/>
410 <xsl:with-param name="fallback.index" select="$fallback.index + 1"/>
411 <xsl:with-param name="olink.fallback.sequence"
412 select="$olink.fallback.sequence"/>
419 <xsl:template name="select.target.lang">
420 <xsl:param name="fallback.index" select="1"/>
421 <xsl:param name="olink.fallback.sequence" select="''"/>
423 <!-- recurse backwards to find the lang matching the index -->
424 <xsl:variable name="firstlang"
425 select="substring-before($olink.fallback.sequence, ' ')"/>
426 <xsl:variable name="rest"
427 select="substring-after($olink.fallback.sequence, ' ')"/>
429 <xsl:when test="$fallback.index = 1">
430 <xsl:value-of select="$firstlang"/>
432 <xsl:when test="$fallback.index > 1">
433 <xsl:call-template name="select.target.lang">
434 <xsl:with-param name="fallback.index" select="$fallback.index - 1"/>
435 <xsl:with-param name="olink.fallback.sequence"
444 <xsl:template name="select.olink.lang.fallback">
445 <xsl:param name="olink.lang" select="''"/>
447 <!-- Prefer language of the olink element -->
448 <xsl:value-of select="concat(normalize-space(concat($olink.lang, ' ',
449 $olink.lang.fallback.sequence)), ' ')"/>
452 <!-- Returns the complete olink href value if found -->
453 <xsl:template name="make.olink.href">
454 <xsl:param name="olink.key" select="''"/>
455 <xsl:param name="target.database"/>
457 <xsl:if test="$olink.key != ''">
458 <xsl:variable name="target.href" >
459 <xsl:for-each select="$target.database" >
460 <xsl:value-of select="key('targetptr-key', $olink.key)[1]/@href" />
464 <xsl:variable name="targetdoc">
465 <xsl:value-of select="substring-before($olink.key, '/')"/>
468 <!-- Does the target database use a sitemap? -->
469 <xsl:variable name="use.sitemap">
471 <xsl:when test="$target.database//sitemap">1</xsl:when>
472 <xsl:otherwise>0</xsl:otherwise>
477 <!-- Get the baseuri for this targetptr -->
478 <xsl:variable name="baseuri" >
480 <!-- Does the database use a sitemap? -->
481 <xsl:when test="$use.sitemap != 0" >
483 <!-- Was current.docid parameter set? -->
484 <xsl:when test="$current.docid != ''">
485 <!-- Was it found in the database? -->
486 <xsl:variable name="currentdoc.key" >
487 <xsl:for-each select="$target.database" >
488 <xsl:value-of select="key('targetdoc-key',
489 $current.docid)[1]/@targetdoc" />
493 <xsl:when test="$currentdoc.key != ''">
494 <xsl:for-each select="$target.database" >
495 <xsl:call-template name="targetpath" >
496 <xsl:with-param name="dirnode"
497 select="key('targetdoc-key', $current.docid)[1]/parent::dir"/>
498 <xsl:with-param name="targetdoc" select="$targetdoc"/>
504 <xsl:text>Olink error: cannot compute relative </xsl:text>
505 <xsl:text>sitemap path because $current.docid '</xsl:text>
506 <xsl:value-of select="$current.docid"/>
507 <xsl:text>' not found in target database.</xsl:text>
514 <xsl:text>Olink warning: cannot compute relative </xsl:text>
515 <xsl:text>sitemap path without $current.docid parameter</xsl:text>
519 <!-- In either case, add baseuri from its document entry-->
520 <xsl:variable name="docbaseuri">
521 <xsl:for-each select="$target.database" >
522 <xsl:value-of select="key('targetdoc-key', $targetdoc)[1]/@baseuri" />
525 <xsl:if test="$docbaseuri != ''" >
526 <xsl:value-of select="$docbaseuri"/>
529 <!-- No database sitemap in use -->
531 <!-- Just use any baseuri from its document entry -->
532 <xsl:variable name="docbaseuri">
533 <xsl:for-each select="$target.database" >
534 <xsl:value-of select="key('targetdoc-key', $targetdoc)[1]/@baseuri" />
537 <xsl:if test="$docbaseuri != ''" >
538 <xsl:value-of select="$docbaseuri"/>
544 <!-- Form the href information -->
545 <xsl:if test="$baseuri != ''">
546 <xsl:value-of select="$baseuri"/>
547 <xsl:if test="substring($target.href,1,1) != '#'">
548 <!--xsl:text>/</xsl:text-->
551 <!-- optionally turn off frag for PDF references -->
552 <xsl:if test="not($insert.olink.pdf.frag = 0 and
553 translate(substring($baseuri, string-length($baseuri) - 3),
554 'PDF', 'pdf') = '.pdf'
555 and starts-with($target.href, '#') )">
556 <xsl:value-of select="$target.href"/>
561 <!-- Computes the href of the object containing the olink element -->
562 <xsl:template name="olink.from.uri">
563 <xsl:param name="target.database"/>
564 <xsl:param name="object" select="NotAnElement"/>
565 <xsl:param name="object.targetdoc" select="$current.docid"/>
566 <xsl:param name="object.lang"
567 select="concat($object/ancestor::*[last()]/@lang,
568 $object/ancestor::*[last()]/@xml:lang)"/>
570 <xsl:variable name="parent.id">
571 <xsl:call-template name="object.id">
572 <xsl:with-param name="object" select="$object"/>
576 <!-- Get the olink key for the parent of olink element -->
577 <xsl:variable name="from.key">
578 <xsl:call-template name="select.olink.key">
579 <xsl:with-param name="targetdoc.att" select="$object.targetdoc"/>
580 <xsl:with-param name="targetptr.att" select="$parent.id"/>
581 <xsl:with-param name="olink.lang" select="$object.lang"/>
582 <xsl:with-param name="target.database" select="$target.database"/>
586 <xsl:variable name="from.olink.href">
587 <xsl:for-each select="$target.database" >
588 <xsl:value-of select="key('targetptr-key', $from.key)[1]/@href" />
593 <!-- we found the olink object -->
594 <xsl:when test="$from.olink.href != ''">
595 <xsl:value-of select="$from.olink.href"/>
597 <xsl:when test="not($object/parent::*)">
598 <xsl:value-of select="$from.olink.href"/>
601 <!-- recurse upward in current document -->
602 <xsl:call-template name="olink.from.uri">
603 <xsl:with-param name="target.database" select="$target.database"/>
604 <xsl:with-param name="object" select="$object/parent::*"/>
605 <xsl:with-param name="object.targetdoc" select="$object.targetdoc"/>
606 <xsl:with-param name="object.lang" select="$object.lang"/>
613 <xsl:template name="olink.hottext">
614 <xsl:param name="target.database"/>
615 <xsl:param name="olink.lang" select="''"/>
616 <xsl:param name="olink.key" select="''"/>
617 <xsl:param name="referrer" select="."/>
618 <xsl:param name="xrefstyle">
620 <xsl:when test="@role and not(@xrefstyle)
621 and $use.role.as.xrefstyle != 0">
622 <xsl:value-of select="@role"/>
625 <xsl:value-of select="@xrefstyle"/>
631 <!-- If it has elements or text (not just PI or comment) -->
632 <xsl:when test="child::text() or child::*">
633 <xsl:apply-templates/>
635 <xsl:when test="$olink.key != ''">
636 <!-- Get the xref text for this record -->
637 <xsl:variable name="xref.text" >
638 <xsl:for-each select="$target.database" >
639 <xsl:call-template name="insert.targetdb.data">
640 <xsl:with-param name="data"
641 select="key('targetptr-key', $olink.key)[1]/xreftext/node()" />
646 <xsl:variable name="xref.number" >
647 <xsl:for-each select="$target.database" >
648 <xsl:value-of select="key('targetptr-key', $olink.key)[1]/@number" />
652 <xsl:variable name="target.elem" >
653 <xsl:for-each select="$target.database" >
654 <xsl:value-of select="key('targetptr-key', $olink.key)[1]/@element" />
658 <xsl:variable name="lang">
659 <xsl:variable name="candidate">
660 <xsl:for-each select="$target.database" >
662 select="key('targetptr-key', $olink.key)[1]/@lang" />
666 <xsl:when test="$candidate != ''">
667 <xsl:value-of select="$candidate"/>
670 <xsl:value-of select="$olink.lang"/>
675 <xsl:variable name="targetdoc">
676 <xsl:value-of select="substring-before($olink.key, '/')"/>
680 <xsl:when test="$xrefstyle != '' and
681 starts-with(normalize-space($xrefstyle), 'select:') and
682 (contains($xrefstyle, 'nodocname') or
683 contains($xrefstyle, 'nopage')) and
684 not(contains($xrefstyle, 'title')) and
685 not(contains($xrefstyle, 'label'))">
686 <xsl:copy-of select="$xref.text"/>
688 <xsl:when test="$xrefstyle != ''">
689 <xsl:if test="$olink.debug != 0">
691 <xsl:text>xrefstyle is '</xsl:text>
692 <xsl:value-of select="$xrefstyle"/>
693 <xsl:text>'.</xsl:text>
696 <xsl:variable name="template">
698 <xsl:when test="starts-with(normalize-space($xrefstyle),
700 <xsl:call-template name="make.gentext.template">
701 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
702 <xsl:with-param name="purpose" select="'olink'"/>
703 <xsl:with-param name="referrer" select="."/>
704 <xsl:with-param name="target.elem" select="$target.elem"/>
707 <xsl:when test="starts-with(normalize-space($xrefstyle),
709 <xsl:value-of select="substring-after(
710 normalize-space($xrefstyle), 'template:')"/>
713 <!-- Look for Gentext template with @style attribute -->
714 <!-- Must compare to no style value because gentext.template
715 falls back to no style -->
717 <xsl:variable name="xref-context">
718 <xsl:call-template name="gentext.template">
719 <xsl:with-param name="context" select="'xref'"/>
720 <xsl:with-param name="name" select="$target.elem"/>
721 <xsl:with-param name="lang" select="$lang"/>
725 <xsl:variable name="styled-xref-context">
726 <xsl:call-template name="gentext.template">
727 <xsl:with-param name="context" select="'xref'"/>
728 <xsl:with-param name="name" select="$target.elem"/>
729 <xsl:with-param name="lang" select="$lang"/>
730 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
734 <xsl:variable name="xref-number-context">
735 <xsl:call-template name="gentext.template">
736 <xsl:with-param name="context" select="'xref-number'"/>
737 <xsl:with-param name="name" select="$target.elem"/>
738 <xsl:with-param name="lang" select="$lang"/>
742 <xsl:variable name="styled-xref-number-context">
743 <xsl:call-template name="gentext.template">
744 <xsl:with-param name="context" select="'xref-number'"/>
745 <xsl:with-param name="name" select="$target.elem"/>
746 <xsl:with-param name="lang" select="$lang"/>
747 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
751 <xsl:variable name="xref-number-and-title-context">
752 <xsl:call-template name="gentext.template">
753 <xsl:with-param name="context"
754 select="'xref-number-and-title'"/>
755 <xsl:with-param name="name" select="$target.elem"/>
756 <xsl:with-param name="lang" select="$lang"/>
760 <xsl:variable name="styled-xref-number-and-title-context">
761 <xsl:call-template name="gentext.template">
762 <xsl:with-param name="context"
763 select="'xref-number-and-title'"/>
764 <xsl:with-param name="name" select="$target.elem"/>
765 <xsl:with-param name="lang" select="$lang"/>
766 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
771 <xsl:when test="$xref-number-and-title-context !=
772 $styled-xref-number-and-title-context and
773 $xref.number != '' and
774 $xref.with.number.and.title != 0">
776 select="$styled-xref-number-and-title-context"/>
778 <xsl:when test="$xref-number-context !=
779 $styled-xref-number-context and
781 <xsl:value-of select="$styled-xref-number-context"/>
783 <xsl:when test="$xref-context != $styled-xref-context">
784 <xsl:value-of select="$styled-xref-context"/>
786 <xsl:when test="$xref-number-and-title-context != '' and
787 $xref.number != '' and
788 $xref.with.number.and.title != 0">
790 select="$xref-number-and-title-context"/>
791 <xsl:if test="$olink.debug">
793 <xsl:text>Olink error: no gentext template</xsl:text>
794 <xsl:text> exists for xrefstyle '</xsl:text>
795 <xsl:value-of select="$xrefstyle"/>
796 <xsl:text>' for element '</xsl:text>
797 <xsl:value-of select="$target.elem"/>
798 <xsl:text>' in language '</xsl:text>
799 <xsl:value-of select="$lang"/>
800 <xsl:text>' in context 'xref-number-and-title</xsl:text>
801 <xsl:text>'. Using template without @style.</xsl:text>
805 <xsl:when test="$xref-number-context != '' and
807 <xsl:value-of select="$xref-number-context"/>
808 <xsl:if test="$olink.debug">
810 <xsl:text>Olink error: no gentext template</xsl:text>
811 <xsl:text> exists for xrefstyle '</xsl:text>
812 <xsl:value-of select="$xrefstyle"/>
813 <xsl:text>' for element '</xsl:text>
814 <xsl:value-of select="$target.elem"/>
815 <xsl:text>' in language '</xsl:text>
816 <xsl:value-of select="$lang"/>
817 <xsl:text>' in context 'xref-number</xsl:text>
818 <xsl:text>'. Using template without @style.</xsl:text>
822 <xsl:when test="$xref-context != ''">
823 <xsl:value-of select="$xref-context"/>
824 <xsl:if test="$olink.debug">
826 <xsl:text>Olink error: no gentext template</xsl:text>
827 <xsl:text> exists for xrefstyle '</xsl:text>
828 <xsl:value-of select="$xrefstyle"/>
829 <xsl:text>' for element '</xsl:text>
830 <xsl:value-of select="$target.elem"/>
831 <xsl:text>' in language '</xsl:text>
832 <xsl:value-of select="$lang"/>
833 <xsl:text>' in context 'xref</xsl:text>
834 <xsl:text>'. Using template without @style.</xsl:text>
840 <xsl:text>Olink error: no gentext template</xsl:text>
841 <xsl:text> exists for xrefstyle '</xsl:text>
842 <xsl:value-of select="$xrefstyle"/>
843 <xsl:text>' for element '</xsl:text>
844 <xsl:value-of select="$target.elem"/>
845 <xsl:text>' in language '</xsl:text>
846 <xsl:value-of select="$lang"/>
847 <xsl:text>'. Trying '%t'.</xsl:text>
849 <xsl:value-of select="'%t'"/>
856 <xsl:if test="$olink.debug != 0">
858 <xsl:text>Olink debug: xrefstyle template is '</xsl:text>
859 <xsl:value-of select="$template"/>
860 <xsl:text>'.</xsl:text>
864 <xsl:call-template name="substitute-markup">
865 <xsl:with-param name="template" select="$template"/>
866 <xsl:with-param name="title">
867 <xsl:for-each select="$target.database" >
868 <xsl:call-template name="insert.targetdb.data">
869 <xsl:with-param name="data"
870 select="key('targetptr-key', $olink.key)/ttl/node()"/>
874 <xsl:with-param name="label">
875 <xsl:for-each select="$target.database" >
877 select="key('targetptr-key', $olink.key)[1]/@number" />
880 <xsl:with-param name="pagenumber">
881 <xsl:for-each select="$target.database" >
883 select="key('targetptr-key', $olink.key)[1]/@page" />
886 <xsl:with-param name="docname">
887 <xsl:for-each select="$target.database" >
888 <xsl:call-template name="insert.targetdb.data">
889 <xsl:with-param name="data"
890 select="key('targetdoc-key', $targetdoc)[1]/div[1]/ttl/node()" />
897 <xsl:when test="$use.local.olink.style != 0">
899 <!-- Is autonumbering on? -->
900 <xsl:variable name="target.number">
901 <xsl:for-each select="$target.database" >
903 select="key('targetptr-key', $olink.key)[1]/@number" />
907 <xsl:variable name="autonumber">
909 <xsl:when test="$target.number != ''">1</xsl:when>
910 <xsl:otherwise>0</xsl:otherwise>
914 <xsl:variable name="number-and-title-template">
915 <xsl:call-template name="gentext.template.exists">
916 <xsl:with-param name="context" select="'xref-number-and-title'"/>
917 <xsl:with-param name="name" select="$target.elem"/>
921 <xsl:variable name="number-template">
922 <xsl:call-template name="gentext.template.exists">
923 <xsl:with-param name="context" select="'xref-number'"/>
924 <xsl:with-param name="name" select="$target.elem"/>
928 <xsl:variable name="context">
930 <xsl:when test="string($autonumber) != 0
931 and $number-and-title-template != 0
932 and $xref.with.number.and.title != 0">
933 <xsl:value-of select="'xref-number-and-title'"/>
935 <xsl:when test="string($autonumber) != 0
936 and $number-template != 0">
937 <xsl:value-of select="'xref-number'"/>
940 <xsl:value-of select="'xref'"/>
945 <xsl:variable name="template">
946 <xsl:call-template name="gentext.template">
947 <xsl:with-param name="context" select="$context"/>
948 <xsl:with-param name="name" select="$target.elem"/>
949 <xsl:with-param name="lang" select="$lang"/>
953 <xsl:call-template name="substitute-markup">
954 <xsl:with-param name="template" select="$template"/>
955 <xsl:with-param name="title">
956 <xsl:for-each select="$target.database" >
957 <xsl:call-template name="insert.targetdb.data">
958 <xsl:with-param name="data"
959 select="key('targetptr-key', $olink.key)[1]/ttl/node()" />
963 <xsl:with-param name="label">
964 <xsl:for-each select="$target.database" >
965 <xsl:call-template name="insert.targetdb.data">
966 <xsl:with-param name="data"
967 select="key('targetptr-key', $olink.key)[1]/@number" />
973 <xsl:when test="$xref.text !=''">
974 <xsl:copy-of select="$xref.text"/>
978 <xsl:text>Olink error: no generated text for </xsl:text>
979 <xsl:text>targetdoc/targetptr/lang = '</xsl:text>
980 <xsl:value-of select="$olink.key"/>
981 <xsl:text>'.</xsl:text>
983 <xsl:text>????</xsl:text>
987 <xsl:when test="@targetdoc != '' or @targetptr != ''">
988 <xsl:if test="$olink.key != ''">
990 <xsl:text>Olink error: no generated text for </xsl:text>
991 <xsl:text>targetdoc/targetptr/lang = '</xsl:text>
992 <xsl:value-of select="$olink.key"/>
993 <xsl:text>'.</xsl:text>
996 <xsl:text>????</xsl:text>
999 <!-- old style olink -->
1000 <xsl:call-template name="olink.outline">
1001 <xsl:with-param name="outline.base.uri"
1002 select="unparsed-entity-uri(@targetdocent)"/>
1003 <xsl:with-param name="localinfo" select="@localinfo"/>
1004 <xsl:with-param name="return" select="'xreftext'"/>
1005 </xsl:call-template>
1010 <xsl:template name="insert.targetdb.data">
1011 <xsl:param name="data"/>
1012 <!-- Customize this to massage data further -->
1013 <xsl:copy-of select="$data"/>
1016 <xsl:template match="*" mode="olink.docname.markup">
1017 <!-- No-op for now -->
1020 <xsl:template name="targetpath">
1021 <xsl:param name="dirnode" />
1022 <xsl:param name="targetdoc" select="''"/>
1025 <xsl:message>dirnode is <xsl:value-of select="$dirnode/@name"/></xsl:message>
1026 <xsl:message>targetdoc is <xsl:value-of select="$targetdoc"/></xsl:message>
1028 <!-- recursive template generates path to olink target directory -->
1030 <!-- Have we arrived at the final path step? -->
1031 <xsl:when test="$dirnode/child::document[@targetdoc = $targetdoc]">
1032 <!-- We are done -->
1034 <!-- Have we reached the top without a match? -->
1035 <xsl:when test="local-name($dirnode) != 'dir'" >
1036 <xsl:message>Olink error: cannot locate targetdoc <xsl:value-of select="$targetdoc"/> in sitemap</xsl:message>
1038 <!-- Is the target in a descendant? -->
1039 <xsl:when test="$dirnode/descendant::document/@targetdoc = $targetdoc">
1040 <xsl:variable name="step" select="$dirnode/child::dir[descendant::document/@targetdoc = $targetdoc]"/>
1041 <xsl:if test = "$step">
1042 <xsl:value-of select="$step/@name"/>
1043 <xsl:text>/</xsl:text>
1045 <!-- Now recurse with the child -->
1046 <xsl:call-template name="targetpath" >
1047 <xsl:with-param name="dirnode" select="$step"/>
1048 <xsl:with-param name="targetdoc" select="$targetdoc"/>
1049 </xsl:call-template>
1051 <!-- Otherwise we need to move up a step -->
1053 <xsl:if test="$dirnode/parent::dir">
1054 <xsl:text>../</xsl:text>
1056 <xsl:call-template name="targetpath" >
1057 <xsl:with-param name="dirnode" select="$dirnode/parent::*"/>
1058 <xsl:with-param name="targetdoc" select="$targetdoc"/>
1059 </xsl:call-template>
1064 <xsl:template name="olink.page.citation">
1065 <xsl:param name="olink.key" select="''"/>
1066 <xsl:param name="olink.lang" select="'en'"/>
1067 <xsl:param name="target.database"/>
1068 <xsl:param name="linkend" select="''"/>
1069 <xsl:param name="xrefstyle">
1071 <xsl:when test="@role and not(@xrefstyle)
1072 and $use.role.as.xrefstyle != 0">
1073 <xsl:value-of select="@role"/>
1076 <xsl:value-of select="@xrefstyle"/>
1081 <xsl:variable name="targetdoc">
1082 <xsl:value-of select="substring-before($olink.key, '/')"/>
1086 <xsl:when test="$linkend != ''">
1087 <xsl:call-template name="xref.page.citation">
1088 <xsl:with-param name="linkend" select="$linkend"/>
1089 <xsl:with-param name="target" select="key('id', $linkend)"/>
1090 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
1091 </xsl:call-template>
1093 <xsl:when test="not(starts-with(normalize-space($xrefstyle),
1095 and (contains($xrefstyle, 'page')
1096 or contains($xrefstyle, 'Page')))
1097 and $current.docid != ''
1098 and $current.docid != $targetdoc
1099 and $insert.olink.page.number = 'yes' ">
1101 <xsl:variable name="page-number">
1102 <xsl:for-each select="$target.database" >
1104 select="key('targetptr-key', $olink.key)[1]/@page" />
1108 <xsl:if test="$page-number != ''">
1109 <xsl:call-template name="substitute-markup">
1110 <xsl:with-param name="template">
1111 <xsl:call-template name="gentext.template">
1112 <xsl:with-param name="name" select="'olink.page.citation'"/>
1113 <xsl:with-param name="context" select="'xref'"/>
1114 <xsl:with-param name="lang" select="$olink.lang"/>
1115 </xsl:call-template>
1117 <xsl:with-param name="pagenumber" select="$page-number"/>
1118 </xsl:call-template>
1125 <xsl:template name="olink.document.citation">
1126 <xsl:param name="olink.key" select="''"/>
1127 <xsl:param name="olink.lang" select="'en'"/>
1128 <xsl:param name="target.database"/>
1129 <xsl:param name="xrefstyle">
1131 <xsl:when test="@role and not(@xrefstyle)
1132 and $use.role.as.xrefstyle != 0">
1133 <xsl:value-of select="@role"/>
1136 <xsl:value-of select="@xrefstyle"/>
1141 <xsl:variable name="page">
1142 <xsl:for-each select="$target.database" >
1144 select="key('targetptr-key', $olink.key)[1]/@page" />
1148 <xsl:variable name="targetdoc">
1149 <xsl:value-of select="substring-before($olink.key, '/')"/>
1152 <xsl:variable name="targetptr">
1154 select="substring-before(substring-after($olink.key, '/'), '/')"/>
1157 <!-- Don't add docname if pointing to root element -->
1158 <xsl:variable name="rootptr">
1159 <xsl:for-each select="$target.database" >
1161 select="key('targetdoc-key', $targetdoc)[1]/div[1]/@targetptr" />
1165 <xsl:variable name="docname">
1166 <xsl:for-each select="$target.database" >
1167 <xsl:call-template name="insert.targetdb.data">
1168 <xsl:with-param name="data"
1169 select="key('targetdoc-key', $targetdoc)[1]/div[1]/ttl/node()" />
1170 </xsl:call-template>
1174 <xsl:if test="not(starts-with(normalize-space($xrefstyle), 'select:')
1175 and (contains($xrefstyle, 'docname')))
1176 and ($olink.doctitle = 'yes' or $olink.doctitle = '1')
1177 and $current.docid != ''
1178 and $rootptr != $targetptr
1179 and $current.docid != $targetdoc
1180 and $docname != ''">
1181 <xsl:call-template name="substitute-markup">
1182 <xsl:with-param name="template">
1183 <xsl:call-template name="gentext.template">
1184 <xsl:with-param name="name" select="'olink.document.citation'"/>
1185 <xsl:with-param name="context" select="'xref'"/>
1186 <xsl:with-param name="lang" select="$olink.lang"/>
1187 </xsl:call-template>
1189 <xsl:with-param name="docname" select="$docname"/>
1190 <xsl:with-param name="pagenumber" select="$page"/>
1191 </xsl:call-template>
1195 <xsl:template name="xref.page.citation">
1196 <!-- Determine if this xref should have a page citation.
1197 Context node is the xref or local olink element -->
1198 <xsl:param name="linkend" select="@linkend"/>
1199 <xsl:param name="target" select="key('id', $linkend)"/>
1200 <xsl:param name="xrefstyle">
1202 <xsl:when test="@role and not(@xrefstyle)
1203 and $use.role.as.xrefstyle != 0">
1204 <xsl:value-of select="@role"/>
1207 <xsl:value-of select="@xrefstyle"/>
1212 <xsl:if test="not(starts-with(normalize-space($xrefstyle),'select:')
1213 and (contains($xrefstyle, 'page')
1214 or contains($xrefstyle, 'Page')))
1215 and ( $insert.xref.page.number = 'yes'
1216 or $insert.xref.page.number = '1')
1217 or local-name($target) = 'para'">
1218 <xsl:apply-templates select="$target" mode="page.citation">
1219 <xsl:with-param name="id" select="$linkend"/>
1220 </xsl:apply-templates>