source: trunk/lib/docbook/docbook/xsl/html/chunk-common.xsl @ 3319

Last change on this file since 3319 was 3319, checked in by Nicklas Nordborg, 16 years ago

Fixed problem with incorrect links to <sect2> sections.

  • Property svn:eol-style set to native
File size: 45.3 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<!-- ********************************************************************
6     $Id: chunk-common.xsl 6403 2006-11-12 08:23:54Z bobstayton $
7     ********************************************************************
8
9     This file is part of the XSL DocBook Stylesheet distribution.
10     See ../README or http://nwalsh.com/docbook/xsl/ for copyright
11     and other information.
12
13     ******************************************************************** -->
14
15<!-- ==================================================================== -->
16
17<xsl:template name="chunk">
18  <xsl:param name="node" select="."/>
19  <!-- returns 1 if $node is a chunk -->
20
21  <!-- ==================================================================== -->
22  <!-- What's a chunk?
23
24       The root element
25       appendix
26       article
27       bibliography  in article or part or book
28       book
29       chapter
30       colophon
31       glossary      in article or part or book
32       index         in article or part or book
33       part
34       preface
35       refentry
36       reference
37       sect{1,2,3,4,5}  if position()>1 && depth < chunk.section.depth
38       section          if position()>1 && depth < chunk.section.depth
39       set
40       setindex
41                                                                            -->
42  <!-- ==================================================================== -->
43
44<!--
45  <xsl:message>
46    <xsl:text>chunk: </xsl:text>
47    <xsl:value-of select="name($node)"/>
48    <xsl:text>(</xsl:text>
49    <xsl:value-of select="$node/@id"/>
50    <xsl:text>)</xsl:text>
51    <xsl:text> csd: </xsl:text>
52    <xsl:value-of select="$chunk.section.depth"/>
53    <xsl:text> cfs: </xsl:text>
54    <xsl:value-of select="$chunk.first.sections"/>
55    <xsl:text> ps: </xsl:text>
56    <xsl:value-of select="count($node/parent::section)"/>
57    <xsl:text> prs: </xsl:text>
58    <xsl:value-of select="count($node/preceding-sibling::section)"/>
59  </xsl:message>
60-->
61
62  <xsl:choose>
63    <xsl:when test="../@chunked = 0">0</xsl:when>
64    <xsl:when test="not($node/parent::*)">1</xsl:when>
65
66    <xsl:when test="local-name($node) = 'sect1'
67                    and $chunk.section.depth &gt;= 1
68                    and ($chunk.first.sections != 0
69                         or count($node/preceding-sibling::sect1) &gt; 0)">
70      <xsl:text>1</xsl:text>
71    </xsl:when>
72    <xsl:when test="local-name($node) = 'sect2'
73                    and $chunk.section.depth &gt;= 2
74                    and ($chunk.first.sections != 0
75                         or count($node/preceding-sibling::sect2) &gt; 0)">
76      <xsl:call-template name="chunk">
77        <xsl:with-param name="node" select="$node/parent::*"/>
78      </xsl:call-template>
79    </xsl:when>
80    <xsl:when test="local-name($node) = 'sect3'
81                    and $chunk.section.depth &gt;= 3
82                    and ($chunk.first.sections != 0
83                         or count($node/preceding-sibling::sect3) &gt; 0)">
84      <xsl:call-template name="chunk">
85        <xsl:with-param name="node" select="$node/parent::*"/>
86      </xsl:call-template>
87    </xsl:when>
88    <xsl:when test="local-name($node) = 'sect4'
89                    and $chunk.section.depth &gt;= 4
90                    and ($chunk.first.sections != 0
91                         or count($node/preceding-sibling::sect4) &gt; 0)">
92      <xsl:call-template name="chunk">
93        <xsl:with-param name="node" select="$node/parent::*"/>
94      </xsl:call-template>
95    </xsl:when>
96    <xsl:when test="local-name($node) = 'sect5'
97                    and $chunk.section.depth &gt;= 5
98                    and ($chunk.first.sections != 0
99                         or count($node/preceding-sibling::sect5) &gt; 0)">
100      <xsl:call-template name="chunk">
101        <xsl:with-param name="node" select="$node/parent::*"/>
102      </xsl:call-template>
103    </xsl:when>
104    <xsl:when test="local-name($node) = 'section'
105                    and $chunk.section.depth &gt;= count($node/ancestor::section)+1
106                    and ($chunk.first.sections != 0
107                         or count($node/preceding-sibling::section) &gt; 0)">
108      <xsl:call-template name="chunk">
109        <xsl:with-param name="node" select="$node/parent::*"/>
110      </xsl:call-template>
111    </xsl:when>
112
113    <xsl:when test="local-name($node)='preface'">1</xsl:when>
114    <xsl:when test="local-name($node)='chapter'">1</xsl:when>
115    <xsl:when test="local-name($node)='appendix'">1</xsl:when>
116    <xsl:when test="local-name($node)='article'">1</xsl:when>
117    <xsl:when test="local-name($node)='part'">1</xsl:when>
118    <xsl:when test="local-name($node)='reference'">1</xsl:when>
119    <xsl:when test="local-name($node)='refentry'">1</xsl:when>
120    <xsl:when test="local-name($node)='index' and ($generate.index != 0 or count($node/*) > 0)
121                    and (local-name($node/parent::*) = 'article'
122                    or local-name($node/parent::*) = 'book'
123                    or local-name($node/parent::*) = 'part'
124                    )">1</xsl:when>
125    <xsl:when test="local-name($node)='bibliography'
126                    and (local-name($node/parent::*) = 'article'
127                    or local-name($node/parent::*) = 'book'
128                    or local-name($node/parent::*) = 'part'
129                    )">1</xsl:when>
130    <xsl:when test="local-name($node)='glossary'
131                    and (local-name($node/parent::*) = 'article'
132                    or local-name($node/parent::*) = 'book'
133                    or local-name($node/parent::*) = 'part'
134                    )">1</xsl:when>
135    <xsl:when test="local-name($node)='colophon'">1</xsl:when>
136    <xsl:when test="local-name($node)='book'">1</xsl:when>
137    <xsl:when test="local-name($node)='set'">1</xsl:when>
138    <xsl:when test="local-name($node)='setindex'">1</xsl:when>
139    <xsl:when test="local-name($node)='legalnotice'
140                    and $generate.legalnotice.link != 0">1</xsl:when>
141    <xsl:otherwise>0</xsl:otherwise>
142  </xsl:choose>
143</xsl:template>
144
145<!-- ==================================================================== -->
146
147<xsl:template match="*" mode="chunk-filename">
148  <!-- returns the filename of a chunk -->
149  <xsl:variable name="ischunk">
150    <xsl:call-template name="chunk"/>
151  </xsl:variable>
152
153  <xsl:variable name="fn">
154    <xsl:apply-templates select="." mode="recursive-chunk-filename"/>
155  </xsl:variable>
156
157  <!--
158  <xsl:message>
159    <xsl:value-of select="$ischunk"/>
160    <xsl:text> (</xsl:text>
161    <xsl:value-of select="local-name(.)"/>
162    <xsl:text>) </xsl:text>
163    <xsl:value-of select="$fn"/>
164    <xsl:text>, </xsl:text>
165    <xsl:call-template name="dbhtml-dir"/>
166  </xsl:message>
167  -->
168
169  <!-- 2003-11-25 by ndw:
170       The following test used to read test="$ischunk != 0 and $fn != ''"
171       I've removed the ischunk part of the test so that href.to.uri and
172       href.from.uri will be fully qualified even if the source or target
173       isn't a chunk. I *think* that if $fn != '' then it's appropriate
174       to put the directory on the front, even if the element isn't a
175       chunk. I could be wrong. -->
176
177  <xsl:if test="$fn != ''">
178    <xsl:call-template name="dbhtml-dir"/>
179  </xsl:if>
180
181  <xsl:value-of select="$fn"/>
182  <!-- You can't add the html.ext here because dbhtml filename= may already -->
183  <!-- have added it. It really does have to be handled in the recursive template -->
184</xsl:template>
185
186<xsl:template match="*" mode="recursive-chunk-filename">
187  <xsl:param name="recursive" select="false()"/>
188
189  <!-- returns the filename of a chunk -->
190  <xsl:variable name="ischunk">
191    <xsl:call-template name="chunk"/>
192  </xsl:variable>
193
194  <xsl:variable name="dbhtml-filename">
195    <xsl:call-template name="dbhtml-filename"/>
196  </xsl:variable>
197
198  <xsl:variable name="filename">
199    <xsl:choose>
200      <xsl:when test="$dbhtml-filename != ''">
201        <xsl:value-of select="$dbhtml-filename"/>
202      </xsl:when>
203      <!-- if this is the root element, use the root.filename -->
204      <xsl:when test="not(parent::*) and $root.filename != ''">
205        <xsl:value-of select="$root.filename"/>
206        <xsl:value-of select="$html.ext"/>
207      </xsl:when>
208      <!-- Special case -->
209      <xsl:when test="self::legalnotice and $generate.legalnotice.link != 0">
210        <xsl:variable name="id">
211          <xsl:call-template name="object.id"/>
212        </xsl:variable>
213        <xsl:value-of select="concat('ln-',$id,$html.ext)"/>
214      </xsl:when>
215      <!-- if there's no dbhtml filename, and if we're to use IDs as -->
216      <!-- filenames, then use the ID to generate the filename. -->
217      <xsl:when test="(@id or @xml:id) and $use.id.as.filename != 0">
218        <xsl:value-of select="(@id|@xml:id)[1]"/>
219        <xsl:value-of select="$html.ext"/>
220      </xsl:when>
221      <xsl:otherwise></xsl:otherwise>
222    </xsl:choose>
223  </xsl:variable>
224
225  <xsl:choose>
226    <xsl:when test="$ischunk='0'">
227      <!-- if called on something that isn't a chunk, walk up... -->
228      <xsl:choose>
229        <xsl:when test="count(parent::*)>0">
230          <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
231            <xsl:with-param name="recursive" select="$recursive"/>
232          </xsl:apply-templates>
233        </xsl:when>
234        <!-- unless there is no up, in which case return "" -->
235        <xsl:otherwise></xsl:otherwise>
236      </xsl:choose>
237    </xsl:when>
238
239    <xsl:when test="not($recursive) and $filename != ''">
240      <!-- if this chunk has an explicit name, use it -->
241      <xsl:value-of select="$filename"/>
242    </xsl:when>
243
244    <xsl:when test="self::set">
245      <xsl:value-of select="$root.filename"/>
246      <xsl:if test="not($recursive)">
247        <xsl:value-of select="$html.ext"/>
248      </xsl:if>
249    </xsl:when>
250
251    <xsl:when test="self::book">
252      <xsl:text>bk</xsl:text>
253      <xsl:number level="any" format="01"/>
254      <xsl:if test="not($recursive)">
255        <xsl:value-of select="$html.ext"/>
256      </xsl:if>
257    </xsl:when>
258
259    <xsl:when test="self::article">
260      <xsl:if test="/set">
261        <!-- in a set, make sure we inherit the right book info... -->
262        <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
263          <xsl:with-param name="recursive" select="true()"/>
264        </xsl:apply-templates>
265      </xsl:if>
266
267      <xsl:text>ar</xsl:text>
268      <xsl:number level="any" format="01" from="book"/>
269      <xsl:if test="not($recursive)">
270        <xsl:value-of select="$html.ext"/>
271      </xsl:if>
272    </xsl:when>
273
274    <xsl:when test="self::preface">
275      <xsl:if test="/set">
276        <!-- in a set, make sure we inherit the right book info... -->
277        <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
278          <xsl:with-param name="recursive" select="true()"/>
279        </xsl:apply-templates>
280      </xsl:if>
281
282      <xsl:text>pr</xsl:text>
283      <xsl:number level="any" format="01" from="book"/>
284      <xsl:if test="not($recursive)">
285        <xsl:value-of select="$html.ext"/>
286      </xsl:if>
287    </xsl:when>
288
289    <xsl:when test="self::chapter">
290      <xsl:if test="/set">
291        <!-- in a set, make sure we inherit the right book info... -->
292        <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
293          <xsl:with-param name="recursive" select="true()"/>
294        </xsl:apply-templates>
295      </xsl:if>
296
297      <xsl:text>ch</xsl:text>
298      <xsl:number level="any" format="01" from="book"/>
299      <xsl:if test="not($recursive)">
300        <xsl:value-of select="$html.ext"/>
301      </xsl:if>
302    </xsl:when>
303
304    <xsl:when test="self::appendix">
305      <xsl:if test="/set">
306        <!-- in a set, make sure we inherit the right book info... -->
307        <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
308          <xsl:with-param name="recursive" select="true()"/>
309        </xsl:apply-templates>
310      </xsl:if>
311
312      <xsl:text>ap</xsl:text>
313      <xsl:number level="any" format="a" from="book"/>
314      <xsl:if test="not($recursive)">
315        <xsl:value-of select="$html.ext"/>
316      </xsl:if>
317    </xsl:when>
318
319    <xsl:when test="self::part">
320      <xsl:choose>
321        <xsl:when test="/set">
322          <!-- in a set, make sure we inherit the right book info... -->
323          <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
324            <xsl:with-param name="recursive" select="true()"/>
325          </xsl:apply-templates>
326        </xsl:when>
327        <xsl:otherwise>
328        </xsl:otherwise>
329      </xsl:choose>
330
331      <xsl:text>pt</xsl:text>
332      <xsl:number level="any" format="01" from="book"/>
333      <xsl:if test="not($recursive)">
334        <xsl:value-of select="$html.ext"/>
335      </xsl:if>
336    </xsl:when>
337
338    <xsl:when test="self::reference">
339      <xsl:choose>
340        <xsl:when test="/set">
341          <!-- in a set, make sure we inherit the right book info... -->
342          <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
343            <xsl:with-param name="recursive" select="true()"/>
344          </xsl:apply-templates>
345        </xsl:when>
346        <xsl:otherwise>
347        </xsl:otherwise>
348      </xsl:choose>
349
350      <xsl:text>rn</xsl:text>
351      <xsl:number level="any" format="01" from="book"/>
352      <xsl:if test="not($recursive)">
353        <xsl:value-of select="$html.ext"/>
354      </xsl:if>
355    </xsl:when>
356
357    <xsl:when test="self::refentry">
358      <xsl:choose>
359        <xsl:when test="parent::reference">
360          <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
361            <xsl:with-param name="recursive" select="true()"/>
362          </xsl:apply-templates>
363        </xsl:when>
364        <xsl:otherwise>
365        </xsl:otherwise>
366      </xsl:choose>
367
368      <xsl:text>re</xsl:text>
369      <xsl:number level="any" format="01" from="book"/>
370      <xsl:if test="not($recursive)">
371        <xsl:value-of select="$html.ext"/>
372      </xsl:if>
373    </xsl:when>
374
375    <xsl:when test="self::colophon">
376      <xsl:choose>
377        <xsl:when test="/set">
378          <!-- in a set, make sure we inherit the right book info... -->
379          <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
380            <xsl:with-param name="recursive" select="true()"/>
381          </xsl:apply-templates>
382        </xsl:when>
383        <xsl:otherwise>
384        </xsl:otherwise>
385      </xsl:choose>
386
387      <xsl:text>co</xsl:text>
388      <xsl:number level="any" format="01" from="book"/>
389      <xsl:if test="not($recursive)">
390        <xsl:value-of select="$html.ext"/>
391      </xsl:if>
392    </xsl:when>
393
394    <xsl:when test="self::sect1
395                    or self::sect2
396                    or self::sect3
397                    or self::sect4
398                    or self::sect5
399                    or self::section">
400      <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
401        <xsl:with-param name="recursive" select="true()"/>
402      </xsl:apply-templates>
403      <xsl:text>s</xsl:text>
404      <xsl:number format="01"/>
405      <xsl:if test="not($recursive)">
406        <xsl:value-of select="$html.ext"/>
407      </xsl:if>
408    </xsl:when>
409
410    <xsl:when test="self::bibliography">
411      <xsl:choose>
412        <xsl:when test="/set">
413          <!-- in a set, make sure we inherit the right book info... -->
414          <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
415            <xsl:with-param name="recursive" select="true()"/>
416          </xsl:apply-templates>
417        </xsl:when>
418        <xsl:otherwise>
419        </xsl:otherwise>
420      </xsl:choose>
421
422      <xsl:text>bi</xsl:text>
423      <xsl:number level="any" format="01" from="book"/>
424      <xsl:if test="not($recursive)">
425        <xsl:value-of select="$html.ext"/>
426      </xsl:if>
427    </xsl:when>
428
429    <xsl:when test="self::glossary">
430      <xsl:choose>
431        <xsl:when test="/set">
432          <!-- in a set, make sure we inherit the right book info... -->
433          <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
434            <xsl:with-param name="recursive" select="true()"/>
435          </xsl:apply-templates>
436        </xsl:when>
437        <xsl:otherwise>
438        </xsl:otherwise>
439      </xsl:choose>
440
441      <xsl:text>go</xsl:text>
442      <xsl:number level="any" format="01" from="book"/>
443      <xsl:if test="not($recursive)">
444        <xsl:value-of select="$html.ext"/>
445      </xsl:if>
446    </xsl:when>
447
448    <xsl:when test="self::index">
449      <xsl:choose>
450        <xsl:when test="/set">
451          <!-- in a set, make sure we inherit the right book info... -->
452          <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
453            <xsl:with-param name="recursive" select="true()"/>
454          </xsl:apply-templates>
455        </xsl:when>
456        <xsl:otherwise>
457        </xsl:otherwise>
458      </xsl:choose>
459
460      <xsl:text>ix</xsl:text>
461      <xsl:number level="any" format="01" from="book"/>
462      <xsl:if test="not($recursive)">
463        <xsl:value-of select="$html.ext"/>
464      </xsl:if>
465    </xsl:when>
466
467    <xsl:when test="self::setindex">
468      <xsl:text>si</xsl:text>
469      <xsl:number level="any" format="01" from="set"/>
470      <xsl:if test="not($recursive)">
471        <xsl:value-of select="$html.ext"/>
472      </xsl:if>
473    </xsl:when>
474
475    <xsl:otherwise>
476      <xsl:text>chunk-filename-error-</xsl:text>
477      <xsl:value-of select="name(.)"/>
478      <xsl:number level="any" format="01" from="set"/>
479      <xsl:if test="not($recursive)">
480        <xsl:value-of select="$html.ext"/>
481      </xsl:if>
482    </xsl:otherwise>
483  </xsl:choose>
484</xsl:template>
485
486<!-- ==================================================================== -->
487
488<xsl:template name="href.target.uri">
489  <xsl:param name="object" select="."/>
490  <xsl:variable name="ischunk">
491    <xsl:call-template name="chunk" />
492  </xsl:variable>
493
494  <xsl:apply-templates mode="chunk-filename" select="$object"/>
495
496  <xsl:if test="$ischunk='0'">
497    <xsl:text>#</xsl:text>
498    <xsl:call-template name="object.id">
499      <xsl:with-param name="object" select="$object"/>
500    </xsl:call-template>
501  </xsl:if>
502</xsl:template>
503
504<xsl:template name="href.target">
505  <xsl:param name="context" select="."/>
506  <xsl:param name="object" select="."/>
507
508  <xsl:variable name="href.to.uri">
509    <xsl:call-template name="href.target.uri">
510      <xsl:with-param name="object" select="$object"/>
511    </xsl:call-template>
512  </xsl:variable>
513
514  <xsl:variable name="href.from.uri">
515    <xsl:call-template name="href.target.uri">
516      <xsl:with-param name="object" select="$context"/>
517    </xsl:call-template>
518  </xsl:variable>
519 
520  <!--
521  <xsl:message>href.to.uri: <xsl:value-of select="$href.to.uri"/></xsl:message>
522  <xsl:message>href.from.uri: <xsl:value-of select="$href.from.uri"/></xsl:message>
523  -->
524
525  <xsl:variable name="href.to">
526    <xsl:call-template name="trim.common.uri.paths">
527      <xsl:with-param name="uriA" select="$href.to.uri"/>
528      <xsl:with-param name="uriB" select="$href.from.uri"/>
529      <xsl:with-param name="return" select="'A'"/>
530    </xsl:call-template>
531  </xsl:variable>
532
533  <xsl:variable name="href.from">
534    <xsl:call-template name="trim.common.uri.paths">
535      <xsl:with-param name="uriA" select="$href.to.uri"/>
536      <xsl:with-param name="uriB" select="$href.from.uri"/>
537      <xsl:with-param name="return" select="'B'"/>
538    </xsl:call-template>
539  </xsl:variable>
540
541  <xsl:variable name="depth">
542    <xsl:call-template name="count.uri.path.depth">
543      <xsl:with-param name="filename" select="$href.from"/>
544    </xsl:call-template>
545  </xsl:variable>
546
547  <xsl:variable name="href">
548    <xsl:call-template name="copy-string">
549      <xsl:with-param name="string" select="'../'"/>
550      <xsl:with-param name="count" select="$depth"/>
551    </xsl:call-template>
552    <xsl:value-of select="$href.to"/>
553  </xsl:variable>
554
555  <!--
556  <xsl:message>
557    <xsl:text>In </xsl:text>
558    <xsl:value-of select="name(.)"/>
559    <xsl:text> (</xsl:text>
560    <xsl:value-of select="$href.from"/>
561    <xsl:text>,</xsl:text>
562    <xsl:value-of select="$depth"/>
563    <xsl:text>) </xsl:text>
564    <xsl:value-of select="name($object)"/>
565    <xsl:text> href=</xsl:text>
566    <xsl:value-of select="$href"/>
567  </xsl:message>
568  -->
569
570  <xsl:value-of select="$href"/>
571</xsl:template>
572
573<!-- Returns the complete olink href value if found -->
574<!-- Must take into account any dbhtml dir of the chunk containing the olink -->
575<xsl:template name="make.olink.href">
576  <xsl:param name="olink.key" select="''"/>
577  <xsl:param name="target.database"/>
578
579  <xsl:if test="$olink.key != ''">
580    <xsl:variable name="target.href" >
581      <xsl:for-each select="$target.database" >
582        <xsl:value-of select="key('targetptr-key', $olink.key)/@href" />
583      </xsl:for-each>
584    </xsl:variable>
585 
586    <!-- an olink starting point may be in a subdirectory, so need
587         the "from" reference point to compute a relative path -->
588
589    <xsl:variable name="from.href">
590      <xsl:call-template name="olink.from.uri">
591        <xsl:with-param name="target.database" select="$target.database"/>
592        <xsl:with-param name="object" select="."/>
593        <xsl:with-param name="object.targetdoc" select="$current.docid"/>
594      </xsl:call-template>
595    </xsl:variable>
596
597    <!-- If the from.href has directory path, then must "../" upward
598         to document level -->
599    <xsl:variable name="upward.from.path">
600      <xsl:call-template name="upward.path">
601        <xsl:with-param name="path" select="$from.href"/>
602      </xsl:call-template>
603    </xsl:variable>
604
605    <xsl:variable name="targetdoc">
606      <xsl:value-of select="substring-before($olink.key, '/')"/>
607    </xsl:variable>
608 
609    <!-- Does the target database use a sitemap? -->
610    <xsl:variable name="use.sitemap">
611      <xsl:choose>
612        <xsl:when test="$target.database//sitemap">1</xsl:when>
613        <xsl:otherwise>0</xsl:otherwise>
614      </xsl:choose>
615    </xsl:variable>
616 
617 
618    <!-- Get the baseuri for this targetptr -->
619    <xsl:variable name="baseuri" >
620      <xsl:choose>
621        <!-- Does the database use a sitemap? -->
622        <xsl:when test="$use.sitemap != 0" >
623          <xsl:choose>
624            <!-- Was current.docid parameter set? -->
625            <xsl:when test="$current.docid != ''">
626              <!-- Was it found in the database? -->
627              <xsl:variable name="currentdoc.key" >
628                <xsl:for-each select="$target.database" >
629                  <xsl:value-of select="key('targetdoc-key',
630                                        $current.docid)/@targetdoc" />
631                </xsl:for-each>
632              </xsl:variable>
633              <xsl:choose>
634                <xsl:when test="$currentdoc.key != ''">
635                  <xsl:for-each select="$target.database" >
636                    <xsl:call-template name="targetpath" >
637                      <xsl:with-param name="dirnode" 
638                          select="key('targetdoc-key', $current.docid)/parent::dir"/>
639                      <xsl:with-param name="targetdoc" select="$targetdoc"/>
640                    </xsl:call-template>
641                  </xsl:for-each >
642                </xsl:when>
643                <xsl:otherwise>
644                  <xsl:message>
645                    <xsl:text>Olink error: cannot compute relative </xsl:text>
646                    <xsl:text>sitemap path because $current.docid '</xsl:text>
647                    <xsl:value-of select="$current.docid"/>
648                    <xsl:text>' not found in target database.</xsl:text>
649                  </xsl:message>
650                </xsl:otherwise>
651              </xsl:choose>
652            </xsl:when>
653            <xsl:otherwise>
654              <xsl:message>
655                <xsl:text>Olink warning: cannot compute relative </xsl:text>
656                <xsl:text>sitemap path without $current.docid parameter</xsl:text>
657              </xsl:message>
658            </xsl:otherwise>
659          </xsl:choose> 
660          <!-- In either case, add baseuri from its document entry-->
661          <xsl:variable name="docbaseuri">
662            <xsl:for-each select="$target.database" >
663              <xsl:value-of select="key('targetdoc-key', $targetdoc)/@baseuri" />
664            </xsl:for-each>
665          </xsl:variable>
666          <xsl:if test="$docbaseuri != ''" >
667            <xsl:value-of select="$docbaseuri"/>
668          </xsl:if>
669        </xsl:when>
670        <!-- No database sitemap in use -->
671        <xsl:otherwise>
672          <!-- Just use any baseuri from its document entry -->
673          <xsl:variable name="docbaseuri">
674            <xsl:for-each select="$target.database" >
675              <xsl:value-of select="key('targetdoc-key', $targetdoc)/@baseuri" />
676            </xsl:for-each>
677          </xsl:variable>
678          <xsl:if test="$docbaseuri != ''" >
679            <xsl:value-of select="$docbaseuri"/>
680          </xsl:if>
681        </xsl:otherwise>
682      </xsl:choose>
683    </xsl:variable>
684 
685    <!-- Form the href information -->
686    <xsl:if test="not(contains($baseuri, ':'))">
687      <!-- if not an absolute uri, add upward path from olink chunk -->
688      <xsl:value-of select="$upward.from.path"/>
689    </xsl:if>
690
691    <xsl:if test="$baseuri != ''">
692      <xsl:value-of select="$baseuri"/>
693      <xsl:if test="substring($target.href,1,1) != '#'">
694        <!--xsl:text>/</xsl:text-->
695      </xsl:if>
696    </xsl:if>
697    <!-- optionally turn off frag for PDF references -->
698    <xsl:if test="not($insert.olink.pdf.frag = 0 and
699          translate(substring($baseuri, string-length($baseuri) - 3),
700                    'PDF', 'pdf') = '.pdf'
701          and starts-with($target.href, '#') )">
702      <xsl:value-of select="$target.href"/>
703    </xsl:if>
704  </xsl:if>
705</xsl:template>
706
707<!-- Computes "../" to reach top -->
708<xsl:template name="upward.path">
709  <xsl:param name="path" select="''"/>
710  <xsl:choose> 
711    <!-- Don't bother with absolute uris -->
712    <xsl:when test="contains($path, ':')"/>
713    <xsl:when test="starts-with($path, '/')"/>
714    <xsl:when test="contains($path, '/')">
715      <xsl:text>../</xsl:text>
716      <xsl:call-template name="upward.path">
717        <xsl:with-param name="path" select="substring-after($path, '/')"/>
718      </xsl:call-template>
719    </xsl:when>
720  </xsl:choose>
721
722</xsl:template>
723
724<!-- ==================================================================== -->
725
726<xsl:template name="html.head">
727  <xsl:param name="prev" select="/foo"/>
728  <xsl:param name="next" select="/foo"/>
729  <xsl:variable name="this" select="."/>
730  <xsl:variable name="home" select="/*[1]"/>
731  <xsl:variable name="up" select="parent::*"/>
732
733  <head>
734    <xsl:call-template name="system.head.content"/>
735    <xsl:call-template name="head.content"/>
736
737    <xsl:if test="$home">
738      <link rel="start">
739        <xsl:attribute name="href">
740          <xsl:call-template name="href.target">
741            <xsl:with-param name="object" select="$home"/>
742          </xsl:call-template>
743        </xsl:attribute>
744        <xsl:attribute name="title">
745          <xsl:apply-templates select="$home"
746                               mode="object.title.markup.textonly"/>
747        </xsl:attribute>
748      </link>
749    </xsl:if>
750
751    <xsl:if test="$up">
752      <link rel="up">
753        <xsl:attribute name="href">
754          <xsl:call-template name="href.target">
755            <xsl:with-param name="object" select="$up"/>
756          </xsl:call-template>
757        </xsl:attribute>
758        <xsl:attribute name="title">
759          <xsl:apply-templates select="$up" mode="object.title.markup.textonly"/>
760        </xsl:attribute>
761      </link>
762    </xsl:if>
763
764    <xsl:if test="$prev">
765      <link rel="prev">
766        <xsl:attribute name="href">
767          <xsl:call-template name="href.target">
768            <xsl:with-param name="object" select="$prev"/>
769          </xsl:call-template>
770        </xsl:attribute>
771        <xsl:attribute name="title">
772          <xsl:apply-templates select="$prev" mode="object.title.markup.textonly"/>
773        </xsl:attribute>
774      </link>
775    </xsl:if>
776
777    <xsl:if test="$next">
778      <link rel="next">
779        <xsl:attribute name="href">
780          <xsl:call-template name="href.target">
781            <xsl:with-param name="object" select="$next"/>
782          </xsl:call-template>
783        </xsl:attribute>
784        <xsl:attribute name="title">
785          <xsl:apply-templates select="$next" mode="object.title.markup.textonly"/>
786        </xsl:attribute>
787      </link>
788    </xsl:if>
789
790    <xsl:if test="$html.extra.head.links != 0">
791      <xsl:for-each select="//part
792                            |//reference
793                            |//preface
794                            |//chapter
795                            |//article
796                            |//refentry
797                            |//appendix[not(parent::article)]|appendix
798                            |//glossary[not(parent::article)]|glossary
799                            |//index[not(parent::article)]|index">
800        <link rel="{local-name(.)}">
801          <xsl:attribute name="href">
802            <xsl:call-template name="href.target">
803              <xsl:with-param name="context" select="$this"/>
804              <xsl:with-param name="object" select="."/>
805            </xsl:call-template>
806          </xsl:attribute>
807          <xsl:attribute name="title">
808            <xsl:apply-templates select="." mode="object.title.markup.textonly"/>
809          </xsl:attribute>
810        </link>
811      </xsl:for-each>
812
813      <xsl:for-each select="section|sect1|refsection|refsect1">
814        <link>
815          <xsl:attribute name="rel">
816            <xsl:choose>
817              <xsl:when test="local-name($this) = 'section'
818                              or local-name($this) = 'refsection'">
819                <xsl:value-of select="'subsection'"/>
820              </xsl:when>
821              <xsl:otherwise>
822                <xsl:value-of select="'section'"/>
823              </xsl:otherwise>
824            </xsl:choose>
825          </xsl:attribute>
826          <xsl:attribute name="href">
827            <xsl:call-template name="href.target">
828              <xsl:with-param name="context" select="$this"/>
829              <xsl:with-param name="object" select="."/>
830            </xsl:call-template>
831          </xsl:attribute>
832          <xsl:attribute name="title">
833            <xsl:apply-templates select="." mode="object.title.markup.textonly"/>
834          </xsl:attribute>
835        </link>
836      </xsl:for-each>
837
838      <xsl:for-each select="sect2|sect3|sect4|sect5|refsect2|refsect3">
839        <link rel="subsection">
840          <xsl:attribute name="href">
841            <xsl:call-template name="href.target">
842              <xsl:with-param name="context" select="$this"/>
843              <xsl:with-param name="object" select="."/>
844            </xsl:call-template>
845          </xsl:attribute>
846          <xsl:attribute name="title">
847            <xsl:apply-templates select="." mode="object.title.markup.textonly"/>
848          </xsl:attribute>
849        </link>
850      </xsl:for-each>
851    </xsl:if>
852
853    <!-- * if we have a legalnotice and user wants it output as a -->
854    <!-- * separate page and $html.head.legalnotice.link.types is -->
855    <!-- * non-empty, we generate a link or links for each value in -->
856    <!-- * $html.head.legalnotice.link.types -->
857    <xsl:if test="//legalnotice
858                  and not($generate.legalnotice.link = 0)
859                  and not($html.head.legalnotice.link.types = '')">
860      <xsl:call-template name="make.legalnotice.head.links"/>
861    </xsl:if>
862
863    <xsl:call-template name="user.head.content"/>
864  </head>
865</xsl:template>
866
867<!-- ==================================================================== -->
868
869<xsl:template name="header.navigation">
870  <xsl:param name="prev" select="/foo"/>
871  <xsl:param name="next" select="/foo"/>
872  <xsl:param name="nav.context"/>
873
874  <xsl:variable name="home" select="/*[1]"/>
875  <xsl:variable name="up" select="parent::*"/>
876
877  <xsl:variable name="row1" select="$navig.showtitles != 0"/>
878  <xsl:variable name="row2" select="count($prev) &gt; 0
879                                    or (count($up) &gt; 0
880                                        and generate-id($up) != generate-id($home)
881                                        and $navig.showtitles != 0)
882                                    or count($next) &gt; 0"/>
883
884  <xsl:if test="$suppress.navigation = '0' and $suppress.header.navigation = '0'">
885    <div class="navheader">
886      <xsl:if test="$row1 or $row2">
887        <table width="100%" summary="Navigation header">
888          <xsl:if test="$row1">
889            <tr>
890              <th colspan="3" align="center">
891                <xsl:apply-templates select="." mode="object.title.markup"/>
892              </th>
893            </tr>
894          </xsl:if>
895
896          <xsl:if test="$row2">
897            <tr>
898              <td width="20%" align="left">
899                <xsl:if test="count($prev)>0">
900                  <a accesskey="p">
901                    <xsl:attribute name="href">
902                      <xsl:call-template name="href.target">
903                        <xsl:with-param name="object" select="$prev"/>
904                      </xsl:call-template>
905                    </xsl:attribute>
906                    <xsl:call-template name="navig.content">
907                      <xsl:with-param name="direction" select="'prev'"/>
908                    </xsl:call-template>
909                  </a>
910                </xsl:if>
911                <xsl:text>&#160;</xsl:text>
912              </td>
913              <th width="60%" align="center">
914                <xsl:choose>
915                  <xsl:when test="count($up) > 0
916                                  and generate-id($up) != generate-id($home)
917                                  and $navig.showtitles != 0">
918                    <xsl:apply-templates select="$up" mode="object.title.markup"/>
919                  </xsl:when>
920                  <xsl:otherwise>&#160;</xsl:otherwise>
921                </xsl:choose>
922              </th>
923              <td width="20%" align="right">
924                <xsl:text>&#160;</xsl:text>
925                <xsl:if test="count($next)>0">
926                  <a accesskey="n">
927                    <xsl:attribute name="href">
928                      <xsl:call-template name="href.target">
929                        <xsl:with-param name="object" select="$next"/>
930                      </xsl:call-template>
931                    </xsl:attribute>
932                    <xsl:call-template name="navig.content">
933                      <xsl:with-param name="direction" select="'next'"/>
934                    </xsl:call-template>
935                  </a>
936                </xsl:if>
937              </td>
938            </tr>
939          </xsl:if>
940        </table>
941      </xsl:if>
942      <xsl:if test="$header.rule != 0">
943        <hr/>
944      </xsl:if>
945    </div>
946  </xsl:if>
947</xsl:template>
948
949<!-- ==================================================================== -->
950
951<xsl:template name="footer.navigation">
952  <xsl:param name="prev" select="/foo"/>
953  <xsl:param name="next" select="/foo"/>
954  <xsl:param name="nav.context"/>
955
956  <xsl:variable name="home" select="/*[1]"/>
957  <xsl:variable name="up" select="parent::*"/>
958
959  <xsl:variable name="row1" select="count($prev) &gt; 0
960                                    or count($up) &gt; 0
961                                    or count($next) &gt; 0"/>
962
963  <xsl:variable name="row2" select="($prev and $navig.showtitles != 0)
964                                    or (generate-id($home) != generate-id(.)
965                                        or $nav.context = 'toc')
966                                    or ($chunk.tocs.and.lots != 0
967                                        and $nav.context != 'toc')
968                                    or ($next and $navig.showtitles != 0)"/>
969
970  <xsl:if test="$suppress.navigation = '0' and $suppress.footer.navigation = '0'">
971    <div class="navfooter">
972      <xsl:if test="$footer.rule != 0">
973        <hr/>
974      </xsl:if>
975
976      <xsl:if test="$row1 or $row2">
977        <table width="100%" summary="Navigation footer">
978          <xsl:if test="$row1">
979            <tr>
980              <td width="40%" align="left">
981                <xsl:if test="count($prev)>0">
982                  <a accesskey="p">
983                    <xsl:attribute name="href">
984                      <xsl:call-template name="href.target">
985                        <xsl:with-param name="object" select="$prev"/>
986                      </xsl:call-template>
987                    </xsl:attribute>
988                    <xsl:call-template name="navig.content">
989                      <xsl:with-param name="direction" select="'prev'"/>
990                    </xsl:call-template>
991                  </a>
992                </xsl:if>
993                <xsl:text>&#160;</xsl:text>
994              </td>
995              <td width="20%" align="center">
996                <xsl:choose>
997                  <xsl:when test="count($up)&gt;0
998                                  and generate-id($up) != generate-id($home)">
999                    <a accesskey="u">
1000                      <xsl:attribute name="href">
1001                        <xsl:call-template name="href.target">
1002                          <xsl:with-param name="object" select="$up"/>
1003                        </xsl:call-template>
1004                      </xsl:attribute>
1005                      <xsl:call-template name="navig.content">
1006                        <xsl:with-param name="direction" select="'up'"/>
1007                      </xsl:call-template>
1008                    </a>
1009                  </xsl:when>
1010                  <xsl:otherwise>&#160;</xsl:otherwise>
1011                </xsl:choose>
1012              </td>
1013              <td width="40%" align="right">
1014                <xsl:text>&#160;</xsl:text>
1015                <xsl:if test="count($next)>0">
1016                  <a accesskey="n">
1017                    <xsl:attribute name="href">
1018                      <xsl:call-template name="href.target">
1019                        <xsl:with-param name="object" select="$next"/>
1020                      </xsl:call-template>
1021                    </xsl:attribute>
1022                    <xsl:call-template name="navig.content">
1023                      <xsl:with-param name="direction" select="'next'"/>
1024                    </xsl:call-template>
1025                  </a>
1026                </xsl:if>
1027              </td>
1028            </tr>
1029          </xsl:if>
1030
1031          <xsl:if test="$row2">
1032            <tr>
1033              <td width="40%" align="left" valign="top">
1034                <xsl:if test="$navig.showtitles != 0">
1035                  <xsl:apply-templates select="$prev" mode="object.title.markup"/>
1036                </xsl:if>
1037                <xsl:text>&#160;</xsl:text>
1038              </td>
1039              <td width="20%" align="center">
1040                <xsl:choose>
1041                  <xsl:when test="$home != . or $nav.context = 'toc'">
1042                    <a accesskey="h">
1043                      <xsl:attribute name="href">
1044                        <xsl:call-template name="href.target">
1045                          <xsl:with-param name="object" select="$home"/>
1046                        </xsl:call-template>
1047                      </xsl:attribute>
1048                      <xsl:call-template name="navig.content">
1049                        <xsl:with-param name="direction" select="'home'"/>
1050                      </xsl:call-template>
1051                    </a>
1052                    <xsl:if test="$chunk.tocs.and.lots != 0 and $nav.context != 'toc'">
1053                      <xsl:text>&#160;|&#160;</xsl:text>
1054                    </xsl:if>
1055                  </xsl:when>
1056                  <xsl:otherwise>&#160;</xsl:otherwise>
1057                </xsl:choose>
1058
1059                <xsl:if test="$chunk.tocs.and.lots != 0 and $nav.context != 'toc'">
1060                  <a accesskey="t">
1061                    <xsl:attribute name="href">
1062                      <xsl:apply-templates select="/*[1]"
1063                                           mode="recursive-chunk-filename">
1064                        <xsl:with-param name="recursive" select="true()"/>
1065                      </xsl:apply-templates>
1066                      <xsl:text>-toc</xsl:text>
1067                      <xsl:value-of select="$html.ext"/>
1068                    </xsl:attribute>
1069                    <xsl:call-template name="gentext">
1070                      <xsl:with-param name="key" select="'nav-toc'"/>
1071                    </xsl:call-template>
1072                  </a>
1073                </xsl:if>
1074              </td>
1075              <td width="40%" align="right" valign="top">
1076                <xsl:text>&#160;</xsl:text>
1077                <xsl:if test="$navig.showtitles != 0">
1078                  <xsl:apply-templates select="$next" mode="object.title.markup"/>
1079                </xsl:if>
1080              </td>
1081            </tr>
1082          </xsl:if>
1083        </table>
1084      </xsl:if>
1085    </div>
1086  </xsl:if>
1087</xsl:template>
1088
1089<!-- ==================================================================== -->
1090
1091<xsl:template name="navig.content">
1092    <xsl:param name="direction" select="next"/>
1093    <xsl:variable name="navtext">
1094        <xsl:choose>
1095            <xsl:when test="$direction = 'prev'">
1096                <xsl:call-template name="gentext.nav.prev"/>
1097            </xsl:when>
1098            <xsl:when test="$direction = 'next'">
1099                <xsl:call-template name="gentext.nav.next"/>
1100            </xsl:when>
1101            <xsl:when test="$direction = 'up'">
1102                <xsl:call-template name="gentext.nav.up"/>
1103            </xsl:when>
1104            <xsl:when test="$direction = 'home'">
1105                <xsl:call-template name="gentext.nav.home"/>
1106            </xsl:when>
1107            <xsl:otherwise>
1108                <xsl:text>xxx</xsl:text>
1109            </xsl:otherwise>
1110        </xsl:choose>
1111    </xsl:variable>
1112
1113    <xsl:choose>
1114        <xsl:when test="$navig.graphics != 0">
1115            <img>
1116                <xsl:attribute name="src">
1117                    <xsl:value-of select="$navig.graphics.path"/>
1118                    <xsl:value-of select="$direction"/>
1119                    <xsl:value-of select="$navig.graphics.extension"/>
1120                </xsl:attribute>
1121                <xsl:attribute name="alt">
1122                    <xsl:value-of select="$navtext"/>
1123                </xsl:attribute>
1124            </img>
1125        </xsl:when>
1126        <xsl:otherwise>
1127            <xsl:value-of select="$navtext"/>
1128        </xsl:otherwise>
1129    </xsl:choose>
1130</xsl:template>
1131
1132<!-- ==================================================================== -->
1133
1134<!-- * The following template assumes that the first legalnotice -->
1135<!-- * instance found in a document applies to the contents of the -->
1136<!-- * entire document. It generates an HTML link in each chunk, back -->
1137<!-- * to the file containing the contents of the first legalnotice. -->
1138<!-- * -->
1139<!-- * Actually, it may generate multiple link instances in each chunk, -->
1140<!-- * because it walks through the space-separated list of link -->
1141<!-- * types specified in the $html.head.legalnotice.link.types param, -->
1142<!-- * popping off link types and generating links for them until it -->
1143<!-- * depletes the list. -->
1144 
1145<xsl:template name="make.legalnotice.head.links">
1146  <!-- * the following ID is used as part of the legalnotice filename; -->
1147  <!-- * we need it in order to construct the filename for use in the -->
1148  <!-- * value of the href attribute on the link -->
1149  <xsl:param name="id">
1150    <xsl:call-template name="object.id">
1151      <xsl:with-param name="object" select="(//legalnotice)[1]"/>
1152    </xsl:call-template>
1153  </xsl:param>
1154  <xsl:param name="linktype">
1155    <xsl:choose>
1156      <xsl:when test="contains($html.head.legalnotice.link.types, ' ')">
1157        <xsl:value-of
1158            select="normalize-space(
1159                    substring-before($html.head.legalnotice.link.types, ' '))"/>
1160      </xsl:when>
1161      <xsl:otherwise>
1162        <xsl:value-of select="$html.head.legalnotice.link.types"/>
1163      </xsl:otherwise>
1164    </xsl:choose>
1165  </xsl:param>
1166  <xsl:param
1167      name="remaining.linktypes"
1168      select="concat(
1169              normalize-space(
1170              substring-after($html.head.legalnotice.link.types, ' ')),' ')"/>
1171  <xsl:if test="not($linktype = '')">
1172    <link rel="{$linktype}">
1173      <xsl:attribute name="href">
1174        <xsl:value-of select="concat('ln-',$id,$html.ext)"/>
1175      </xsl:attribute>
1176      <xsl:attribute name="title">
1177        <xsl:apply-templates select="(//legalnotice)[1]"
1178                             mode="object.title.markup.textonly"/>
1179      </xsl:attribute>
1180    </link>
1181    <xsl:call-template name="make.legalnotice.head.links">
1182      <!-- * pop the next value off the list of link types -->
1183      <xsl:with-param
1184          name="linktype"
1185          select="substring-before($remaining.linktypes, ' ')"/>
1186      <!-- * remove the link type from the list of remaining link types -->
1187      <xsl:with-param
1188          name="remaining.linktypes"
1189          select="substring-after($remaining.linktypes, ' ')"/>
1190    </xsl:call-template>
1191  </xsl:if>
1192</xsl:template>
1193
1194<!-- ==================================================================== -->
1195
1196<xsl:template match="processing-instruction('dbhtml')">
1197  <!-- nop -->
1198</xsl:template>
1199
1200<!-- ==================================================================== -->
1201
1202<xsl:template name="chunk-element-content">
1203  <xsl:param name="prev"/>
1204  <xsl:param name="next"/>
1205  <xsl:param name="nav.context"/>
1206  <xsl:param name="content">
1207    <xsl:apply-imports/>
1208  </xsl:param>
1209
1210  <xsl:call-template name="user.preroot"/>
1211
1212  <html>
1213    <xsl:call-template name="html.head">
1214      <xsl:with-param name="prev" select="$prev"/>
1215      <xsl:with-param name="next" select="$next"/>
1216    </xsl:call-template>
1217
1218    <body>
1219      <xsl:call-template name="body.attributes"/>
1220      <xsl:call-template name="user.header.navigation"/>
1221
1222      <xsl:call-template name="header.navigation">
1223        <xsl:with-param name="prev" select="$prev"/>
1224        <xsl:with-param name="next" select="$next"/>
1225        <xsl:with-param name="nav.context" select="$nav.context"/>
1226      </xsl:call-template>
1227
1228      <xsl:call-template name="user.header.content"/>
1229
1230      <xsl:copy-of select="$content"/>
1231
1232      <xsl:call-template name="user.footer.content"/>
1233
1234      <xsl:call-template name="footer.navigation">
1235        <xsl:with-param name="prev" select="$prev"/>
1236        <xsl:with-param name="next" select="$next"/>
1237        <xsl:with-param name="nav.context" select="$nav.context"/>
1238      </xsl:call-template>
1239
1240      <xsl:call-template name="user.footer.navigation"/>
1241    </body>
1242  </html>
1243  <xsl:value-of select="$chunk.append"/>
1244</xsl:template>
1245
1246</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.