source: stylesheets/lfs-xsl/docbook-xsl-snapshot/common/olink.xsl@ 410e228b

10.0 10.1 11.0 11.1 6.3 6.3-rc1 6.3-rc2 6.3-rc3 7.10 7.4 7.5 7.6 7.6-blfs 7.6-systemd 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 9.0 9.1 basic bdubbs/svn elogind gnome kde5-13430 kde5-14269 kde5-14686 krejzi/svn lazarus nosym perl-modules qt5new systemd-11177 systemd-13485 trunk upgradedb xry111/intltool xry111/test-20220226
Last change on this file since 410e228b was 410e228b, checked in by Randy McMurchy <randy@…>, 14 years ago

Removed extraneous whitespace from the ends of line text

git-svn-id: svn://svn.linuxfromscratch.org/BLFS/trunk/BOOK@7431 af4574ff-66df-0310-9fd7-8a98e5e911e0

  • Property mode set to 100644
File size: 44.9 KB
Line 
1<?xml version="1.0"?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 version="1.0">
4
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)" />
10
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="''"/>
16
17 <!-- use root's xml:base if exists -->
18 <xsl:variable name="xml.base" select="/*/@xml:base"/>
19
20 <!-- This selection can be customized if needed -->
21 <xsl:variable name="target.database.filename">
22 <xsl:choose>
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"/>
28 </xsl:call-template>
29 <xsl:value-of select="$target.database.document"/>
30 </xsl:when>
31 <xsl:otherwise>
32 <xsl:value-of select="$target.database.document"/>
33 </xsl:otherwise>
34 </xsl:choose>
35 </xsl:variable>
36
37 <xsl:variable name="target.database"
38 select="document($target.database.filename,/)"/>
39
40 <xsl:choose>
41 <!-- Was the database document parameter not set? -->
42 <xsl:when test="$target.database.document = ''">
43 <xsl:message>
44 <xsl:text>Olinks not processed: must specify a </xsl:text>
45 <xsl:text>$target.database.document parameter&#10;</xsl:text>
46 <xsl:text>when using olinks with targetdoc </xsl:text>
47 <xsl:text>and targetptr attributes.</xsl:text>
48 </xsl:message>
49 </xsl:when>
50 <!-- Did it not open? Should be a targetset element -->
51 <xsl:when test="not($target.database/*)">
52 <xsl:message>
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>
56 </xsl:message>
57 </xsl:when>
58 <xsl:otherwise>
59 <xsl:value-of select="$target.database.filename"/>
60 </xsl:otherwise>
61 </xsl:choose>
62</xsl:template>
63
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"/>
69
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"/>
74 </xsl:call-template>
75 </xsl:variable>
76
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"/>
86 </xsl:call-template>
87 </xsl:if>
88
89</xsl:template>
90
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="''"/>
99
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"/>
105 </xsl:call-template>
106 </xsl:variable>
107
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>
116 </xsl:message>
117 </xsl:if>
118
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
123 -->
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, '/',
129 $targetptr.att, '/',
130 $target.lang)"/>
131 <xsl:choose>
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>
136 </xsl:if>
137 </xsl:when>
138 <xsl:when test="$olink.debug != 0">
139 <xsl:message>Olink debug: CaseA NOT matched</xsl:message>
140 </xsl:when>
141 </xsl:choose>
142 </xsl:for-each>
143 </xsl:if>
144 </xsl:variable>
145
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
151 -->
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, '/',
159 $targetptr.att, '/',
160 $target.lang)"/>
161 <xsl:choose>
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>
166 </xsl:if>
167 </xsl:when>
168 <xsl:when test="$olink.debug != 0">
169 <xsl:message>Olink debug: CaseB NOT matched</xsl:message>
170 </xsl:when>
171 </xsl:choose>
172 </xsl:for-each>
173 </xsl:if>
174 </xsl:variable>
175
176 <xsl:variable name="CaseC">
177 <!-- targetdoc.att = blank
178 targetptr.att = not blank
179 current.docid = not blank
180 -->
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, '/',
188 $targetptr.att, '/',
189 $target.lang)"/>
190 <xsl:choose>
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>
195 </xsl:if>
196 </xsl:when>
197 <xsl:when test="$olink.debug != 0">
198 <xsl:message>Olink debug: CaseC NOT matched.</xsl:message>
199 </xsl:when>
200 </xsl:choose>
201 </xsl:for-each>
202 </xsl:if>
203 </xsl:variable>
204
205 <xsl:variable name="CaseD">
206 <!-- targetdoc.att = blank
207 targetptr.att = not blank
208 current.docid = blank
209 -->
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, '/',
218 $targetptr.att, '/',
219 $target.lang)"/>
220 <xsl:choose>
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>
225 </xsl:if>
226 </xsl:when>
227 <xsl:when test="$olink.debug != 0">
228 <xsl:message>Olink debug: CaseD NOT matched</xsl:message>
229 </xsl:when>
230 </xsl:choose>
231 </xsl:for-each>
232 </xsl:if>
233 </xsl:variable>
234
235 <xsl:variable name="CaseE">
236 <!-- targetdoc.att = not blank
237 targetptr.att = blank
238 -->
239 <xsl:if test="$targetdoc.att != '' and
240 string-length($targetptr.att) = 0">
241
242 <!-- Try the document's root element id -->
243 <xsl:variable name="rootid">
244 <xsl:choose>
245 <xsl:when test="$target.lang != ''">
246 <xsl:value-of select="$target.database//document[@targetdoc = $targetdoc.att and @lang = $target.lang]/*[1]/@targetptr"/>
247 </xsl:when>
248 <xsl:otherwise>
249 <xsl:value-of select="$target.database//document[@targetdoc = $targetdoc.att and not(@lang)]/*[1]/@targetptr"/>
250 </xsl:otherwise>
251 </xsl:choose>
252 </xsl:variable>
253
254 <xsl:for-each select="$target.database">
255 <xsl:variable name="key"
256 select="concat($targetdoc.att, '/',
257 $rootid, '/',
258 $target.lang)"/>
259 <xsl:choose>
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>
264 </xsl:if>
265 </xsl:when>
266 <xsl:when test="$olink.debug != 0">
267 <xsl:message>Olink debug: CaseE NOT matched.</xsl:message>
268 </xsl:when>
269 </xsl:choose>
270 </xsl:for-each>
271 </xsl:if>
272 </xsl:variable>
273
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
279 -->
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">
286 <xsl:choose>
287 <xsl:when test="$target.lang != ''">
288 <xsl:value-of select="$target.database//document[@targetdoc = $current.docid and @lang = $target.lang]/*[1]/@targetptr"/>
289 </xsl:when>
290 <xsl:otherwise>
291 <xsl:value-of select="$target.database//document[@targetdoc = $current.docid and not(@lang)]/*[1]/@targetptr"/>
292 </xsl:otherwise>
293 </xsl:choose>
294 </xsl:variable>
295
296 <xsl:for-each select="$target.database">
297 <xsl:variable name="key"
298 select="concat($current.docid, '/',
299 $rootid, '/',
300 $target.lang)"/>
301 <xsl:choose>
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>
306 </xsl:if>
307 </xsl:when>
308 <xsl:when test="$olink.debug != 0">
309 <xsl:message>Olink debug: CaseF NOT matched.</xsl:message>
310 </xsl:when>
311 </xsl:choose>
312 </xsl:for-each>
313 </xsl:if>
314 </xsl:variable>
315
316 <!-- Now select the best match. Customize the order if needed -->
317 <xsl:variable name="selected.key">
318 <xsl:choose>
319 <xsl:when test="$CaseB != ''">
320 <xsl:value-of select="$CaseB"/>
321 <xsl:if test="$olink.debug != 0">
322 <xsl:message>
323 <xsl:text>Olink debug: CaseB key is the final selection: </xsl:text>
324 <xsl:value-of select="$CaseB"/>
325 </xsl:message>
326 </xsl:if>
327 </xsl:when>
328 <xsl:when test="$CaseA != ''">
329 <xsl:value-of select="$CaseA"/>
330 <xsl:if test="$olink.debug != 0">
331 <xsl:message>
332 <xsl:text>Olink debug: CaseA key is the final selection: </xsl:text>
333 <xsl:value-of select="$CaseA"/>
334 </xsl:message>
335 </xsl:if>
336 </xsl:when>
337 <xsl:when test="$CaseC != ''">
338 <xsl:value-of select="$CaseC"/>
339 <xsl:if test="$olink.debug != 0">
340 <xsl:message>
341 <xsl:text>Olink debug: CaseC key is the final selection: </xsl:text>
342 <xsl:value-of select="$CaseC"/>
343 </xsl:message>
344 </xsl:if>
345 </xsl:when>
346 <xsl:when test="$CaseD != ''">
347 <xsl:value-of select="$CaseD"/>
348 <xsl:if test="$olink.debug != 0">
349 <xsl:message>
350 <xsl:text>Olink debug: CaseD key is the final selection: </xsl:text>
351 <xsl:value-of select="$CaseD"/>
352 </xsl:message>
353 </xsl:if>
354 </xsl:when>
355 <xsl:when test="$CaseF != ''">
356 <xsl:value-of select="$CaseF"/>
357 <xsl:if test="$olink.debug != 0">
358 <xsl:message>
359 <xsl:text>Olink debug: CaseF key is the final selection: </xsl:text>
360 <xsl:value-of select="$CaseF"/>
361 </xsl:message>
362 </xsl:if>
363 </xsl:when>
364 <xsl:when test="$CaseE != ''">
365 <xsl:value-of select="$CaseE"/>
366 <xsl:if test="$olink.debug != 0">
367 <xsl:message>
368 <xsl:text>Olink debug: CaseE key is the final selection: </xsl:text>
369 <xsl:value-of select="$CaseE"/>
370 </xsl:message>
371 </xsl:if>
372 </xsl:when>
373 <xsl:otherwise>
374 <xsl:if test="$olink.debug != 0">
375 <xsl:message>
376 <xsl:text>Olink debug: No case matched for lang '</xsl:text>
377 <xsl:value-of select="$target.lang"/>
378 <xsl:text>'.</xsl:text>
379 </xsl:message>
380 </xsl:if>
381 </xsl:otherwise>
382 </xsl:choose>
383 </xsl:variable>
384
385 <xsl:choose>
386 <xsl:when test="$selected.key != ''">
387 <xsl:value-of select="$selected.key"/>
388 </xsl:when>
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 -->
392 </xsl:when>
393 <xsl:otherwise>
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"/>
403 </xsl:call-template>
404 </xsl:otherwise>
405 </xsl:choose>
406
407</xsl:template>
408
409<xsl:template name="select.target.lang">
410 <xsl:param name="fallback.index" select="1"/>
411 <xsl:param name="olink.fallback.sequence" select="''"/>
412
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, ' ')"/>
418 <xsl:choose>
419 <xsl:when test="$fallback.index = 1">
420 <xsl:value-of select="$firstlang"/>
421 </xsl:when>
422 <xsl:when test="$fallback.index &gt; 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"
426 select="$rest"/>
427 </xsl:call-template>
428 </xsl:when>
429 <xsl:otherwise>
430 </xsl:otherwise>
431 </xsl:choose>
432</xsl:template>
433
434<xsl:template name="select.olink.lang.fallback">
435 <xsl:param name="olink.lang" select="''"/>
436
437 <!-- Prefer language of the olink element -->
438 <xsl:value-of select="concat(normalize-space(concat($olink.lang, ' ',
439 $olink.lang.fallback.sequence)), ' ')"/>
440</xsl:template>
441
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"/>
446
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" />
451 </xsl:for-each>
452 </xsl:variable>
453
454 <xsl:variable name="targetdoc">
455 <xsl:value-of select="substring-before($olink.key, '/')"/>
456 </xsl:variable>
457
458 <!-- Does the target database use a sitemap? -->
459 <xsl:variable name="use.sitemap">
460 <xsl:choose>
461 <xsl:when test="$target.database//sitemap">1</xsl:when>
462 <xsl:otherwise>0</xsl:otherwise>
463 </xsl:choose>
464 </xsl:variable>
465
466
467 <!-- Get the baseuri for this targetptr -->
468 <xsl:variable name="baseuri" >
469 <xsl:choose>
470 <!-- Does the database use a sitemap? -->
471 <xsl:when test="$use.sitemap != 0" >
472 <xsl:choose>
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" />
480 </xsl:for-each>
481 </xsl:variable>
482 <xsl:choose>
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"/>
489 </xsl:call-template>
490 </xsl:for-each >
491 </xsl:when>
492 <xsl:otherwise>
493 <xsl:message>
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>
498 </xsl:message>
499 </xsl:otherwise>
500 </xsl:choose>
501 </xsl:when>
502 <xsl:otherwise>
503 <xsl:message>
504 <xsl:text>Olink warning: cannot compute relative </xsl:text>
505 <xsl:text>sitemap path without $current.docid parameter</xsl:text>
506 </xsl:message>
507 </xsl:otherwise>
508 </xsl:choose>
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" />
513 </xsl:for-each>
514 </xsl:variable>
515 <xsl:if test="$docbaseuri != ''" >
516 <xsl:value-of select="$docbaseuri"/>
517 </xsl:if>
518 </xsl:when>
519 <!-- No database sitemap in use -->
520 <xsl:otherwise>
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" />
525 </xsl:for-each>
526 </xsl:variable>
527 <xsl:if test="$docbaseuri != ''" >
528 <xsl:value-of select="$docbaseuri"/>
529 </xsl:if>
530 </xsl:otherwise>
531 </xsl:choose>
532 </xsl:variable>
533
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-->
539 </xsl:if>
540 </xsl:if>
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"/>
547 </xsl:if>
548 </xsl:if>
549</xsl:template>
550
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)"/>
559
560 <xsl:variable name="parent.id">
561 <xsl:call-template name="object.id">
562 <xsl:with-param name="object" select="$object"/>
563 </xsl:call-template>
564 </xsl:variable>
565
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"/>
573 </xsl:call-template>
574 </xsl:variable>
575
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" />
579 </xsl:for-each>
580 </xsl:variable>
581
582 <xsl:choose>
583 <!-- we found the olink object -->
584 <xsl:when test="$from.olink.href != ''">
585 <xsl:value-of select="$from.olink.href"/>
586 </xsl:when>
587 <xsl:when test="not($object/parent::*)">
588 <xsl:value-of select="$from.olink.href"/>
589 </xsl:when>
590 <xsl:otherwise>
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"/>
597 </xsl:call-template>
598 </xsl:otherwise>
599 </xsl:choose>
600
601</xsl:template>
602
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">
609 <xsl:choose>
610 <xsl:when test="@role and not(@xrefstyle)
611 and $use.role.as.xrefstyle != 0">
612 <xsl:value-of select="@role"/>
613 </xsl:when>
614 <xsl:otherwise>
615 <xsl:value-of select="@xrefstyle"/>
616 </xsl:otherwise>
617 </xsl:choose>
618 </xsl:param>
619
620 <xsl:choose>
621 <!-- If it has elements or text (not just PI or comment) -->
622 <xsl:when test="child::text() or child::*">
623 <xsl:apply-templates/>
624 </xsl:when>
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" >
629 <xsl:copy-of
630 select="key('targetptr-key', $olink.key)/xreftext/node()" />
631 </xsl:for-each>
632 </xsl:variable>
633
634 <xsl:variable name="xref.number" >
635 <xsl:for-each select="$target.database" >
636 <xsl:value-of select="key('targetptr-key', $olink.key)/@number" />
637 </xsl:for-each>
638 </xsl:variable>
639
640 <xsl:variable name="target.elem" >
641 <xsl:for-each select="$target.database" >
642 <xsl:value-of select="key('targetptr-key', $olink.key)/@element" />
643 </xsl:for-each>
644 </xsl:variable>
645
646 <xsl:variable name="lang">
647 <xsl:variable name="candidate">
648 <xsl:for-each select="$target.database" >
649 <xsl:value-of
650 select="key('targetptr-key', $olink.key)/@lang" />
651 </xsl:for-each>
652 </xsl:variable>
653 <xsl:choose>
654 <xsl:when test="$candidate != ''">
655 <xsl:value-of select="$candidate"/>
656 </xsl:when>
657 <xsl:otherwise>
658 <xsl:value-of select="$olink.lang"/>
659 </xsl:otherwise>
660 </xsl:choose>
661 </xsl:variable>
662
663 <xsl:variable name="targetdoc">
664 <xsl:value-of select="substring-before($olink.key, '/')"/>
665 </xsl:variable>
666
667 <xsl:choose>
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"/>
675 </xsl:when>
676 <xsl:when test="$xrefstyle != ''">
677 <xsl:if test="$olink.debug != 0">
678 <xsl:message>
679 <xsl:text>xrefstyle is '</xsl:text>
680 <xsl:value-of select="$xrefstyle"/>
681 <xsl:text>'.</xsl:text>
682 </xsl:message>
683 </xsl:if>
684 <xsl:variable name="template">
685 <xsl:choose>
686 <xsl:when test="starts-with(normalize-space($xrefstyle),
687 'select:')">
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"/>
693 </xsl:call-template>
694 </xsl:when>
695 <xsl:when test="starts-with(normalize-space($xrefstyle),
696 'template:')">
697 <xsl:value-of select="substring-after(
698 normalize-space($xrefstyle), 'template:')"/>
699 </xsl:when>
700 <xsl:otherwise>
701 <!-- Look for Gentext template with @style attribute -->
702 <!-- Must compare to no style value because gentext.template
703 falls back to no style -->
704
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"/>
710 </xsl:call-template>
711 </xsl:variable>
712
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"/>
719 </xsl:call-template>
720 </xsl:variable>
721
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"/>
727 </xsl:call-template>
728 </xsl:variable>
729
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"/>
736 </xsl:call-template>
737 </xsl:variable>
738
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"/>
745 </xsl:call-template>
746 </xsl:variable>
747
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"/>
755 </xsl:call-template>
756 </xsl:variable>
757
758 <xsl:choose>
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">
763 <xsl:value-of
764 select="$styled-xref-number-and-title-context"/>
765 </xsl:when>
766 <xsl:when test="$xref-number-context !=
767 $styled-xref-number-context and
768 $xref.number != ''">
769 <xsl:value-of select="$styled-xref-number-context"/>
770 </xsl:when>
771 <xsl:when test="$xref-context != $styled-xref-context">
772 <xsl:value-of select="$styled-xref-context"/>
773 </xsl:when>
774 <xsl:when test="$xref-number-and-title-context != '' and
775 $xref.number != '' and
776 $xref.with.number.and.title != 0">
777 <xsl:value-of
778 select="$xref-number-and-title-context"/>
779 <xsl:if test="$olink.debug">
780 <xsl:message>
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>
790 </xsl:message>
791 </xsl:if>
792 </xsl:when>
793 <xsl:when test="$xref-number-context != '' and
794 $xref.number != ''">
795 <xsl:value-of select="$xref-number-context"/>
796 <xsl:if test="$olink.debug">
797 <xsl:message>
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>
807 </xsl:message>
808 </xsl:if>
809 </xsl:when>
810 <xsl:when test="$xref-context != ''">
811 <xsl:value-of select="$xref-context"/>
812 <xsl:if test="$olink.debug">
813 <xsl:message>
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>
823 </xsl:message>
824 </xsl:if>
825 </xsl:when>
826 <xsl:otherwise>
827 <xsl:message>
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>
836 </xsl:message>
837 <xsl:value-of select="'%t'"/>
838 </xsl:otherwise>
839 </xsl:choose>
840 </xsl:otherwise>
841 </xsl:choose>
842 </xsl:variable>
843
844 <xsl:if test="$olink.debug != 0">
845 <xsl:message>
846 <xsl:text>Olink debug: xrefstyle template is '</xsl:text>
847 <xsl:value-of select="$template"/>
848 <xsl:text>'.</xsl:text>
849 </xsl:message>
850 </xsl:if>
851
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" />
857 </xsl:for-each>
858 </xsl:with-param>
859 <xsl:with-param name="label">
860 <xsl:for-each select="$target.database" >
861 <xsl:value-of
862 select="key('targetptr-key', $olink.key)/@number" />
863 </xsl:for-each>
864 </xsl:with-param>
865 <xsl:with-param name="pagenumber">
866 <xsl:for-each select="$target.database" >
867 <xsl:value-of
868 select="key('targetptr-key', $olink.key)/@page" />
869 </xsl:for-each>
870 </xsl:with-param>
871 <xsl:with-param name="docname">
872 <xsl:for-each select="$target.database" >
873 <xsl:value-of
874 select="key('targetdoc-key', $targetdoc)/div[1]/ttl" />
875 </xsl:for-each>
876 </xsl:with-param>
877 </xsl:call-template>
878 </xsl:when>
879
880 <xsl:when test="$use.local.olink.style != 0">
881
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"/>
887 </xsl:call-template>
888 </xsl:variable>
889
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" />
895 </xsl:for-each>
896 </xsl:with-param>
897 <xsl:with-param name="label">
898 <xsl:for-each select="$target.database" >
899 <xsl:value-of
900 select="key('targetptr-key', $olink.key)/@number" />
901 </xsl:for-each>
902 </xsl:with-param>
903 </xsl:call-template>
904 </xsl:when>
905 <xsl:when test="$xref.text !=''">
906 <xsl:copy-of select="$xref.text"/>
907 </xsl:when>
908 <xsl:otherwise>
909 <xsl:message>
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>
914 </xsl:message>
915 <xsl:text>????</xsl:text>
916 </xsl:otherwise>
917 </xsl:choose>
918 </xsl:when>
919 <xsl:when test="@targetdoc != '' or @targetptr != ''">
920 <xsl:if test="$olink.key != ''">
921 <xsl:message>
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>
926 </xsl:message>
927 </xsl:if>
928 <xsl:text>????</xsl:text>
929 </xsl:when>
930 <xsl:otherwise>
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'"/>
937 </xsl:call-template>
938 </xsl:otherwise>
939 </xsl:choose>
940</xsl:template>
941
942<xsl:template match="*" mode="olink.docname.markup">
943 <!-- No-op for now -->
944</xsl:template>
945
946<xsl:template name="targetpath">
947 <xsl:param name="dirnode" />
948 <xsl:param name="targetdoc" select="''"/>
949
950<!--
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>
953-->
954 <!-- recursive template generates path to olink target directory -->
955 <xsl:choose>
956 <!-- Have we arrived at the final path step? -->
957 <xsl:when test="$dirnode/child::document[@targetdoc = $targetdoc]">
958 <!-- We are done -->
959 </xsl:when>
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>
963 </xsl:when>
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>
970 </xsl:if>
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"/>
975 </xsl:call-template>
976 </xsl:when>
977 <!-- Otherwise we need to move up a step -->
978 <xsl:otherwise>
979 <xsl:if test="$dirnode/parent::dir">
980 <xsl:text>../</xsl:text>
981 </xsl:if>
982 <xsl:call-template name="targetpath" >
983 <xsl:with-param name="dirnode" select="$dirnode/parent::*"/>
984 <xsl:with-param name="targetdoc" select="$targetdoc"/>
985 </xsl:call-template>
986 </xsl:otherwise>
987 </xsl:choose>
988</xsl:template>
989
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">
996 <xsl:choose>
997 <xsl:when test="@role and not(@xrefstyle)
998 and $use.role.as.xrefstyle != 0">
999 <xsl:value-of select="@role"/>
1000 </xsl:when>
1001 <xsl:otherwise>
1002 <xsl:value-of select="@xrefstyle"/>
1003 </xsl:otherwise>
1004 </xsl:choose>
1005 </xsl:param>
1006
1007 <xsl:variable name="targetdoc">
1008 <xsl:value-of select="substring-before($olink.key, '/')"/>
1009 </xsl:variable>
1010
1011 <xsl:choose>
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>
1018 </xsl:when>
1019 <xsl:when test="not(starts-with(normalize-space($xrefstyle),
1020 'select:')
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' ">
1026
1027 <xsl:variable name="page-number">
1028 <xsl:for-each select="$target.database" >
1029 <xsl:value-of
1030 select="key('targetptr-key', $olink.key)/@page" />
1031 </xsl:for-each>
1032 </xsl:variable>
1033
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>
1042 </xsl:with-param>
1043 <xsl:with-param name="pagenumber" select="$page-number"/>
1044 </xsl:call-template>
1045 </xsl:if>
1046
1047 </xsl:when>
1048 </xsl:choose>
1049</xsl:template>
1050
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">
1056 <xsl:choose>
1057 <xsl:when test="@role and not(@xrefstyle)
1058 and $use.role.as.xrefstyle != 0">
1059 <xsl:value-of select="@role"/>
1060 </xsl:when>
1061 <xsl:otherwise>
1062 <xsl:value-of select="@xrefstyle"/>
1063 </xsl:otherwise>
1064 </xsl:choose>
1065 </xsl:param>
1066
1067 <xsl:variable name="page">
1068 <xsl:for-each select="$target.database" >
1069 <xsl:value-of
1070 select="key('targetptr-key', $olink.key)/@page" />
1071 </xsl:for-each>
1072 </xsl:variable>
1073
1074 <xsl:variable name="targetdoc">
1075 <xsl:value-of select="substring-before($olink.key, '/')"/>
1076 </xsl:variable>
1077
1078 <xsl:variable name="targetptr">
1079 <xsl:value-of
1080 select="substring-before(substring-after($olink.key, '/'), '/')"/>
1081 </xsl:variable>
1082
1083 <!-- Don't add docname if pointing to root element -->
1084 <xsl:variable name="rootptr">
1085 <xsl:for-each select="$target.database" >
1086 <xsl:value-of
1087 select="key('targetdoc-key', $targetdoc)/div[1]/@targetptr" />
1088 </xsl:for-each>
1089 </xsl:variable>
1090
1091 <xsl:variable name="docname">
1092 <xsl:for-each select="$target.database" >
1093 <xsl:value-of
1094 select="key('targetdoc-key', $targetdoc)/div[1]/ttl" />
1095 </xsl:for-each>
1096 </xsl:variable>
1097
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>
1112 </xsl:with-param>
1113 <xsl:with-param name="docname" select="$docname"/>
1114 <xsl:with-param name="pagenumber" select="$page"/>
1115 </xsl:call-template>
1116 </xsl:if>
1117</xsl:template>
1118
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">
1125 <xsl:choose>
1126 <xsl:when test="@role and not(@xrefstyle)
1127 and $use.role.as.xrefstyle != 0">
1128 <xsl:value-of select="@role"/>
1129 </xsl:when>
1130 <xsl:otherwise>
1131 <xsl:value-of select="@xrefstyle"/>
1132 </xsl:otherwise>
1133 </xsl:choose>
1134 </xsl:param>
1135
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>
1145 </xsl:if>
1146</xsl:template>
1147
1148</xsl:stylesheet>
1149
Note: See TracBrowser for help on using the repository browser.