2 <xsl:stylesheet xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform"
5 <!-- Create keys for quickly looking up olink targets -->
6 <xsl:key name=
"targetdoc-key" match=
"document" use=
"@targetdoc" />
7 <xsl:key name=
"targetptr-key" match=
"div|obj"
8 use=
"concat(ancestor::document/@targetdoc, '/',
9 @targetptr, '/', ancestor::document/@lang)" />
11 <!-- Return filename of database -->
12 <xsl:template name=
"select.target.database">
13 <xsl:param name=
"targetdoc.att" select=
"''"/>
14 <xsl:param name=
"targetptr.att" select=
"''"/>
15 <xsl:param name=
"olink.lang" select=
"''"/>
17 <!-- use root's xml:base if exists -->
18 <xsl:variable name=
"xml.base" select=
"/*/@xml:base"/>
20 <!-- This selection can be customized if needed -->
21 <xsl:variable name=
"target.database.filename">
23 <xsl:when test=
"$xml.base != '' and
24 not(starts-with($target.database.document, 'file:/')) and
25 not(starts-with($target.database.document, '/'))">
26 <xsl:call-template name=
"systemIdToBaseURI">
27 <xsl:with-param name=
"systemId" select=
"$xml.base"/>
29 <xsl:value-of select=
"$target.database.document"/>
32 <xsl:value-of select=
"$target.database.document"/>
37 <xsl:variable name=
"target.database"
38 select=
"document($target.database.filename,/)"/>
41 <!-- Was the database document parameter not set? -->
42 <xsl:when test=
"$target.database.document = ''">
44 <xsl:text>Olinks not processed: must specify a
</xsl:text>
45 <xsl:text>$target.database.document parameter
</xsl:text>
46 <xsl:text>when using olinks with targetdoc
</xsl:text>
47 <xsl:text>and targetptr attributes.
</xsl:text>
50 <!-- Did it not open? Should be a targetset element -->
51 <xsl:when test=
"not($target.database/*)">
53 <xsl:text>Olink error: could not open target database '
</xsl:text>
54 <xsl:value-of select=
"$target.database.filename"/>
55 <xsl:text>'.
</xsl:text>
59 <xsl:value-of select=
"$target.database.filename"/>
64 <xsl:template name=
"select.olink.key">
65 <xsl:param name=
"targetdoc.att" select=
"''"/>
66 <xsl:param name=
"targetptr.att" select=
"''"/>
67 <xsl:param name=
"olink.lang" select=
"''"/>
68 <xsl:param name=
"target.database"/>
70 <xsl:if test=
"$target.database/*">
71 <xsl:variable name=
"olink.fallback.sequence">
72 <xsl:call-template name=
"select.olink.lang.fallback">
73 <xsl:with-param name=
"olink.lang" select=
"$olink.lang"/>
77 <!-- Recurse through the languages until you find a match -->
78 <xsl:call-template name=
"select.olink.key.in.lang">
79 <xsl:with-param name=
"targetdoc.att" select=
"$targetdoc.att"/>
80 <xsl:with-param name=
"targetptr.att" select=
"$targetptr.att"/>
81 <xsl:with-param name=
"olink.lang" select=
"$olink.lang"/>
82 <xsl:with-param name=
"target.database" select=
"$target.database"/>
83 <xsl:with-param name=
"fallback.index" select=
"1"/>
84 <xsl:with-param name=
"olink.fallback.sequence"
85 select=
"$olink.fallback.sequence"/>
91 <!-- Locate olink key in a particular language -->
92 <xsl:template name=
"select.olink.key.in.lang">
93 <xsl:param name=
"targetdoc.att" select=
"''"/>
94 <xsl:param name=
"targetptr.att" select=
"''"/>
95 <xsl:param name=
"olink.lang" select=
"''"/>
96 <xsl:param name=
"target.database"/>
97 <xsl:param name=
"fallback.index" select=
"1"/>
98 <xsl:param name=
"olink.fallback.sequence" select=
"''"/>
100 <xsl:variable name=
"target.lang">
101 <xsl:call-template name=
"select.target.lang">
102 <xsl:with-param name=
"fallback.index" select=
"$fallback.index"/>
103 <xsl:with-param name=
"olink.fallback.sequence"
104 select=
"$olink.fallback.sequence"/>
108 <xsl:if test=
"$olink.debug != 0">
109 <xsl:message><xsl:text>Olink debug: cases for targetdoc='
</xsl:text>
110 <xsl:value-of select=
"$targetdoc.att"/>
111 <xsl:text>' and targetptr='
</xsl:text>
112 <xsl:value-of select=
"$targetptr.att"/>
113 <xsl:text>' in language '
</xsl:text>
114 <xsl:value-of select=
"$target.lang"/>
115 <xsl:text>'.
</xsl:text>
119 <!-- Customize these cases if you want different selection logic -->
120 <xsl:variable name=
"CaseA">
121 <!-- targetdoc.att = not blank
122 targetptr.att = not blank
124 <xsl:if test=
"$targetdoc.att != '' and
125 $targetptr.att != ''">
126 <xsl:for-each select=
"$target.database">
127 <xsl:variable name=
"key"
128 select=
"concat($targetdoc.att, '/',
132 <xsl:when test=
"key('targetptr-key', $key)/@href != ''">
133 <xsl:value-of select=
"$key"/>
134 <xsl:if test=
"$olink.debug != 0">
135 <xsl:message>Olink debug: CaseA matched.
</xsl:message>
138 <xsl:when test=
"$olink.debug != 0">
139 <xsl:message>Olink debug: CaseA NOT matched
</xsl:message>
146 <xsl:variable name=
"CaseB">
147 <!-- targetdoc.att = not blank
148 targetptr.att = not blank
149 prefer.internal.olink = not zero
150 current.docid = not blank
152 <xsl:if test=
"$targetdoc.att != '' and
153 $targetptr.att != '' and
154 $current.docid != '' and
155 $prefer.internal.olink != 0">
156 <xsl:for-each select=
"$target.database">
157 <xsl:variable name=
"key"
158 select=
"concat($current.docid, '/',
162 <xsl:when test=
"key('targetptr-key', $key)/@href != ''">
163 <xsl:value-of select=
"$key"/>
164 <xsl:if test=
"$olink.debug != 0">
165 <xsl:message>Olink debug: CaseB matched.
</xsl:message>
168 <xsl:when test=
"$olink.debug != 0">
169 <xsl:message>Olink debug: CaseB NOT matched
</xsl:message>
176 <xsl:variable name=
"CaseC">
177 <!-- targetdoc.att = blank
178 targetptr.att = not blank
179 current.docid = not blank
181 <xsl:if test=
"string-length($targetdoc.att) = 0 and
182 $targetptr.att != '' and
183 $current.docid != ''">
184 <!-- Must use a for-each to change context for keys to work -->
185 <xsl:for-each select=
"$target.database">
186 <xsl:variable name=
"key"
187 select=
"concat($current.docid, '/',
191 <xsl:when test=
"key('targetptr-key', $key)/@href != ''">
192 <xsl:value-of select=
"$key"/>
193 <xsl:if test=
"$olink.debug != 0">
194 <xsl:message>Olink debug: CaseC matched.
</xsl:message>
197 <xsl:when test=
"$olink.debug != 0">
198 <xsl:message>Olink debug: CaseC NOT matched.
</xsl:message>
205 <xsl:variable name=
"CaseD">
206 <!-- targetdoc.att = blank
207 targetptr.att = not blank
208 current.docid = blank
210 <!-- This is possible if only one document in the database -->
211 <xsl:if test=
"string-length($targetdoc.att) = 0 and
212 $targetptr.att != '' and
213 string-length($current.docid) = 0 and
214 count($target.database//document) = 1">
215 <xsl:for-each select=
"$target.database">
216 <xsl:variable name=
"key"
217 select=
"concat(.//document/@targetdoc, '/',
221 <xsl:when test=
"key('targetptr-key', $key)/@href != ''">
222 <xsl:value-of select=
"$key"/>
223 <xsl:if test=
"$olink.debug != 0">
224 <xsl:message>Olink debug: CaseD matched.
</xsl:message>
227 <xsl:when test=
"$olink.debug != 0">
228 <xsl:message>Olink debug: CaseD NOT matched
</xsl:message>
235 <xsl:variable name=
"CaseE">
236 <!-- targetdoc.att = not blank
237 targetptr.att = blank
239 <xsl:if test=
"$targetdoc.att != '' and
240 string-length($targetptr.att) = 0">
242 <!-- Try the document's root element id -->
243 <xsl:variable name=
"rootid">
245 <xsl:when test=
"$target.lang != ''">
246 <xsl:value-of select=
"$target.database//document[@targetdoc = $targetdoc.att and @lang = $target.lang]/*[1]/@targetptr"/>
249 <xsl:value-of select=
"$target.database//document[@targetdoc = $targetdoc.att and not(@lang)]/*[1]/@targetptr"/>
254 <xsl:for-each select=
"$target.database">
255 <xsl:variable name=
"key"
256 select=
"concat($targetdoc.att, '/',
260 <xsl:when test=
"key('targetptr-key', $key)/@href != ''">
261 <xsl:value-of select=
"$key"/>
262 <xsl:if test=
"$olink.debug != 0">
263 <xsl:message>Olink debug: CaseE matched.
</xsl:message>
266 <xsl:when test=
"$olink.debug != 0">
267 <xsl:message>Olink debug: CaseE NOT matched.
</xsl:message>
274 <xsl:variable name=
"CaseF">
275 <!-- targetdoc.att = not blank
276 targetptr.att = blank
277 prefer.internal.olink = not zero
278 current.docid = not blank
280 <xsl:if test=
"$targetdoc.att != '' and
281 string-length($targetptr.att) = 0 and
282 $current.docid != '' and
283 $prefer.internal.olink != 0">
284 <!-- Try the document's root element id -->
285 <xsl:variable name=
"rootid">
287 <xsl:when test=
"$target.lang != ''">
288 <xsl:value-of select=
"$target.database//document[@targetdoc = $current.docid and @lang = $target.lang]/*[1]/@targetptr"/>
291 <xsl:value-of select=
"$target.database//document[@targetdoc = $current.docid and not(@lang)]/*[1]/@targetptr"/>
296 <xsl:for-each select=
"$target.database">
297 <xsl:variable name=
"key"
298 select=
"concat($current.docid, '/',
302 <xsl:when test=
"key('targetptr-key', $key)/@href != ''">
303 <xsl:value-of select=
"$key"/>
304 <xsl:if test=
"$olink.debug != 0">
305 <xsl:message>Olink debug: CaseF matched.
</xsl:message>
308 <xsl:when test=
"$olink.debug != 0">
309 <xsl:message>Olink debug: CaseF NOT matched.
</xsl:message>
316 <!-- Now select the best match. Customize the order if needed -->
317 <xsl:variable name=
"selected.key">
319 <xsl:when test=
"$CaseB != ''">
320 <xsl:value-of select=
"$CaseB"/>
321 <xsl:if test=
"$olink.debug != 0">
323 <xsl:text>Olink debug: CaseB key is the final selection:
</xsl:text>
324 <xsl:value-of select=
"$CaseB"/>
328 <xsl:when test=
"$CaseA != ''">
329 <xsl:value-of select=
"$CaseA"/>
330 <xsl:if test=
"$olink.debug != 0">
332 <xsl:text>Olink debug: CaseA key is the final selection:
</xsl:text>
333 <xsl:value-of select=
"$CaseA"/>
337 <xsl:when test=
"$CaseC != ''">
338 <xsl:value-of select=
"$CaseC"/>
339 <xsl:if test=
"$olink.debug != 0">
341 <xsl:text>Olink debug: CaseC key is the final selection:
</xsl:text>
342 <xsl:value-of select=
"$CaseC"/>
346 <xsl:when test=
"$CaseD != ''">
347 <xsl:value-of select=
"$CaseD"/>
348 <xsl:if test=
"$olink.debug != 0">
350 <xsl:text>Olink debug: CaseD key is the final selection:
</xsl:text>
351 <xsl:value-of select=
"$CaseD"/>
355 <xsl:when test=
"$CaseF != ''">
356 <xsl:value-of select=
"$CaseF"/>
357 <xsl:if test=
"$olink.debug != 0">
359 <xsl:text>Olink debug: CaseF key is the final selection:
</xsl:text>
360 <xsl:value-of select=
"$CaseF"/>
364 <xsl:when test=
"$CaseE != ''">
365 <xsl:value-of select=
"$CaseE"/>
366 <xsl:if test=
"$olink.debug != 0">
368 <xsl:text>Olink debug: CaseE key is the final selection:
</xsl:text>
369 <xsl:value-of select=
"$CaseE"/>
374 <xsl:if test=
"$olink.debug != 0">
376 <xsl:text>Olink debug: No case matched for lang '
</xsl:text>
377 <xsl:value-of select=
"$target.lang"/>
378 <xsl:text>'.
</xsl:text>
386 <xsl:when test=
"$selected.key != ''">
387 <xsl:value-of select=
"$selected.key"/>
389 <xsl:when test=
"string-length($selected.key) = 0 and
390 string-length($target.lang) = 0">
391 <!-- No match on last try, and we are done -->
394 <!-- Recurse through next language -->
395 <xsl:call-template name=
"select.olink.key.in.lang">
396 <xsl:with-param name=
"targetdoc.att" select=
"$targetdoc.att"/>
397 <xsl:with-param name=
"targetptr.att" select=
"$targetptr.att"/>
398 <xsl:with-param name=
"olink.lang" select=
"$olink.lang"/>
399 <xsl:with-param name=
"target.database" select=
"$target.database"/>
400 <xsl:with-param name=
"fallback.index" select=
"$fallback.index + 1"/>
401 <xsl:with-param name=
"olink.fallback.sequence"
402 select=
"$olink.fallback.sequence"/>
409 <xsl:template name=
"select.target.lang">
410 <xsl:param name=
"fallback.index" select=
"1"/>
411 <xsl:param name=
"olink.fallback.sequence" select=
"''"/>
413 <!-- recurse backwards to find the lang matching the index -->
414 <xsl:variable name=
"firstlang"
415 select=
"substring-before($olink.fallback.sequence, ' ')"/>
416 <xsl:variable name=
"rest"
417 select=
"substring-after($olink.fallback.sequence, ' ')"/>
419 <xsl:when test=
"$fallback.index = 1">
420 <xsl:value-of select=
"$firstlang"/>
422 <xsl:when test=
"$fallback.index > 1">
423 <xsl:call-template name=
"select.target.lang">
424 <xsl:with-param name=
"fallback.index" select=
"$fallback.index - 1"/>
425 <xsl:with-param name=
"olink.fallback.sequence"
434 <xsl:template name=
"select.olink.lang.fallback">
435 <xsl:param name=
"olink.lang" select=
"''"/>
437 <!-- Prefer language of the olink element -->
438 <xsl:value-of select=
"concat(normalize-space(concat($olink.lang, ' ',
439 $olink.lang.fallback.sequence)), ' ')"/>
442 <!-- Returns the complete olink href value if found -->
443 <xsl:template name=
"make.olink.href">
444 <xsl:param name=
"olink.key" select=
"''"/>
445 <xsl:param name=
"target.database"/>
447 <xsl:if test=
"$olink.key != ''">
448 <xsl:variable name=
"target.href" >
449 <xsl:for-each select=
"$target.database" >
450 <xsl:value-of select=
"key('targetptr-key', $olink.key)/@href" />
454 <xsl:variable name=
"targetdoc">
455 <xsl:value-of select=
"substring-before($olink.key, '/')"/>
458 <!-- Does the target database use a sitemap? -->
459 <xsl:variable name=
"use.sitemap">
461 <xsl:when test=
"$target.database//sitemap">1</xsl:when>
462 <xsl:otherwise>0</xsl:otherwise>
467 <!-- Get the baseuri for this targetptr -->
468 <xsl:variable name=
"baseuri" >
470 <!-- Does the database use a sitemap? -->
471 <xsl:when test=
"$use.sitemap != 0" >
473 <!-- Was current.docid parameter set? -->
474 <xsl:when test=
"$current.docid != ''">
475 <!-- Was it found in the database? -->
476 <xsl:variable name=
"currentdoc.key" >
477 <xsl:for-each select=
"$target.database" >
478 <xsl:value-of select=
"key('targetdoc-key',
479 $current.docid)/@targetdoc" />
483 <xsl:when test=
"$currentdoc.key != ''">
484 <xsl:for-each select=
"$target.database" >
485 <xsl:call-template name=
"targetpath" >
486 <xsl:with-param name=
"dirnode"
487 select=
"key('targetdoc-key', $current.docid)/parent::dir"/>
488 <xsl:with-param name=
"targetdoc" select=
"$targetdoc"/>
494 <xsl:text>Olink error: cannot compute relative
</xsl:text>
495 <xsl:text>sitemap path because $current.docid '
</xsl:text>
496 <xsl:value-of select=
"$current.docid"/>
497 <xsl:text>' not found in target database.
</xsl:text>
504 <xsl:text>Olink warning: cannot compute relative
</xsl:text>
505 <xsl:text>sitemap path without $current.docid parameter
</xsl:text>
509 <!-- In either case, add baseuri from its document entry-->
510 <xsl:variable name=
"docbaseuri">
511 <xsl:for-each select=
"$target.database" >
512 <xsl:value-of select=
"key('targetdoc-key', $targetdoc)/@baseuri" />
515 <xsl:if test=
"$docbaseuri != ''" >
516 <xsl:value-of select=
"$docbaseuri"/>
519 <!-- No database sitemap in use -->
521 <!-- Just use any baseuri from its document entry -->
522 <xsl:variable name=
"docbaseuri">
523 <xsl:for-each select=
"$target.database" >
524 <xsl:value-of select=
"key('targetdoc-key', $targetdoc)/@baseuri" />
527 <xsl:if test=
"$docbaseuri != ''" >
528 <xsl:value-of select=
"$docbaseuri"/>
534 <!-- Form the href information -->
535 <xsl:if test=
"$baseuri != ''">
536 <xsl:value-of select=
"$baseuri"/>
537 <xsl:if test=
"substring($target.href,1,1) != '#'">
538 <!--xsl:text>/</xsl:text-->
541 <!-- optionally turn off frag for PDF references -->
542 <xsl:if test=
"not($insert.olink.pdf.frag = 0 and
543 translate(substring($baseuri, string-length($baseuri) - 3),
544 'PDF', 'pdf') = '.pdf'
545 and starts-with($target.href, '#') )">
546 <xsl:value-of select=
"$target.href"/>
551 <!-- Computes the href of the object containing the olink element -->
552 <xsl:template name=
"olink.from.uri">
553 <xsl:param name=
"target.database"/>
554 <xsl:param name=
"object" select=
"NotAnElement"/>
555 <xsl:param name=
"object.targetdoc" select=
"$current.docid"/>
556 <xsl:param name=
"object.lang"
557 select=
"concat($object/ancestor::*[last()]/@lang,
558 $object/ancestor::*[last()]/@xml:lang)"/>
560 <xsl:variable name=
"parent.id">
561 <xsl:call-template name=
"object.id">
562 <xsl:with-param name=
"object" select=
"$object"/>
566 <!-- Get the olink key for the parent of olink element -->
567 <xsl:variable name=
"from.key">
568 <xsl:call-template name=
"select.olink.key">
569 <xsl:with-param name=
"targetdoc.att" select=
"$object.targetdoc"/>
570 <xsl:with-param name=
"targetptr.att" select=
"$parent.id"/>
571 <xsl:with-param name=
"olink.lang" select=
"$object.lang"/>
572 <xsl:with-param name=
"target.database" select=
"$target.database"/>
576 <xsl:variable name=
"from.olink.href">
577 <xsl:for-each select=
"$target.database" >
578 <xsl:value-of select=
"key('targetptr-key', $from.key)/@href" />
583 <!-- we found the olink object -->
584 <xsl:when test=
"$from.olink.href != ''">
585 <xsl:value-of select=
"$from.olink.href"/>
587 <xsl:when test=
"not($object/parent::*)">
588 <xsl:value-of select=
"$from.olink.href"/>
591 <!-- recurse upward in current document -->
592 <xsl:call-template name=
"olink.from.uri">
593 <xsl:with-param name=
"target.database" select=
"$target.database"/>
594 <xsl:with-param name=
"object" select=
"$object/parent::*"/>
595 <xsl:with-param name=
"object.targetdoc" select=
"$object.targetdoc"/>
596 <xsl:with-param name=
"object.lang" select=
"$object.lang"/>
603 <xsl:template name=
"olink.hottext">
604 <xsl:param name=
"target.database"/>
605 <xsl:param name=
"olink.lang" select=
"''"/>
606 <xsl:param name=
"olink.key" select=
"''"/>
607 <xsl:param name=
"referrer" select=
"."/>
608 <xsl:param name=
"xrefstyle">
610 <xsl:when test=
"@role and not(@xrefstyle)
611 and $use.role.as.xrefstyle != 0">
612 <xsl:value-of select=
"@role"/>
615 <xsl:value-of select=
"@xrefstyle"/>
621 <!-- If it has elements or text (not just PI or comment) -->
622 <xsl:when test=
"child::text() or child::*">
623 <xsl:apply-templates/>
625 <xsl:when test=
"$olink.key != ''">
626 <!-- Get the xref text for this record -->
627 <xsl:variable name=
"xref.text" >
628 <xsl:for-each select=
"$target.database" >
630 select=
"key('targetptr-key', $olink.key)/xreftext/node()" />
634 <xsl:variable name=
"xref.number" >
635 <xsl:for-each select=
"$target.database" >
636 <xsl:value-of select=
"key('targetptr-key', $olink.key)/@number" />
640 <xsl:variable name=
"target.elem" >
641 <xsl:for-each select=
"$target.database" >
642 <xsl:value-of select=
"key('targetptr-key', $olink.key)/@element" />
646 <xsl:variable name=
"lang">
647 <xsl:variable name=
"candidate">
648 <xsl:for-each select=
"$target.database" >
650 select=
"key('targetptr-key', $olink.key)/@lang" />
654 <xsl:when test=
"$candidate != ''">
655 <xsl:value-of select=
"$candidate"/>
658 <xsl:value-of select=
"$olink.lang"/>
663 <xsl:variable name=
"targetdoc">
664 <xsl:value-of select=
"substring-before($olink.key, '/')"/>
668 <xsl:when test=
"$xrefstyle != '' and
669 starts-with(normalize-space($xrefstyle), 'select:') and
670 (contains($xrefstyle, 'nodocname') or
671 contains($xrefstyle, 'nopage')) and
672 not(contains($xrefstyle, 'title')) and
673 not(contains($xrefstyle, 'label'))">
674 <xsl:copy-of select=
"$xref.text"/>
676 <xsl:when test=
"$xrefstyle != ''">
677 <xsl:if test=
"$olink.debug != 0">
679 <xsl:text>xrefstyle is '
</xsl:text>
680 <xsl:value-of select=
"$xrefstyle"/>
681 <xsl:text>'.
</xsl:text>
684 <xsl:variable name=
"template">
686 <xsl:when test=
"starts-with(normalize-space($xrefstyle),
688 <xsl:call-template name=
"make.gentext.template">
689 <xsl:with-param name=
"xrefstyle" select=
"$xrefstyle"/>
690 <xsl:with-param name=
"purpose" select=
"'olink'"/>
691 <xsl:with-param name=
"referrer" select=
"."/>
692 <xsl:with-param name=
"target.elem" select=
"$target.elem"/>
695 <xsl:when test=
"starts-with(normalize-space($xrefstyle),
697 <xsl:value-of select=
"substring-after(
698 normalize-space($xrefstyle), 'template:')"/>
701 <!-- Look for Gentext template with @style attribute -->
702 <!-- Must compare to no style value because gentext.template
703 falls back to no style -->
705 <xsl:variable name=
"xref-context">
706 <xsl:call-template name=
"gentext.template">
707 <xsl:with-param name=
"context" select=
"'xref'"/>
708 <xsl:with-param name=
"name" select=
"$target.elem"/>
709 <xsl:with-param name=
"lang" select=
"$lang"/>
713 <xsl:variable name=
"styled-xref-context">
714 <xsl:call-template name=
"gentext.template">
715 <xsl:with-param name=
"context" select=
"'xref'"/>
716 <xsl:with-param name=
"name" select=
"$target.elem"/>
717 <xsl:with-param name=
"lang" select=
"$lang"/>
718 <xsl:with-param name=
"xrefstyle" select=
"$xrefstyle"/>
722 <xsl:variable name=
"xref-number-context">
723 <xsl:call-template name=
"gentext.template">
724 <xsl:with-param name=
"context" select=
"'xref-number'"/>
725 <xsl:with-param name=
"name" select=
"$target.elem"/>
726 <xsl:with-param name=
"lang" select=
"$lang"/>
730 <xsl:variable name=
"styled-xref-number-context">
731 <xsl:call-template name=
"gentext.template">
732 <xsl:with-param name=
"context" select=
"'xref-number'"/>
733 <xsl:with-param name=
"name" select=
"$target.elem"/>
734 <xsl:with-param name=
"lang" select=
"$lang"/>
735 <xsl:with-param name=
"xrefstyle" select=
"$xrefstyle"/>
739 <xsl:variable name=
"xref-number-and-title-context">
740 <xsl:call-template name=
"gentext.template">
741 <xsl:with-param name=
"context"
742 select=
"'xref-number-and-title'"/>
743 <xsl:with-param name=
"name" select=
"$target.elem"/>
744 <xsl:with-param name=
"lang" select=
"$lang"/>
748 <xsl:variable name=
"styled-xref-number-and-title-context">
749 <xsl:call-template name=
"gentext.template">
750 <xsl:with-param name=
"context"
751 select=
"'xref-number-and-title'"/>
752 <xsl:with-param name=
"name" select=
"$target.elem"/>
753 <xsl:with-param name=
"lang" select=
"$lang"/>
754 <xsl:with-param name=
"xrefstyle" select=
"$xrefstyle"/>
759 <xsl:when test=
"$xref-number-and-title-context !=
760 $styled-xref-number-and-title-context and
761 $xref.number != '' and
762 $xref.with.number.and.title != 0">
764 select=
"$styled-xref-number-and-title-context"/>
766 <xsl:when test=
"$xref-number-context !=
767 $styled-xref-number-context and
769 <xsl:value-of select=
"$styled-xref-number-context"/>
771 <xsl:when test=
"$xref-context != $styled-xref-context">
772 <xsl:value-of select=
"$styled-xref-context"/>
774 <xsl:when test=
"$xref-number-and-title-context != '' and
775 $xref.number != '' and
776 $xref.with.number.and.title != 0">
778 select=
"$xref-number-and-title-context"/>
779 <xsl:if test=
"$olink.debug">
781 <xsl:text>Olink error: no gentext template
</xsl:text>
782 <xsl:text> exists for xrefstyle '
</xsl:text>
783 <xsl:value-of select=
"$xrefstyle"/>
784 <xsl:text>' for element '
</xsl:text>
785 <xsl:value-of select=
"$target.elem"/>
786 <xsl:text>' in language '
</xsl:text>
787 <xsl:value-of select=
"$lang"/>
788 <xsl:text>' in context 'xref-number-and-title
</xsl:text>
789 <xsl:text>'. Using template without @style.
</xsl:text>
793 <xsl:when test=
"$xref-number-context != '' and
795 <xsl:value-of select=
"$xref-number-context"/>
796 <xsl:if test=
"$olink.debug">
798 <xsl:text>Olink error: no gentext template
</xsl:text>
799 <xsl:text> exists for xrefstyle '
</xsl:text>
800 <xsl:value-of select=
"$xrefstyle"/>
801 <xsl:text>' for element '
</xsl:text>
802 <xsl:value-of select=
"$target.elem"/>
803 <xsl:text>' in language '
</xsl:text>
804 <xsl:value-of select=
"$lang"/>
805 <xsl:text>' in context 'xref-number
</xsl:text>
806 <xsl:text>'. Using template without @style.
</xsl:text>
810 <xsl:when test=
"$xref-context != ''">
811 <xsl:value-of select=
"$xref-context"/>
812 <xsl:if test=
"$olink.debug">
814 <xsl:text>Olink error: no gentext template
</xsl:text>
815 <xsl:text> exists for xrefstyle '
</xsl:text>
816 <xsl:value-of select=
"$xrefstyle"/>
817 <xsl:text>' for element '
</xsl:text>
818 <xsl:value-of select=
"$target.elem"/>
819 <xsl:text>' in language '
</xsl:text>
820 <xsl:value-of select=
"$lang"/>
821 <xsl:text>' in context 'xref
</xsl:text>
822 <xsl:text>'. Using template without @style.
</xsl:text>
828 <xsl:text>Olink error: no gentext template
</xsl:text>
829 <xsl:text> exists for xrefstyle '
</xsl:text>
830 <xsl:value-of select=
"$xrefstyle"/>
831 <xsl:text>' for element '
</xsl:text>
832 <xsl:value-of select=
"$target.elem"/>
833 <xsl:text>' in language '
</xsl:text>
834 <xsl:value-of select=
"$lang"/>
835 <xsl:text>'. Trying '%t'.
</xsl:text>
837 <xsl:value-of select=
"'%t'"/>
844 <xsl:if test=
"$olink.debug != 0">
846 <xsl:text>Olink debug: xrefstyle template is '
</xsl:text>
847 <xsl:value-of select=
"$template"/>
848 <xsl:text>'.
</xsl:text>
852 <xsl:call-template name=
"substitute-markup">
853 <xsl:with-param name=
"template" select=
"$template"/>
854 <xsl:with-param name=
"title">
855 <xsl:for-each select=
"$target.database" >
856 <xsl:value-of select=
"key('targetptr-key', $olink.key)/ttl" />
859 <xsl:with-param name=
"label">
860 <xsl:for-each select=
"$target.database" >
862 select=
"key('targetptr-key', $olink.key)/@number" />
865 <xsl:with-param name=
"pagenumber">
866 <xsl:for-each select=
"$target.database" >
868 select=
"key('targetptr-key', $olink.key)/@page" />
871 <xsl:with-param name=
"docname">
872 <xsl:for-each select=
"$target.database" >
874 select=
"key('targetdoc-key', $targetdoc)/div[1]/ttl" />
880 <xsl:when test=
"$use.local.olink.style != 0">
882 <xsl:variable name=
"template">
883 <xsl:call-template name=
"gentext.template">
884 <xsl:with-param name=
"context" select=
"'xref'"/>
885 <xsl:with-param name=
"name" select=
"$target.elem"/>
886 <xsl:with-param name=
"lang" select=
"$lang"/>
890 <xsl:call-template name=
"substitute-markup">
891 <xsl:with-param name=
"template" select=
"$template"/>
892 <xsl:with-param name=
"title">
893 <xsl:for-each select=
"$target.database" >
894 <xsl:value-of select=
"key('targetptr-key', $olink.key)/ttl" />
897 <xsl:with-param name=
"label">
898 <xsl:for-each select=
"$target.database" >
900 select=
"key('targetptr-key', $olink.key)/@number" />
905 <xsl:when test=
"$xref.text !=''">
906 <xsl:copy-of select=
"$xref.text"/>
910 <xsl:text>Olink error: no generated text for
</xsl:text>
911 <xsl:text>targetdoc/targetptr/lang = '
</xsl:text>
912 <xsl:value-of select=
"$olink.key"/>
913 <xsl:text>'.
</xsl:text>
915 <xsl:text>????
</xsl:text>
919 <xsl:when test=
"@targetdoc != '' or @targetptr != ''">
920 <xsl:if test=
"$olink.key != ''">
922 <xsl:text>Olink error: no generated text for
</xsl:text>
923 <xsl:text>targetdoc/targetptr/lang = '
</xsl:text>
924 <xsl:value-of select=
"$olink.key"/>
925 <xsl:text>'.
</xsl:text>
928 <xsl:text>????
</xsl:text>
931 <!-- old style olink -->
932 <xsl:call-template name=
"olink.outline">
933 <xsl:with-param name=
"outline.base.uri"
934 select=
"unparsed-entity-uri(@targetdocent)"/>
935 <xsl:with-param name=
"localinfo" select=
"@localinfo"/>
936 <xsl:with-param name=
"return" select=
"'xreftext'"/>
942 <xsl:template match=
"*" mode=
"olink.docname.markup">
943 <!-- No-op for now -->
946 <xsl:template name=
"targetpath">
947 <xsl:param name=
"dirnode" />
948 <xsl:param name=
"targetdoc" select=
"''"/>
951 <xsl:message>dirnode is <xsl:value-of select="$dirnode/@name"/></xsl:message>
952 <xsl:message>targetdoc is <xsl:value-of select="$targetdoc"/></xsl:message>
954 <!-- recursive template generates path to olink target directory -->
956 <!-- Have we arrived at the final path step? -->
957 <xsl:when test=
"$dirnode/child::document[@targetdoc = $targetdoc]">
960 <!-- Have we reached the top without a match? -->
961 <xsl:when test=
"local-name($dirnode) != 'dir'" >
962 <xsl:message>Olink error: cannot locate targetdoc
<xsl:value-of select=
"$targetdoc"/> in sitemap
</xsl:message>
964 <!-- Is the target in a descendant? -->
965 <xsl:when test=
"$dirnode/descendant::document/@targetdoc = $targetdoc">
966 <xsl:variable name=
"step" select=
"$dirnode/child::dir[descendant::document/@targetdoc = $targetdoc]"/>
967 <xsl:if test =
"$step">
968 <xsl:value-of select=
"$step/@name"/>
969 <xsl:text>/
</xsl:text>
971 <!-- Now recurse with the child -->
972 <xsl:call-template name=
"targetpath" >
973 <xsl:with-param name=
"dirnode" select=
"$step"/>
974 <xsl:with-param name=
"targetdoc" select=
"$targetdoc"/>
977 <!-- Otherwise we need to move up a step -->
979 <xsl:if test=
"$dirnode/parent::dir">
980 <xsl:text>../
</xsl:text>
982 <xsl:call-template name=
"targetpath" >
983 <xsl:with-param name=
"dirnode" select=
"$dirnode/parent::*"/>
984 <xsl:with-param name=
"targetdoc" select=
"$targetdoc"/>
990 <xsl:template name=
"olink.page.citation">
991 <xsl:param name=
"olink.key" select=
"''"/>
992 <xsl:param name=
"olink.lang" select=
"'en'"/>
993 <xsl:param name=
"target.database"/>
994 <xsl:param name=
"linkend" select=
"''"/>
995 <xsl:param name=
"xrefstyle">
997 <xsl:when test=
"@role and not(@xrefstyle)
998 and $use.role.as.xrefstyle != 0">
999 <xsl:value-of select=
"@role"/>
1002 <xsl:value-of select=
"@xrefstyle"/>
1007 <xsl:variable name=
"targetdoc">
1008 <xsl:value-of select=
"substring-before($olink.key, '/')"/>
1012 <xsl:when test=
"$linkend != ''">
1013 <xsl:call-template name=
"xref.page.citation">
1014 <xsl:with-param name=
"linkend" select=
"$linkend"/>
1015 <xsl:with-param name=
"target" select=
"key('id', $linkend)"/>
1016 <xsl:with-param name=
"xrefstyle" select=
"$xrefstyle"/>
1017 </xsl:call-template>
1019 <xsl:when test=
"not(starts-with(normalize-space($xrefstyle),
1021 and (contains($xrefstyle, 'page')
1022 or contains($xrefstyle, 'Page')))
1023 and $current.docid != ''
1024 and $current.docid != $targetdoc
1025 and $insert.olink.page.number = 'yes' ">
1027 <xsl:variable name=
"page-number">
1028 <xsl:for-each select=
"$target.database" >
1030 select=
"key('targetptr-key', $olink.key)/@page" />
1034 <xsl:if test=
"$page-number != ''">
1035 <xsl:call-template name=
"substitute-markup">
1036 <xsl:with-param name=
"template">
1037 <xsl:call-template name=
"gentext.template">
1038 <xsl:with-param name=
"name" select=
"'olink.page.citation'"/>
1039 <xsl:with-param name=
"context" select=
"'xref'"/>
1040 <xsl:with-param name=
"lang" select=
"$olink.lang"/>
1041 </xsl:call-template>
1043 <xsl:with-param name=
"pagenumber" select=
"$page-number"/>
1044 </xsl:call-template>
1051 <xsl:template name=
"olink.document.citation">
1052 <xsl:param name=
"olink.key" select=
"''"/>
1053 <xsl:param name=
"olink.lang" select=
"'en'"/>
1054 <xsl:param name=
"target.database"/>
1055 <xsl:param name=
"xrefstyle">
1057 <xsl:when test=
"@role and not(@xrefstyle)
1058 and $use.role.as.xrefstyle != 0">
1059 <xsl:value-of select=
"@role"/>
1062 <xsl:value-of select=
"@xrefstyle"/>
1067 <xsl:variable name=
"page">
1068 <xsl:for-each select=
"$target.database" >
1070 select=
"key('targetptr-key', $olink.key)/@page" />
1074 <xsl:variable name=
"targetdoc">
1075 <xsl:value-of select=
"substring-before($olink.key, '/')"/>
1078 <xsl:variable name=
"targetptr">
1080 select=
"substring-before(substring-after($olink.key, '/'), '/')"/>
1083 <!-- Don't add docname if pointing to root element -->
1084 <xsl:variable name=
"rootptr">
1085 <xsl:for-each select=
"$target.database" >
1087 select=
"key('targetdoc-key', $targetdoc)/div[1]/@targetptr" />
1091 <xsl:variable name=
"docname">
1092 <xsl:for-each select=
"$target.database" >
1094 select=
"key('targetdoc-key', $targetdoc)/div[1]/ttl" />
1098 <xsl:if test=
"not(starts-with(normalize-space($xrefstyle), 'select:')
1099 and (contains($xrefstyle, 'docname')))
1100 and ($olink.doctitle = 'yes' or $olink.doctitle = '1')
1101 and $current.docid != ''
1102 and $rootptr != $targetptr
1103 and $current.docid != $targetdoc
1104 and $docname != ''">
1105 <xsl:call-template name=
"substitute-markup">
1106 <xsl:with-param name=
"template">
1107 <xsl:call-template name=
"gentext.template">
1108 <xsl:with-param name=
"name" select=
"'olink.document.citation'"/>
1109 <xsl:with-param name=
"context" select=
"'xref'"/>
1110 <xsl:with-param name=
"lang" select=
"$olink.lang"/>
1111 </xsl:call-template>
1113 <xsl:with-param name=
"docname" select=
"$docname"/>
1114 <xsl:with-param name=
"pagenumber" select=
"$page"/>
1115 </xsl:call-template>
1119 <xsl:template name=
"xref.page.citation">
1120 <!-- Determine if this xref should have a page citation.
1121 Context node is the xref or local olink element -->
1122 <xsl:param name=
"linkend" select=
"@linkend"/>
1123 <xsl:param name=
"target" select=
"key('id', $linkend)"/>
1124 <xsl:param name=
"xrefstyle">
1126 <xsl:when test=
"@role and not(@xrefstyle)
1127 and $use.role.as.xrefstyle != 0">
1128 <xsl:value-of select=
"@role"/>
1131 <xsl:value-of select=
"@xrefstyle"/>
1136 <xsl:if test=
"not(starts-with(normalize-space($xrefstyle),'select:')
1137 and (contains($xrefstyle, 'page')
1138 or contains($xrefstyle, 'Page')))
1139 and ( $insert.xref.page.number = 'yes'
1140 or $insert.xref.page.number = '1')
1141 or local-name($target) = 'para'">
1142 <xsl:apply-templates select=
"$target" mode=
"page.citation">
1143 <xsl:with-param name=
"id" select=
"$linkend"/>
1144 </xsl:apply-templates>