]> git.stg.codes - stg.git/blob - doc/xslt/html/chunk-common.xsl
Register smux plugin as .stg24, not as a root
[stg.git] / doc / xslt / html / chunk-common.xsl
1 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2                 xmlns:exsl="http://exslt.org/common"
3                 xmlns:cf="http://docbook.sourceforge.net/xmlns/chunkfast/1.0"
4                 xmlns:ng="http://docbook.org/docbook-ng"
5                 xmlns:db="http://docbook.org/ns/docbook"
6                 version="1.0"
7                 exclude-result-prefixes="exsl cf ng db">
8
9 <!-- ********************************************************************
10      $Id: chunk-common.xsl 8551 2009-12-07 06:03:50Z bobstayton $
11      ********************************************************************
12
13      This file is part of the XSL DocBook Stylesheet distribution.
14      See ../README or http://docbook.sf.net/release/xsl/current/ for
15      copyright and other information.
16
17      ******************************************************************** -->
18
19 <!-- ==================================================================== -->
20
21 <xsl:param name="onechunk" select="0"/>
22 <xsl:param name="refentry.separator" select="0"/>
23 <xsl:param name="chunk.fast" select="0"/>
24
25 <xsl:key name="genid" match="*" use="generate-id()"/>
26
27 <!-- ==================================================================== -->
28
29 <xsl:variable name="chunk.hierarchy">
30   <xsl:if test="$chunk.fast != 0">
31     <xsl:choose>
32       <xsl:when test="$exsl.node.set.available != 0">
33         <xsl:message>Computing chunks...</xsl:message>
34         <xsl:apply-templates select="/*" mode="find.chunks"/>
35       </xsl:when>
36       <xsl:otherwise>
37         <xsl:message>
38           <xsl:text>Fast chunking requires exsl:node-set(). </xsl:text>
39           <xsl:text>Using "slow" chunking.</xsl:text>
40         </xsl:message>
41       </xsl:otherwise>
42     </xsl:choose>
43   </xsl:if>
44 </xsl:variable>
45
46 <!-- ==================================================================== -->
47
48 <xsl:template name="process-chunk-element">
49   <xsl:param name="content">
50     <xsl:apply-imports/>
51   </xsl:param>
52
53   <xsl:choose>
54     <xsl:when test="$chunk.fast != 0 and $exsl.node.set.available != 0">
55       <xsl:variable name="chunks" select="exsl:node-set($chunk.hierarchy)//cf:div"/>
56       <xsl:variable name="genid" select="generate-id()"/>
57
58       <xsl:variable name="div" select="$chunks[@id=$genid or @xml:id=$genid]"/>
59
60       <xsl:variable name="prevdiv"
61                     select="($div/preceding-sibling::cf:div|$div/preceding::cf:div|$div/parent::cf:div)[last()]"/>
62       <xsl:variable name="prev" select="key('genid', ($prevdiv/@id|$prevdiv/@xml:id)[1])"/>
63
64       <xsl:variable name="nextdiv"
65                     select="($div/following-sibling::cf:div|$div/following::cf:div|$div/cf:div)[1]"/>
66       <xsl:variable name="next" select="key('genid', ($nextdiv/@id|$nextdiv/@xml:id)[1])"/>
67
68       <xsl:choose>
69         <xsl:when test="$onechunk != 0 and parent::*">
70           <xsl:copy-of select="$content"/>
71         </xsl:when>
72         <xsl:otherwise>
73           <xsl:call-template name="process-chunk">
74             <xsl:with-param name="prev" select="$prev"/>
75             <xsl:with-param name="next" select="$next"/>
76             <xsl:with-param name="content" select="$content"/>
77           </xsl:call-template>
78         </xsl:otherwise>
79       </xsl:choose>
80     </xsl:when>
81     <xsl:otherwise>
82       <xsl:choose>
83         <xsl:when test="$onechunk != 0 and not(parent::*)">
84           <xsl:call-template name="chunk-all-sections">
85             <xsl:with-param name="content" select="$content"/>
86           </xsl:call-template>
87         </xsl:when>
88         <xsl:when test="$onechunk != 0">
89           <xsl:copy-of select="$content"/>
90         </xsl:when>
91         <xsl:when test="$chunk.first.sections = 0">
92           <xsl:call-template name="chunk-first-section-with-parent">
93             <xsl:with-param name="content" select="$content"/>
94           </xsl:call-template>
95         </xsl:when>
96         <xsl:otherwise>
97           <xsl:call-template name="chunk-all-sections">
98             <xsl:with-param name="content" select="$content"/>
99           </xsl:call-template>
100         </xsl:otherwise>
101       </xsl:choose>
102     </xsl:otherwise>
103   </xsl:choose>
104 </xsl:template>
105
106 <xsl:template name="process-chunk">
107   <xsl:param name="prev" select="."/>
108   <xsl:param name="next" select="."/>
109   <xsl:param name="content">
110     <xsl:apply-imports/>
111   </xsl:param>
112
113   <xsl:variable name="ischunk">
114     <xsl:call-template name="chunk"/>
115   </xsl:variable>
116
117   <xsl:variable name="chunkfn">
118     <xsl:if test="$ischunk='1'">
119       <xsl:apply-templates mode="chunk-filename" select="."/>
120     </xsl:if>
121   </xsl:variable>
122
123   <xsl:if test="$ischunk='0'">
124     <xsl:message>
125       <xsl:text>Error </xsl:text>
126       <xsl:value-of select="name(.)"/>
127       <xsl:text> is not a chunk!</xsl:text>
128     </xsl:message>
129   </xsl:if>
130
131   <xsl:variable name="filename">
132     <xsl:call-template name="make-relative-filename">
133       <xsl:with-param name="base.dir" select="$base.dir"/>
134       <xsl:with-param name="base.name" select="$chunkfn"/>
135     </xsl:call-template>
136   </xsl:variable>
137
138   <xsl:call-template name="write.chunk">
139     <xsl:with-param name="filename" select="$filename"/>
140     <xsl:with-param name="content">
141       <xsl:call-template name="chunk-element-content">
142         <xsl:with-param name="prev" select="$prev"/>
143         <xsl:with-param name="next" select="$next"/>
144         <xsl:with-param name="content" select="$content"/>
145       </xsl:call-template>
146     </xsl:with-param>
147     <xsl:with-param name="quiet" select="$chunk.quietly"/>
148   </xsl:call-template>
149 </xsl:template>
150
151 <xsl:template name="chunk-first-section-with-parent">
152   <xsl:param name="content">
153     <xsl:apply-imports/>
154   </xsl:param>
155
156   <!-- These xpath expressions are really hairy. The trick is to pick sections -->
157   <!-- that are not first children and are not the children of first children -->
158
159   <!-- Break these variables into pieces to work around
160        http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6063 -->
161
162   <xsl:variable name="prev-v1"
163      select="(ancestor::sect1[$chunk.section.depth &gt; 0 
164                                    and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
165                                and preceding-sibling::sect1][1]
166
167              |ancestor::sect2[$chunk.section.depth &gt; 1
168                                and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
169                                and preceding-sibling::sect2
170                                and parent::sect1[preceding-sibling::sect1]][1]
171
172              |ancestor::sect3[$chunk.section.depth &gt; 2
173                                and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
174                                and preceding-sibling::sect3
175                                and parent::sect2[preceding-sibling::sect2]
176                                and ancestor::sect1[preceding-sibling::sect1]][1]
177
178              |ancestor::sect4[$chunk.section.depth &gt; 3
179                                and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
180                                and preceding-sibling::sect4
181                                and parent::sect3[preceding-sibling::sect3]
182                                and ancestor::sect2[preceding-sibling::sect2]
183                                and ancestor::sect1[preceding-sibling::sect1]][1]
184
185              |ancestor::sect5[$chunk.section.depth &gt; 4
186                                and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
187                                and preceding-sibling::sect5
188                                and parent::sect4[preceding-sibling::sect4]
189                                and ancestor::sect3[preceding-sibling::sect3]
190                                and ancestor::sect2[preceding-sibling::sect2]
191                                and ancestor::sect1[preceding-sibling::sect1]][1]
192
193              |ancestor::section[$chunk.section.depth &gt; count(ancestor::section)
194                                     and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
195                                 and not(ancestor::section[not(preceding-sibling::section)])][1])[last()]"/>
196
197   <xsl:variable name="prev-v2"
198      select="(preceding::sect1[$chunk.section.depth &gt; 0
199                                and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
200                                and preceding-sibling::sect1][1]
201
202              |preceding::sect2[$chunk.section.depth &gt; 1
203                                and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
204                                and preceding-sibling::sect2
205                                and parent::sect1[preceding-sibling::sect1]][1]
206
207              |preceding::sect3[$chunk.section.depth &gt; 2
208                                and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
209                                and preceding-sibling::sect3
210                                and parent::sect2[preceding-sibling::sect2]
211                                and ancestor::sect1[preceding-sibling::sect1]][1]
212
213              |preceding::sect4[$chunk.section.depth &gt; 3
214                                and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
215                                and preceding-sibling::sect4
216                                and parent::sect3[preceding-sibling::sect3]
217                                and ancestor::sect2[preceding-sibling::sect2]
218                                and ancestor::sect1[preceding-sibling::sect1]][1]
219
220              |preceding::sect5[$chunk.section.depth &gt; 4
221                                and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
222                                and preceding-sibling::sect5
223                                and parent::sect4[preceding-sibling::sect4]
224                                and ancestor::sect3[preceding-sibling::sect3]
225                                and ancestor::sect2[preceding-sibling::sect2]
226                                and ancestor::sect1[preceding-sibling::sect1]][1]
227
228              |preceding::section[$chunk.section.depth &gt; count(ancestor::section)
229                                      and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
230                                  and preceding-sibling::section
231                                  and not(ancestor::section[not(preceding-sibling::section)])][1])[last()]"/>
232
233   <xsl:variable name="prev"
234     select="(preceding::book[1]
235              |preceding::preface[1]
236              |preceding::chapter[1]
237              |preceding::appendix[1]
238              |preceding::part[1]
239              |preceding::reference[1]
240              |preceding::refentry[1]
241              |preceding::colophon[1]
242              |preceding::article[1]
243              |preceding::bibliography[parent::article or parent::book or parent::part][1]
244              |preceding::glossary[parent::article or parent::book or parent::part][1]
245              |preceding::index[$generate.index != 0]
246                                [parent::article or parent::book or parent::part][1]
247              |preceding::setindex[$generate.index != 0][1]
248              |ancestor::set
249              |ancestor::book[1]
250              |ancestor::preface[1]
251              |ancestor::chapter[1]
252              |ancestor::appendix[1]
253              |ancestor::part[1]
254              |ancestor::reference[1]
255              |ancestor::article[1]
256              |$prev-v1
257              |$prev-v2)[last()]"/>
258
259   <xsl:variable name="next-v1"
260     select="(following::sect1[$chunk.section.depth &gt; 0
261                                    and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
262                                and preceding-sibling::sect1][1]
263
264              |following::sect2[$chunk.section.depth &gt; 1
265                                    and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
266                                and preceding-sibling::sect2
267                                and parent::sect1[preceding-sibling::sect1]][1]
268
269              |following::sect3[$chunk.section.depth &gt; 2
270                                    and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
271                                and preceding-sibling::sect3
272                                and parent::sect2[preceding-sibling::sect2]
273                                and ancestor::sect1[preceding-sibling::sect1]][1]
274
275              |following::sect4[$chunk.section.depth &gt; 3
276                                    and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
277                                and preceding-sibling::sect4
278                                and parent::sect3[preceding-sibling::sect3]
279                                and ancestor::sect2[preceding-sibling::sect2]
280                                and ancestor::sect1[preceding-sibling::sect1]][1]
281
282              |following::sect5[$chunk.section.depth &gt; 4
283                                    and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
284                                and preceding-sibling::sect5
285                                and parent::sect4[preceding-sibling::sect4]
286                                and ancestor::sect3[preceding-sibling::sect3]
287                                and ancestor::sect2[preceding-sibling::sect2]
288                                and ancestor::sect1[preceding-sibling::sect1]][1]
289
290              |following::section[$chunk.section.depth &gt; count(ancestor::section)
291                                      and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
292                                  and preceding-sibling::section 
293                                  and not(ancestor::section[not(preceding-sibling::section)])][1])[1]"/>
294
295   <xsl:variable name="next-v2"
296     select="(descendant::sect1[$chunk.section.depth &gt; 0
297                                    and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
298                                and preceding-sibling::sect1][1]
299
300              |descendant::sect2[$chunk.section.depth &gt; 1
301                                    and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
302                                and preceding-sibling::sect2
303                                and parent::sect1[preceding-sibling::sect1]][1]
304
305              |descendant::sect3[$chunk.section.depth &gt; 2
306                                    and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
307                                and preceding-sibling::sect3
308                                and parent::sect2[preceding-sibling::sect2]
309                                and ancestor::sect1[preceding-sibling::sect1]][1]
310
311              |descendant::sect4[$chunk.section.depth &gt; 3
312                                    and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
313                                and preceding-sibling::sect4
314                                and parent::sect3[preceding-sibling::sect3]
315                                and ancestor::sect2[preceding-sibling::sect2]
316                                and ancestor::sect1[preceding-sibling::sect1]][1]
317
318              |descendant::sect5[$chunk.section.depth &gt; 4
319                                    and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
320                                and preceding-sibling::sect5
321                                and parent::sect4[preceding-sibling::sect4]
322                                and ancestor::sect3[preceding-sibling::sect3]
323                                and ancestor::sect2[preceding-sibling::sect2]
324                                and ancestor::sect1[preceding-sibling::sect1]][1]
325
326              |descendant::section[$chunk.section.depth &gt; count(ancestor::section)
327                                      and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
328                                  and preceding-sibling::section
329                                  and not(ancestor::section[not(preceding-sibling::section)])])[1]"/>
330
331   <xsl:variable name="next"
332     select="(following::book[1]
333              |following::preface[1]
334              |following::chapter[1]
335              |following::appendix[1]
336              |following::part[1]
337              |following::reference[1]
338              |following::refentry[1]
339              |following::colophon[1]
340              |following::bibliography[parent::article or parent::book or parent::part][1]
341              |following::glossary[parent::article or parent::book or parent::part][1]
342              |following::index[$generate.index != 0]
343                                [parent::article or parent::book or parent::part][1]
344              |following::article[1]
345              |following::setindex[$generate.index != 0][1]
346              |descendant::book[1]
347              |descendant::preface[1]
348              |descendant::chapter[1]
349              |descendant::appendix[1]
350              |descendant::article[1]
351              |descendant::bibliography[parent::article or parent::book or parent::part][1]
352              |descendant::glossary[parent::article or parent::book or parent::part][1]
353              |descendant::index[$generate.index != 0]
354                                [parent::article or parent::book or parent::part][1]
355              |descendant::colophon[1]
356              |descendant::setindex[$generate.index != 0][1]
357              |descendant::part[1]
358              |descendant::reference[1]
359              |descendant::refentry[1]
360              |$next-v1
361              |$next-v2)[1]"/>
362
363   <xsl:call-template name="process-chunk">
364     <xsl:with-param name="prev" select="$prev"/>
365     <xsl:with-param name="next" select="$next"/>
366     <xsl:with-param name="content" select="$content"/>
367   </xsl:call-template>
368 </xsl:template>
369
370 <xsl:template name="chunk-all-sections">
371   <xsl:param name="content">
372     <xsl:apply-imports/>
373   </xsl:param>
374
375   <xsl:variable name="prev-v1"
376     select="(preceding::sect1[$chunk.section.depth &gt; 0 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
377              |preceding::sect2[$chunk.section.depth &gt; 1 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
378              |preceding::sect3[$chunk.section.depth &gt; 2 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
379              |preceding::sect4[$chunk.section.depth &gt; 3 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
380              |preceding::sect5[$chunk.section.depth &gt; 4 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
381              |preceding::section[$chunk.section.depth &gt; count(ancestor::section) and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1])[last()]"/>
382
383   <xsl:variable name="prev-v2"
384     select="(ancestor::sect1[$chunk.section.depth &gt; 0 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
385              |ancestor::sect2[$chunk.section.depth &gt; 1 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
386              |ancestor::sect3[$chunk.section.depth &gt; 2 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
387              |ancestor::sect4[$chunk.section.depth &gt; 3 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
388              |ancestor::sect5[$chunk.section.depth &gt; 4 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
389              |ancestor::section[$chunk.section.depth &gt; count(ancestor::section) and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1])[last()]"/>
390
391   <xsl:variable name="prev"
392     select="(preceding::book[1]
393              |preceding::preface[1]
394              |preceding::chapter[1]
395              |preceding::appendix[1]
396              |preceding::part[1]
397              |preceding::reference[1]
398              |preceding::refentry[1]
399              |preceding::colophon[1]
400              |preceding::article[1]
401              |preceding::bibliography[parent::article or parent::book or parent::part][1]
402              |preceding::glossary[parent::article or parent::book or parent::part][1]
403              |preceding::index[$generate.index != 0]
404                                [parent::article or parent::book or parent::part][1]
405              |preceding::setindex[$generate.index != 0][1]
406              |ancestor::set
407              |ancestor::book[1]
408              |ancestor::preface[1]
409              |ancestor::chapter[1]
410              |ancestor::appendix[1]
411              |ancestor::part[1]
412              |ancestor::reference[1]
413              |ancestor::article[1]
414              |$prev-v1
415              |$prev-v2)[last()]"/>
416
417   <xsl:variable name="next-v1"
418     select="(following::sect1[$chunk.section.depth &gt; 0 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
419              |following::sect2[$chunk.section.depth &gt; 1 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
420              |following::sect3[$chunk.section.depth &gt; 2 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
421              |following::sect4[$chunk.section.depth &gt; 3 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
422              |following::sect5[$chunk.section.depth &gt; 4 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
423              |following::section[$chunk.section.depth &gt; count(ancestor::section) and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1])[1]"/>
424
425   <xsl:variable name="next-v2"
426     select="(descendant::sect1[$chunk.section.depth &gt; 0 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
427              |descendant::sect2[$chunk.section.depth &gt; 1 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
428              |descendant::sect3[$chunk.section.depth &gt; 2 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
429              |descendant::sect4[$chunk.section.depth &gt; 3 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
430              |descendant::sect5[$chunk.section.depth &gt; 4 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
431              |descendant::section[$chunk.section.depth 
432                                   &gt; count(ancestor::section) and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1])[1]"/>
433
434   <xsl:variable name="next"
435     select="(following::book[1]
436              |following::preface[1]
437              |following::chapter[1]
438              |following::appendix[1]
439              |following::part[1]
440              |following::reference[1]
441              |following::refentry[1]
442              |following::colophon[1]
443              |following::bibliography[parent::article or parent::book or parent::part][1]
444              |following::glossary[parent::article or parent::book or parent::part][1]
445              |following::index[$generate.index != 0]
446                                [parent::article or parent::book][1]
447              |following::article[1]
448              |following::setindex[$generate.index != 0][1]
449              |descendant::book[1]
450              |descendant::preface[1]
451              |descendant::chapter[1]
452              |descendant::appendix[1]
453              |descendant::article[1]
454              |descendant::bibliography[parent::article or parent::book][1]
455              |descendant::glossary[parent::article or parent::book or parent::part][1]
456              |descendant::index[$generate.index != 0]
457                                [parent::article or parent::book][1]
458              |descendant::colophon[1]
459              |descendant::setindex[$generate.index != 0][1]
460              |descendant::part[1]
461              |descendant::reference[1]
462              |descendant::refentry[1]
463              |$next-v1
464              |$next-v2)[1]"/>
465
466   <xsl:call-template name="process-chunk">
467     <xsl:with-param name="prev" select="$prev"/>
468     <xsl:with-param name="next" select="$next"/>
469     <xsl:with-param name="content" select="$content"/>
470   </xsl:call-template>
471 </xsl:template>
472
473 <!-- ==================================================================== -->
474
475 <!-- ==================================================================== -->
476
477 <xsl:template name="make.lots">
478   <xsl:param name="toc.params" select="''"/>
479   <xsl:param name="toc"/>
480
481   <xsl:variable name="lots">
482     <xsl:if test="contains($toc.params, 'toc')">
483       <xsl:copy-of select="$toc"/>
484     </xsl:if>
485
486     <xsl:if test="contains($toc.params, 'figure')">
487       <xsl:choose>
488         <xsl:when test="$chunk.separate.lots != '0'">
489           <xsl:call-template name="make.lot.chunk">
490             <xsl:with-param name="type" select="'figure'"/>
491             <xsl:with-param name="lot">
492               <xsl:call-template name="list.of.titles">
493                 <xsl:with-param name="titles" select="'figure'"/>
494                 <xsl:with-param name="nodes" select=".//figure"/>
495               </xsl:call-template>
496             </xsl:with-param>
497           </xsl:call-template>
498         </xsl:when>
499         <xsl:otherwise>
500           <xsl:call-template name="list.of.titles">
501             <xsl:with-param name="titles" select="'figure'"/>
502             <xsl:with-param name="nodes" select=".//figure"/>
503           </xsl:call-template>
504         </xsl:otherwise>
505       </xsl:choose>
506     </xsl:if>
507
508     <xsl:if test="contains($toc.params, 'table')">
509       <xsl:choose>
510         <xsl:when test="$chunk.separate.lots != '0'">
511           <xsl:call-template name="make.lot.chunk">
512             <xsl:with-param name="type" select="'table'"/>
513             <xsl:with-param name="lot">
514               <xsl:call-template name="list.of.titles">
515                 <xsl:with-param name="titles" select="'table'"/>
516                 <xsl:with-param name="nodes" select=".//table"/>
517               </xsl:call-template>
518             </xsl:with-param>
519           </xsl:call-template>
520         </xsl:when>
521         <xsl:otherwise>
522           <xsl:call-template name="list.of.titles">
523             <xsl:with-param name="titles" select="'table'"/>
524             <xsl:with-param name="nodes" select=".//table"/>
525           </xsl:call-template>
526         </xsl:otherwise>
527       </xsl:choose>
528     </xsl:if>
529
530     <xsl:if test="contains($toc.params, 'example')">
531       <xsl:choose>
532         <xsl:when test="$chunk.separate.lots != '0'">
533           <xsl:call-template name="make.lot.chunk">
534             <xsl:with-param name="type" select="'example'"/>
535             <xsl:with-param name="lot">
536               <xsl:call-template name="list.of.titles">
537                 <xsl:with-param name="titles" select="'example'"/>
538                 <xsl:with-param name="nodes" select=".//example"/>
539               </xsl:call-template>
540             </xsl:with-param>
541           </xsl:call-template>
542         </xsl:when>
543         <xsl:otherwise>
544           <xsl:call-template name="list.of.titles">
545             <xsl:with-param name="titles" select="'example'"/>
546             <xsl:with-param name="nodes" select=".//example"/>
547           </xsl:call-template>
548         </xsl:otherwise>
549       </xsl:choose>
550     </xsl:if>
551
552     <xsl:if test="contains($toc.params, 'equation')">
553       <xsl:choose>
554         <xsl:when test="$chunk.separate.lots != '0'">
555           <xsl:call-template name="make.lot.chunk">
556             <xsl:with-param name="type" select="'equation'"/>
557             <xsl:with-param name="lot">
558               <xsl:call-template name="list.of.titles">
559                 <xsl:with-param name="titles" select="'equation'"/>
560                 <xsl:with-param name="nodes" select=".//equation[title or info/title]"/>
561               </xsl:call-template>
562             </xsl:with-param>
563           </xsl:call-template>
564         </xsl:when>
565         <xsl:otherwise>
566           <xsl:call-template name="list.of.titles">
567             <xsl:with-param name="titles" select="'equation'"/>
568             <xsl:with-param name="nodes" select=".//equation[title or info/title]"/>
569           </xsl:call-template>
570         </xsl:otherwise>
571       </xsl:choose>
572     </xsl:if>
573
574     <xsl:if test="contains($toc.params, 'procedure')">
575       <xsl:choose>
576         <xsl:when test="$chunk.separate.lots != '0'">
577           <xsl:call-template name="make.lot.chunk">
578             <xsl:with-param name="type" select="'procedure'"/>
579             <xsl:with-param name="lot">
580               <xsl:call-template name="list.of.titles">
581                 <xsl:with-param name="titles" select="'procedure'"/>
582                 <xsl:with-param name="nodes" select=".//procedure[title]"/>
583               </xsl:call-template>
584             </xsl:with-param>
585           </xsl:call-template>
586         </xsl:when>
587         <xsl:otherwise>
588           <xsl:call-template name="list.of.titles">
589             <xsl:with-param name="titles" select="'procedure'"/>
590             <xsl:with-param name="nodes" select=".//procedure[title]"/>
591           </xsl:call-template>
592         </xsl:otherwise>
593       </xsl:choose>
594     </xsl:if>
595   </xsl:variable>
596
597   <xsl:if test="string($lots) != ''">
598     <xsl:choose>
599       <xsl:when test="$chunk.tocs.and.lots != 0 and not(parent::*)">
600         <xsl:call-template name="write.chunk">
601           <xsl:with-param name="filename">
602             <xsl:call-template name="make-relative-filename">
603               <xsl:with-param name="base.dir" select="$base.dir"/>
604               <xsl:with-param name="base.name">
605                 <xsl:call-template name="dbhtml-dir"/>
606                 <xsl:apply-templates select="." mode="recursive-chunk-filename">
607                   <xsl:with-param name="recursive" select="true()"/>
608                 </xsl:apply-templates>
609                 <xsl:text>-toc</xsl:text>
610                 <xsl:value-of select="$html.ext"/>
611               </xsl:with-param>
612             </xsl:call-template>
613           </xsl:with-param>
614           <xsl:with-param name="content">
615             <xsl:call-template name="chunk-element-content">
616               <xsl:with-param name="prev" select="/foo"/>
617               <xsl:with-param name="next" select="/foo"/>
618               <xsl:with-param name="nav.context" select="'toc'"/>
619               <xsl:with-param name="content">
620                 <xsl:if test="$chunk.tocs.and.lots.has.title != 0">
621                   <h1>
622                     <xsl:apply-templates select="." mode="object.title.markup"/>
623                   </h1>
624                 </xsl:if>
625                 <xsl:copy-of select="$lots"/>
626               </xsl:with-param>
627             </xsl:call-template>
628           </xsl:with-param>
629           <xsl:with-param name="quiet" select="$chunk.quietly"/>
630         </xsl:call-template>
631       </xsl:when>
632       <xsl:otherwise>
633         <xsl:copy-of select="$lots"/>
634       </xsl:otherwise>
635     </xsl:choose>
636   </xsl:if>
637 </xsl:template>
638
639 <xsl:template name="make.lot.chunk">
640   <xsl:param name="type" select="''"/>
641   <xsl:param name="lot"/>
642
643   <xsl:if test="string($lot) != ''">
644     <xsl:variable name="filename">
645       <xsl:call-template name="make-relative-filename">
646         <xsl:with-param name="base.dir" select="$base.dir"/>
647         <xsl:with-param name="base.name">
648           <xsl:call-template name="dbhtml-dir"/>
649           <xsl:value-of select="$type"/>
650           <xsl:text>-toc</xsl:text>
651           <xsl:value-of select="$html.ext"/>
652         </xsl:with-param>
653       </xsl:call-template>
654     </xsl:variable>
655
656     <xsl:variable name="href">
657       <xsl:call-template name="make-relative-filename">
658         <xsl:with-param name="base.name">
659           <xsl:call-template name="dbhtml-dir"/>
660           <xsl:value-of select="$type"/>
661           <xsl:text>-toc</xsl:text>
662           <xsl:value-of select="$html.ext"/>
663         </xsl:with-param>
664       </xsl:call-template>
665     </xsl:variable>
666
667     <xsl:call-template name="write.chunk">
668       <xsl:with-param name="filename" select="$filename"/>
669       <xsl:with-param name="content">
670         <xsl:call-template name="chunk-element-content">
671           <xsl:with-param name="prev" select="/foo"/>
672           <xsl:with-param name="next" select="/foo"/>
673           <xsl:with-param name="nav.context" select="'toc'"/>
674           <xsl:with-param name="content">
675             <xsl:copy-of select="$lot"/>
676           </xsl:with-param>
677         </xsl:call-template>
678       </xsl:with-param>
679       <xsl:with-param name="quiet" select="$chunk.quietly"/>
680     </xsl:call-template>
681     <!-- And output a link to this file -->
682     <div>
683       <xsl:attribute name="class">
684         <xsl:text>ListofTitles</xsl:text>
685       </xsl:attribute>
686       <a href="{$href}">
687         <xsl:call-template name="gentext">
688           <xsl:with-param name="key">
689             <xsl:choose>
690               <xsl:when test="$type='table'">ListofTables</xsl:when>
691               <xsl:when test="$type='figure'">ListofFigures</xsl:when>
692               <xsl:when test="$type='equation'">ListofEquations</xsl:when>
693               <xsl:when test="$type='example'">ListofExamples</xsl:when>
694               <xsl:when test="$type='procedure'">ListofProcedures</xsl:when>
695               <xsl:otherwise>ListofUnknown</xsl:otherwise>
696             </xsl:choose>
697           </xsl:with-param>
698         </xsl:call-template>
699       </a>
700     </div>
701   </xsl:if>
702 </xsl:template>
703
704 <!-- ==================================================================== -->
705
706 <xsl:template name="in.other.chunk">
707   <xsl:param name="chunk" select="."/>
708   <xsl:param name="node" select="."/>
709
710   <xsl:variable name="is.chunk">
711     <xsl:call-template name="chunk">
712       <xsl:with-param name="node" select="$node"/>
713     </xsl:call-template>
714   </xsl:variable>
715
716 <!--
717   <xsl:message>
718     <xsl:text>in.other.chunk: </xsl:text>
719     <xsl:value-of select="name($chunk)"/>
720     <xsl:text> </xsl:text>
721     <xsl:value-of select="name($node)"/>
722     <xsl:text> </xsl:text>
723     <xsl:value-of select="$chunk = $node"/>
724     <xsl:text> </xsl:text>
725     <xsl:value-of select="$is.chunk"/>
726   </xsl:message>
727 -->
728
729   <xsl:choose>
730     <xsl:when test="$chunk = $node">0</xsl:when>
731     <xsl:when test="$is.chunk = 1">1</xsl:when>
732     <xsl:when test="count($node) = 0">0</xsl:when>
733     <xsl:otherwise>
734       <xsl:call-template name="in.other.chunk">
735         <xsl:with-param name="chunk" select="$chunk"/>
736         <xsl:with-param name="node" select="$node/parent::*"/>
737       </xsl:call-template>
738     </xsl:otherwise>
739   </xsl:choose>
740 </xsl:template>
741
742 <xsl:template name="count.footnotes.in.this.chunk">
743   <xsl:param name="node" select="."/>
744   <xsl:param name="footnotes" select="$node//footnote"/>
745   <xsl:param name="count" select="0"/>
746
747 <!--
748   <xsl:message>
749     <xsl:text>count.footnotes.in.this.chunk: </xsl:text>
750     <xsl:value-of select="name($node)"/>
751   </xsl:message>
752 -->
753
754   <xsl:variable name="in.other.chunk">
755     <xsl:call-template name="in.other.chunk">
756       <xsl:with-param name="chunk" select="$node"/>
757       <xsl:with-param name="node" select="$footnotes[1]"/>
758     </xsl:call-template>
759   </xsl:variable>
760
761   <xsl:choose>
762     <xsl:when test="count($footnotes) = 0">
763       <xsl:value-of select="$count"/>
764     </xsl:when>
765     <xsl:otherwise>
766       <xsl:choose>
767         <xsl:when test="$in.other.chunk != 0">
768           <xsl:call-template name="count.footnotes.in.this.chunk">
769             <xsl:with-param name="node" select="$node"/>
770             <xsl:with-param name="footnotes"
771                             select="$footnotes[position() &gt; 1]"/>
772             <xsl:with-param name="count" select="$count"/>
773           </xsl:call-template>
774         </xsl:when>
775         <xsl:when test="$footnotes[1]/ancestor::table
776                         |$footnotes[1]/ancestor::informaltable">
777           <xsl:call-template name="count.footnotes.in.this.chunk">
778             <xsl:with-param name="node" select="$node"/>
779             <xsl:with-param name="footnotes"
780                             select="$footnotes[position() &gt; 1]"/>
781             <xsl:with-param name="count" select="$count"/>
782           </xsl:call-template>
783         </xsl:when>
784         <xsl:otherwise>
785           <xsl:call-template name="count.footnotes.in.this.chunk">
786             <xsl:with-param name="node" select="$node"/>
787             <xsl:with-param name="footnotes"
788                             select="$footnotes[position() &gt; 1]"/>
789             <xsl:with-param name="count" select="$count + 1"/>
790           </xsl:call-template>
791         </xsl:otherwise>
792       </xsl:choose>
793     </xsl:otherwise>
794   </xsl:choose>
795 </xsl:template>
796
797 <xsl:template name="process.footnotes.in.this.chunk">
798   <xsl:param name="node" select="."/>
799   <xsl:param name="footnotes" select="$node//footnote"/>
800
801 <!--
802   <xsl:message>process.footnotes.in.this.chunk</xsl:message>
803 -->
804
805   <xsl:variable name="in.other.chunk">
806     <xsl:call-template name="in.other.chunk">
807       <xsl:with-param name="chunk" select="$node"/>
808       <xsl:with-param name="node" select="$footnotes[1]"/>
809     </xsl:call-template>
810   </xsl:variable>
811
812   <xsl:choose>
813     <xsl:when test="count($footnotes) = 0">
814       <!-- nop -->
815     </xsl:when>
816     <xsl:otherwise>
817       <xsl:choose>
818         <xsl:when test="$in.other.chunk != 0">
819           <xsl:call-template name="process.footnotes.in.this.chunk">
820             <xsl:with-param name="node" select="$node"/>
821             <xsl:with-param name="footnotes"
822                             select="$footnotes[position() &gt; 1]"/>
823           </xsl:call-template>
824         </xsl:when>
825         <xsl:when test="$footnotes[1]/ancestor::table
826                         |$footnotes[1]/ancestor::informaltable">
827           <xsl:call-template name="process.footnotes.in.this.chunk">
828             <xsl:with-param name="node" select="$node"/>
829             <xsl:with-param name="footnotes"
830                             select="$footnotes[position() &gt; 1]"/>
831           </xsl:call-template>
832         </xsl:when>
833         <xsl:otherwise>
834           <xsl:apply-templates select="$footnotes[1]"
835                                mode="process.footnote.mode"/>
836           <xsl:call-template name="process.footnotes.in.this.chunk">
837             <xsl:with-param name="node" select="$node"/>
838             <xsl:with-param name="footnotes"
839                             select="$footnotes[position() &gt; 1]"/>
840           </xsl:call-template>
841         </xsl:otherwise>
842       </xsl:choose>
843     </xsl:otherwise>
844   </xsl:choose>
845 </xsl:template>
846
847 <xsl:template name="process.footnotes">
848   <xsl:variable name="footnotes" select=".//footnote"/>
849   <xsl:variable name="fcount">
850     <xsl:call-template name="count.footnotes.in.this.chunk">
851       <xsl:with-param name="node" select="."/>
852       <xsl:with-param name="footnotes" select="$footnotes"/>
853     </xsl:call-template>
854   </xsl:variable>
855
856 <!--
857   <xsl:message>
858     <xsl:value-of select="name(.)"/>
859     <xsl:text> fcount: </xsl:text>
860     <xsl:value-of select="$fcount"/>
861   </xsl:message>
862 -->
863
864   <!-- Only bother to do this if there's at least one non-table footnote -->
865   <xsl:if test="$fcount &gt; 0">
866     <div class="footnotes">
867       <br/>
868       <hr width="100" align="{$direction.align.start}"/>
869       <xsl:call-template name="process.footnotes.in.this.chunk">
870         <xsl:with-param name="node" select="."/>
871         <xsl:with-param name="footnotes" select="$footnotes"/>
872       </xsl:call-template>
873     </div>
874   </xsl:if>
875
876   <!-- FIXME: When chunking, only the annotations actually used
877               in this chunk should be referenced. I don't think it
878               does any harm to reference them all, but it adds
879               unnecessary bloat to each chunk. -->
880   <xsl:if test="$annotation.support != 0 and //annotation">
881     <div class="annotation-list">
882       <div class="annotation-nocss">
883         <p>The following annotations are from this essay. You are seeing
884         them here because your browser doesn’t support the user-interface
885         techniques used to make them appear as â€˜popups’ on modern browsers.</p>
886       </div>
887
888       <xsl:apply-templates select="//annotation"
889                            mode="annotation-popup"/>
890     </div>
891   </xsl:if>
892 </xsl:template>
893
894 <xsl:template name="process.chunk.footnotes">
895   <xsl:variable name="is.chunk">
896     <xsl:call-template name="chunk"/>
897   </xsl:variable>
898   <xsl:if test="$is.chunk = 1">
899     <xsl:call-template name="process.footnotes"/>
900   </xsl:if>
901 </xsl:template>
902
903 <!-- ====================================================================== -->
904
905 <xsl:template name="chunk">
906   <xsl:param name="node" select="."/>
907   <!-- returns 1 if $node is a chunk -->
908
909   <!-- ==================================================================== -->
910   <!-- What's a chunk?
911
912        The root element
913        appendix
914        article
915        bibliography  in article or part or book
916        book
917        chapter
918        colophon
919        glossary      in article or part or book
920        index         in article or part or book
921        part
922        preface
923        refentry
924        reference
925        sect{1,2,3,4,5}  if position()>1 && depth < chunk.section.depth
926        section          if position()>1 && depth < chunk.section.depth
927        set
928        setindex
929                                                                             -->
930   <!-- ==================================================================== -->
931
932 <!--
933   <xsl:message>
934     <xsl:text>chunk: </xsl:text>
935     <xsl:value-of select="name($node)"/>
936     <xsl:text>(</xsl:text>
937     <xsl:value-of select="$node/@id"/>
938     <xsl:text>)</xsl:text>
939     <xsl:text> csd: </xsl:text>
940     <xsl:value-of select="$chunk.section.depth"/>
941     <xsl:text> cfs: </xsl:text>
942     <xsl:value-of select="$chunk.first.sections"/>
943     <xsl:text> ps: </xsl:text>
944     <xsl:value-of select="count($node/parent::section)"/>
945     <xsl:text> prs: </xsl:text>
946     <xsl:value-of select="count($node/preceding-sibling::section)"/>
947   </xsl:message>
948 -->
949
950   <xsl:choose>
951           <xsl:when test="$node/parent::*/processing-instruction('dbhtml')[normalize-space(.) = 'stop-chunking']">0</xsl:when>
952     <xsl:when test="not($node/parent::*)">1</xsl:when>
953
954     <xsl:when test="local-name($node) = 'sect1'
955                     and $chunk.section.depth &gt;= 1
956                     and ($chunk.first.sections != 0
957                          or count($node/preceding-sibling::sect1) &gt; 0)">
958       <xsl:text>1</xsl:text>
959     </xsl:when>
960     <xsl:when test="local-name($node) = 'sect2'
961                     and $chunk.section.depth &gt;= 2
962                     and ($chunk.first.sections != 0
963                          or count($node/preceding-sibling::sect2) &gt; 0)">
964       <xsl:call-template name="chunk">
965         <xsl:with-param name="node" select="$node/parent::*"/>
966       </xsl:call-template>
967     </xsl:when>
968     <xsl:when test="local-name($node) = 'sect3'
969                     and $chunk.section.depth &gt;= 3
970                     and ($chunk.first.sections != 0
971                          or count($node/preceding-sibling::sect3) &gt; 0)">
972       <xsl:call-template name="chunk">
973         <xsl:with-param name="node" select="$node/parent::*"/>
974       </xsl:call-template>
975     </xsl:when>
976     <xsl:when test="local-name($node) = 'sect4'
977                     and $chunk.section.depth &gt;= 4
978                     and ($chunk.first.sections != 0
979                          or count($node/preceding-sibling::sect4) &gt; 0)">
980       <xsl:call-template name="chunk">
981         <xsl:with-param name="node" select="$node/parent::*"/>
982       </xsl:call-template>
983     </xsl:when>
984     <xsl:when test="local-name($node) = 'sect5'
985                     and $chunk.section.depth &gt;= 5
986                     and ($chunk.first.sections != 0
987                          or count($node/preceding-sibling::sect5) &gt; 0)">
988       <xsl:call-template name="chunk">
989         <xsl:with-param name="node" select="$node/parent::*"/>
990       </xsl:call-template>
991     </xsl:when>
992     <xsl:when test="local-name($node) = 'section'
993                     and $chunk.section.depth &gt;= count($node/ancestor::section)+1
994                     and ($chunk.first.sections != 0
995                          or count($node/preceding-sibling::section) &gt; 0)">
996       <xsl:call-template name="chunk">
997         <xsl:with-param name="node" select="$node/parent::*"/>
998       </xsl:call-template>
999     </xsl:when>
1000
1001     <xsl:when test="local-name($node)='preface'">1</xsl:when>
1002     <xsl:when test="local-name($node)='chapter'">1</xsl:when>
1003     <xsl:when test="local-name($node)='appendix'">1</xsl:when>
1004     <xsl:when test="local-name($node)='article'">1</xsl:when>
1005     <xsl:when test="local-name($node)='part'">1</xsl:when>
1006     <xsl:when test="local-name($node)='reference'">1</xsl:when>
1007     <xsl:when test="local-name($node)='refentry'">1</xsl:when>
1008     <xsl:when test="local-name($node)='index' and ($generate.index != 0 or count($node/*) > 0)
1009                     and (local-name($node/parent::*) = 'article'
1010                     or local-name($node/parent::*) = 'book'
1011                     or local-name($node/parent::*) = 'part'
1012                     )">1</xsl:when>
1013     <xsl:when test="local-name($node)='bibliography'
1014                     and (local-name($node/parent::*) = 'article'
1015                     or local-name($node/parent::*) = 'book'
1016                     or local-name($node/parent::*) = 'part'
1017                     )">1</xsl:when>
1018     <xsl:when test="local-name($node)='glossary'
1019                     and (local-name($node/parent::*) = 'article'
1020                     or local-name($node/parent::*) = 'book'
1021                     or local-name($node/parent::*) = 'part'
1022                     )">1</xsl:when>
1023     <xsl:when test="local-name($node)='colophon'">1</xsl:when>
1024     <xsl:when test="local-name($node)='book'">1</xsl:when>
1025     <xsl:when test="local-name($node)='set'">1</xsl:when>
1026     <xsl:when test="local-name($node)='setindex'">1</xsl:when>
1027     <xsl:when test="local-name($node)='legalnotice'
1028                     and $generate.legalnotice.link != 0">1</xsl:when>
1029     <xsl:otherwise>0</xsl:otherwise>
1030   </xsl:choose>
1031 </xsl:template>
1032
1033 <!-- ==================================================================== -->
1034 <xsl:template name="href.target.uri">
1035   <xsl:param name="object" select="."/>
1036   <xsl:variable name="ischunk">
1037     <xsl:call-template name="chunk">
1038       <xsl:with-param name="node" select="$object"/>
1039     </xsl:call-template>
1040   </xsl:variable>
1041
1042   <xsl:apply-templates mode="chunk-filename" select="$object"/>
1043
1044   <xsl:if test="$ischunk='0'">
1045     <xsl:text>#</xsl:text>
1046     <xsl:call-template name="object.id">
1047       <xsl:with-param name="object" select="$object"/>
1048     </xsl:call-template>
1049   </xsl:if>
1050 </xsl:template>
1051
1052 <xsl:template name="href.target">
1053   <xsl:param name="context" select="."/>
1054   <xsl:param name="object" select="."/>
1055   <xsl:param name="toc-context" select="."/>
1056   <!-- * If $toc-context contains some node other than the current node, -->
1057   <!-- * it means we're processing a link in a TOC. In that case, to -->
1058   <!-- * ensure the link will work correctly, we need to take a look at -->
1059   <!-- * where the file containing the TOC will get written, and where -->
1060   <!-- * the file that's being linked to will get written. -->
1061   <xsl:variable name="toc-output-dir">
1062     <xsl:if test="not($toc-context = .)">
1063       <!-- * Get the $toc-context node and all its ancestors, look down -->
1064       <!-- * through them to find the last/closest node to the -->
1065       <!-- * toc-context node that has a "dbhtml dir" PI, and get the -->
1066       <!-- * directory name from that. That's the name of the directory -->
1067       <!-- * to which the current toc output file will get written. -->
1068       <xsl:call-template name="dbhtml-dir">
1069         <xsl:with-param name="context"
1070           select="$toc-context/ancestor-or-self::*[processing-instruction('dbhtml')[contains(.,'dir')]][last()]"/>
1071       </xsl:call-template>
1072     </xsl:if>
1073   </xsl:variable>
1074   <xsl:variable name="linked-file-output-dir">
1075     <xsl:if test="not($toc-context = .)">
1076       <!-- * Get the current node and all its ancestors, look down -->
1077       <!-- * through them to find the last/closest node to the current -->
1078       <!-- * node that has a "dbhtml dir" PI, and get the directory name -->
1079       <!-- * from that.  That's the name of the directory to which the -->
1080       <!-- * file that's being linked to will get written. -->
1081       <xsl:call-template name="dbhtml-dir">
1082         <xsl:with-param name="context"
1083           select="ancestor-or-self::*[processing-instruction('dbhtml')[contains(.,'dir')]][last()]"/>
1084       </xsl:call-template>
1085     </xsl:if>
1086   </xsl:variable>
1087   <xsl:variable name="href.to.uri">
1088     <xsl:call-template name="href.target.uri">
1089       <xsl:with-param name="object" select="$object"/>
1090     </xsl:call-template>
1091   </xsl:variable>
1092   <xsl:variable name="href.from.uri">
1093     <xsl:choose>
1094       <xsl:when test="not($toc-context = .)">
1095         <xsl:call-template name="href.target.uri">
1096           <xsl:with-param name="object" select="$toc-context"/>
1097         </xsl:call-template>
1098       </xsl:when>
1099       <xsl:otherwise>
1100         <xsl:call-template name="href.target.uri">
1101           <xsl:with-param name="object" select="$context"/>
1102         </xsl:call-template>
1103       </xsl:otherwise>
1104     </xsl:choose>
1105   </xsl:variable>
1106   <!-- * <xsl:message>toc-context: <xsl:value-of select="local-name($toc-context)"/></xsl:message> -->
1107   <!-- * <xsl:message>node: <xsl:value-of select="local-name(.)"/></xsl:message> -->
1108   <!-- * <xsl:message>context: <xsl:value-of select="local-name($context)"/></xsl:message> -->
1109   <!-- * <xsl:message>object: <xsl:value-of select="local-name($object)"/></xsl:message> -->
1110   <!-- * <xsl:message>toc-output-dir: <xsl:value-of select="$toc-output-dir"/></xsl:message> -->
1111   <!-- * <xsl:message>linked-file-output-dir: <xsl:value-of select="$linked-file-output-dir"/></xsl:message> -->
1112   <!-- * <xsl:message>href.to.uri: <xsl:value-of select="$href.to.uri"/></xsl:message> -->
1113   <!-- * <xsl:message>href.from.uri: <xsl:value-of select="$href.from.uri"/></xsl:message> -->
1114   <xsl:variable name="href.to">
1115     <xsl:choose>
1116       <!-- * 2007-07-19, MikeSmith: Added the following conditional to -->
1117       <!-- * deal with a problem case for links in TOCs. It checks to see -->
1118       <!-- * if the output dir that a TOC will get written to is -->
1119       <!-- * different from the output dir of the file being linked to. -->
1120       <!-- * If it is different, we do not call trim.common.uri.paths. -->
1121       <!-- *  -->
1122       <!-- * Reason why I added that conditional is: I ran into a bug for -->
1123       <!-- * this case: -->
1124       <!-- *  -->
1125       <!-- * 1. we are chunking into separate dirs -->
1126       <!-- *  -->
1127       <!-- * 2. output for the TOC is written to current dir, but the file -->
1128       <!-- *    being linked to is written to some subdir "foo". -->
1129       <!-- *  -->
1130       <!-- * For that case, links to that file in that TOC did not show -->
1131       <!-- * the correct path - they omitted the "foo". -->
1132       <!-- *  -->
1133       <!-- * The cause of that problem was that the trim.common.uri.paths -->
1134       <!-- * template[1] was being called under all conditions. But it's -->
1135       <!-- * apparent that we don't want to call trim.common.uri.paths in -->
1136       <!-- * the case where a linked file is being written to a different -->
1137       <!-- * directory than the TOC that contains the link, because doing -->
1138       <!-- * so will cause a necessary (not redundant) directory-name -->
1139       <!-- * part of the link to get inadvertently trimmed, resulting in -->
1140       <!-- * a broken link to that file. Thus, added the conditional. -->
1141       <!-- *  -->
1142       <!-- * [1] The purpose of the trim.common.uri.paths template is to -->
1143       <!-- * prevent cases where, if we didn't call it, we end up with -->
1144       <!-- * unnecessary, redundant directory names getting output; for -->
1145       <!-- * example, "foo/foo/refname.html". -->
1146       <xsl:when test="not($toc-output-dir = $linked-file-output-dir)">
1147         <xsl:value-of select="$href.to.uri"/>
1148       </xsl:when>
1149       <xsl:otherwise>
1150         <xsl:call-template name="trim.common.uri.paths">
1151           <xsl:with-param name="uriA" select="$href.to.uri"/>
1152           <xsl:with-param name="uriB" select="$href.from.uri"/>
1153           <xsl:with-param name="return" select="'A'"/>
1154         </xsl:call-template>
1155       </xsl:otherwise>
1156     </xsl:choose>
1157   </xsl:variable>
1158   <xsl:variable name="href.from">
1159     <xsl:call-template name="trim.common.uri.paths">
1160       <xsl:with-param name="uriA" select="$href.to.uri"/>
1161       <xsl:with-param name="uriB" select="$href.from.uri"/>
1162       <xsl:with-param name="return" select="'B'"/>
1163     </xsl:call-template>
1164   </xsl:variable>
1165   <xsl:variable name="depth">
1166     <xsl:call-template name="count.uri.path.depth">
1167       <xsl:with-param name="filename" select="$href.from"/>
1168     </xsl:call-template>
1169   </xsl:variable>
1170   <xsl:variable name="href">
1171     <xsl:call-template name="copy-string">
1172       <xsl:with-param name="string" select="'../'"/>
1173       <xsl:with-param name="count" select="$depth"/>
1174     </xsl:call-template>
1175     <xsl:value-of select="$href.to"/>
1176   </xsl:variable>
1177   <!--
1178   <xsl:message>
1179     <xsl:text>In </xsl:text>
1180     <xsl:value-of select="name(.)"/>
1181     <xsl:text> (</xsl:text>
1182     <xsl:value-of select="$href.from"/>
1183     <xsl:text>,</xsl:text>
1184     <xsl:value-of select="$depth"/>
1185     <xsl:text>) </xsl:text>
1186     <xsl:value-of select="name($object)"/>
1187     <xsl:text> href=</xsl:text>
1188     <xsl:value-of select="$href"/>
1189   </xsl:message>
1190   -->
1191   <xsl:value-of select="$href"/>
1192 </xsl:template>
1193
1194 <!-- Returns the complete olink href value if found -->
1195 <!-- Must take into account any dbhtml dir of the chunk containing the olink -->
1196 <xsl:template name="make.olink.href">
1197   <xsl:param name="olink.key" select="''"/>
1198   <xsl:param name="target.database"/>
1199
1200   <xsl:if test="$olink.key != ''">
1201     <xsl:variable name="target.href" >
1202       <xsl:for-each select="$target.database" >
1203         <xsl:value-of select="key('targetptr-key', $olink.key)[1]/@href" />
1204       </xsl:for-each>
1205     </xsl:variable>
1206   
1207     <!-- an olink starting point may be in a subdirectory, so need
1208          the "from" reference point to compute a relative path -->
1209
1210     <xsl:variable name="from.href">
1211       <xsl:call-template name="olink.from.uri">
1212         <xsl:with-param name="target.database" select="$target.database"/>
1213         <xsl:with-param name="object" select="."/>
1214         <xsl:with-param name="object.targetdoc" select="$current.docid"/>
1215       </xsl:call-template>
1216     </xsl:variable>
1217
1218     <!-- If the from.href has directory path, then must "../" upward
1219          to document level -->
1220     <xsl:variable name="upward.from.path">
1221       <xsl:call-template name="upward.path">
1222         <xsl:with-param name="path" select="$from.href"/>
1223       </xsl:call-template>
1224     </xsl:variable>
1225
1226     <xsl:variable name="targetdoc">
1227       <xsl:value-of select="substring-before($olink.key, '/')"/>
1228     </xsl:variable>
1229   
1230     <!-- Does the target database use a sitemap? -->
1231     <xsl:variable name="use.sitemap">
1232       <xsl:choose>
1233         <xsl:when test="$target.database//sitemap">1</xsl:when>
1234         <xsl:otherwise>0</xsl:otherwise>
1235       </xsl:choose>
1236     </xsl:variable>
1237   
1238   
1239     <!-- Get the baseuri for this targetptr -->
1240     <xsl:variable name="baseuri" >
1241       <xsl:choose>
1242         <!-- Does the database use a sitemap? -->
1243         <xsl:when test="$use.sitemap != 0" >
1244           <xsl:choose>
1245             <!-- Was current.docid parameter set? -->
1246             <xsl:when test="$current.docid != ''">
1247               <!-- Was it found in the database? -->
1248               <xsl:variable name="currentdoc.key" >
1249                 <xsl:for-each select="$target.database" >
1250                   <xsl:value-of select="key('targetdoc-key',
1251                                         $current.docid)/@targetdoc" />
1252                 </xsl:for-each>
1253               </xsl:variable>
1254               <xsl:choose>
1255                 <xsl:when test="$currentdoc.key != ''">
1256                   <xsl:for-each select="$target.database" >
1257                     <xsl:call-template name="targetpath" >
1258                       <xsl:with-param name="dirnode" 
1259                           select="key('targetdoc-key', $current.docid)/parent::dir"/>
1260                       <xsl:with-param name="targetdoc" select="$targetdoc"/>
1261                     </xsl:call-template>
1262                   </xsl:for-each >
1263                 </xsl:when>
1264                 <xsl:otherwise>
1265                   <xsl:message>
1266                     <xsl:text>Olink error: cannot compute relative </xsl:text>
1267                     <xsl:text>sitemap path because $current.docid '</xsl:text>
1268                     <xsl:value-of select="$current.docid"/>
1269                     <xsl:text>' not found in target database.</xsl:text>
1270                   </xsl:message>
1271                 </xsl:otherwise>
1272               </xsl:choose>
1273             </xsl:when>
1274             <xsl:otherwise>
1275               <xsl:message>
1276                 <xsl:text>Olink warning: cannot compute relative </xsl:text>
1277                 <xsl:text>sitemap path without $current.docid parameter</xsl:text>
1278               </xsl:message>
1279             </xsl:otherwise>
1280           </xsl:choose> 
1281           <!-- In either case, add baseuri from its document entry-->
1282           <xsl:variable name="docbaseuri">
1283             <xsl:for-each select="$target.database" >
1284               <xsl:value-of select="key('targetdoc-key', $targetdoc)/@baseuri" />
1285             </xsl:for-each>
1286           </xsl:variable>
1287           <xsl:if test="$docbaseuri != ''" >
1288             <xsl:value-of select="$docbaseuri"/>
1289           </xsl:if>
1290         </xsl:when>
1291         <!-- No database sitemap in use -->
1292         <xsl:otherwise>
1293           <!-- Just use any baseuri from its document entry -->
1294           <xsl:variable name="docbaseuri">
1295             <xsl:for-each select="$target.database" >
1296               <xsl:value-of select="key('targetdoc-key', $targetdoc)/@baseuri" />
1297             </xsl:for-each>
1298           </xsl:variable>
1299           <xsl:if test="$docbaseuri != ''" >
1300             <xsl:value-of select="$docbaseuri"/>
1301           </xsl:if>
1302         </xsl:otherwise>
1303       </xsl:choose>
1304     </xsl:variable>
1305   
1306     <!-- Form the href information -->
1307     <xsl:if test="not(contains($baseuri, ':'))">
1308       <!-- if not an absolute uri, add upward path from olink chunk -->
1309       <xsl:value-of select="$upward.from.path"/>
1310     </xsl:if>
1311
1312     <xsl:if test="$baseuri != ''">
1313       <xsl:value-of select="$baseuri"/>
1314       <xsl:if test="substring($target.href,1,1) != '#'">
1315         <!--xsl:text>/</xsl:text-->
1316       </xsl:if>
1317     </xsl:if>
1318     <!-- optionally turn off frag for PDF references -->
1319     <xsl:if test="not($insert.olink.pdf.frag = 0 and
1320           translate(substring($baseuri, string-length($baseuri) - 3),
1321                     'PDF', 'pdf') = '.pdf'
1322           and starts-with($target.href, '#') )">
1323       <xsl:value-of select="$target.href"/>
1324     </xsl:if>
1325   </xsl:if>
1326 </xsl:template>
1327
1328 <!-- Computes "../" to reach top -->
1329 <xsl:template name="upward.path">
1330   <xsl:param name="path" select="''"/>
1331   <xsl:choose> 
1332     <!-- Don't bother with absolute uris -->
1333     <xsl:when test="contains($path, ':')"/>
1334     <xsl:when test="starts-with($path, '/')"/>
1335     <xsl:when test="contains($path, '/')">
1336       <xsl:text>../</xsl:text>
1337       <xsl:call-template name="upward.path">
1338         <xsl:with-param name="path" select="substring-after($path, '/')"/>
1339       </xsl:call-template>
1340     </xsl:when>
1341   </xsl:choose>
1342
1343 </xsl:template>
1344
1345 <!-- ==================================================================== -->
1346
1347 <xsl:template name="html.head">
1348   <xsl:param name="prev" select="/foo"/>
1349   <xsl:param name="next" select="/foo"/>
1350   <xsl:variable name="this" select="."/>
1351   <xsl:variable name="home" select="/*[1]"/>
1352   <xsl:variable name="up" select="parent::*"/>
1353
1354   <head>
1355     <xsl:call-template name="system.head.content"/>
1356     <xsl:call-template name="head.content"/>
1357
1358     <xsl:if test="$home">
1359       <link rel="home">
1360         <xsl:attribute name="href">
1361           <xsl:call-template name="href.target">
1362             <xsl:with-param name="object" select="$home"/>
1363           </xsl:call-template>
1364         </xsl:attribute>
1365         <xsl:attribute name="title">
1366           <xsl:apply-templates select="$home"
1367                                mode="object.title.markup.textonly"/>
1368         </xsl:attribute>
1369       </link>
1370     </xsl:if>
1371
1372     <xsl:if test="$up">
1373       <link rel="up">
1374         <xsl:attribute name="href">
1375           <xsl:call-template name="href.target">
1376             <xsl:with-param name="object" select="$up"/>
1377           </xsl:call-template>
1378         </xsl:attribute>
1379         <xsl:attribute name="title">
1380           <xsl:apply-templates select="$up" mode="object.title.markup.textonly"/>
1381         </xsl:attribute>
1382       </link>
1383     </xsl:if>
1384
1385     <xsl:if test="$prev">
1386       <link rel="prev">
1387         <xsl:attribute name="href">
1388           <xsl:call-template name="href.target">
1389             <xsl:with-param name="object" select="$prev"/>
1390           </xsl:call-template>
1391         </xsl:attribute>
1392         <xsl:attribute name="title">
1393           <xsl:apply-templates select="$prev" mode="object.title.markup.textonly"/>
1394         </xsl:attribute>
1395       </link>
1396     </xsl:if>
1397
1398     <xsl:if test="$next">
1399       <link rel="next">
1400         <xsl:attribute name="href">
1401           <xsl:call-template name="href.target">
1402             <xsl:with-param name="object" select="$next"/>
1403           </xsl:call-template>
1404         </xsl:attribute>
1405         <xsl:attribute name="title">
1406           <xsl:apply-templates select="$next" mode="object.title.markup.textonly"/>
1407         </xsl:attribute>
1408       </link>
1409     </xsl:if>
1410
1411     <xsl:if test="$html.extra.head.links != 0">
1412       <xsl:for-each select="//part
1413                             |//reference
1414                             |//preface
1415                             |//chapter
1416                             |//article
1417                             |//refentry
1418                             |//appendix[not(parent::article)]|appendix
1419                             |//glossary[not(parent::article)]|glossary
1420                             |//index[not(parent::article)]|index">
1421         <link rel="{local-name(.)}">
1422           <xsl:attribute name="href">
1423             <xsl:call-template name="href.target">
1424               <xsl:with-param name="context" select="$this"/>
1425               <xsl:with-param name="object" select="."/>
1426             </xsl:call-template>
1427           </xsl:attribute>
1428           <xsl:attribute name="title">
1429             <xsl:apply-templates select="." mode="object.title.markup.textonly"/>
1430           </xsl:attribute>
1431         </link>
1432       </xsl:for-each>
1433
1434       <xsl:for-each select="section|sect1|refsection|refsect1">
1435         <link>
1436           <xsl:attribute name="rel">
1437             <xsl:choose>
1438               <xsl:when test="local-name($this) = 'section'
1439                               or local-name($this) = 'refsection'">
1440                 <xsl:value-of select="'subsection'"/>
1441               </xsl:when>
1442               <xsl:otherwise>
1443                 <xsl:value-of select="'section'"/>
1444               </xsl:otherwise>
1445             </xsl:choose>
1446           </xsl:attribute>
1447           <xsl:attribute name="href">
1448             <xsl:call-template name="href.target">
1449               <xsl:with-param name="context" select="$this"/>
1450               <xsl:with-param name="object" select="."/>
1451             </xsl:call-template>
1452           </xsl:attribute>
1453           <xsl:attribute name="title">
1454             <xsl:apply-templates select="." mode="object.title.markup.textonly"/>
1455           </xsl:attribute>
1456         </link>
1457       </xsl:for-each>
1458
1459       <xsl:for-each select="sect2|sect3|sect4|sect5|refsect2|refsect3">
1460         <link rel="subsection">
1461           <xsl:attribute name="href">
1462             <xsl:call-template name="href.target">
1463               <xsl:with-param name="context" select="$this"/>
1464               <xsl:with-param name="object" select="."/>
1465             </xsl:call-template>
1466           </xsl:attribute>
1467           <xsl:attribute name="title">
1468             <xsl:apply-templates select="." mode="object.title.markup.textonly"/>
1469           </xsl:attribute>
1470         </link>
1471       </xsl:for-each>
1472     </xsl:if>
1473
1474     <!-- * if we have a legalnotice and user wants it output as a -->
1475     <!-- * separate page and $html.head.legalnotice.link.types is -->
1476     <!-- * non-empty, we generate a link or links for each value in -->
1477     <!-- * $html.head.legalnotice.link.types -->
1478     <xsl:if test="//legalnotice
1479                   and not($generate.legalnotice.link = 0)
1480                   and not($html.head.legalnotice.link.types = '')">
1481       <xsl:call-template name="make.legalnotice.head.links"/>
1482     </xsl:if>
1483
1484     <xsl:call-template name="user.head.content"/>
1485   </head>
1486 </xsl:template>
1487
1488 <!-- ==================================================================== -->
1489
1490 <xsl:template name="header.navigation">
1491   <xsl:param name="prev" select="/foo"/>
1492   <xsl:param name="next" select="/foo"/>
1493   <xsl:param name="nav.context"/>
1494
1495   <xsl:variable name="home" select="/*[1]"/>
1496   <xsl:variable name="up" select="parent::*"/>
1497
1498   <xsl:variable name="row1" select="$navig.showtitles != 0"/>
1499   <xsl:variable name="row2" select="count($prev) &gt; 0
1500                                     or (count($up) &gt; 0 
1501                                         and generate-id($up) != generate-id($home)
1502                                         and $navig.showtitles != 0)
1503                                     or count($next) &gt; 0"/>
1504
1505   <xsl:if test="$suppress.navigation = '0' and $suppress.header.navigation = '0'">
1506     <div class="navheader">
1507       <xsl:if test="$row1 or $row2">
1508         <table width="100%" summary="Navigation header">
1509           <xsl:if test="$row1">
1510             <tr>
1511               <th colspan="3" align="center">
1512                 <xsl:apply-templates select="." mode="object.title.markup"/>
1513               </th>
1514             </tr>
1515           </xsl:if>
1516
1517           <xsl:if test="$row2">
1518             <tr>
1519               <td width="20%" align="{$direction.align.start}">
1520                 <xsl:if test="count($prev)>0">
1521                   <a accesskey="p">
1522                     <xsl:attribute name="href">
1523                       <xsl:call-template name="href.target">
1524                         <xsl:with-param name="object" select="$prev"/>
1525                       </xsl:call-template>
1526                     </xsl:attribute>
1527                     <xsl:call-template name="navig.content">
1528                       <xsl:with-param name="direction" select="'prev'"/>
1529                     </xsl:call-template>
1530                   </a>
1531                 </xsl:if>
1532                 <xsl:text>&#160;</xsl:text>
1533               </td>
1534               <th width="60%" align="center">
1535                 <xsl:choose>
1536                   <xsl:when test="count($up) > 0
1537                                   and generate-id($up) != generate-id($home)
1538                                   and $navig.showtitles != 0">
1539                     <xsl:apply-templates select="$up" mode="object.title.markup"/>
1540                   </xsl:when>
1541                   <xsl:otherwise>&#160;</xsl:otherwise>
1542                 </xsl:choose>
1543               </th>
1544               <td width="20%" align="{$direction.align.end}">
1545                 <xsl:text>&#160;</xsl:text>
1546                 <xsl:if test="count($next)>0">
1547                   <a accesskey="n">
1548                     <xsl:attribute name="href">
1549                       <xsl:call-template name="href.target">
1550                         <xsl:with-param name="object" select="$next"/>
1551                       </xsl:call-template>
1552                     </xsl:attribute>
1553                     <xsl:call-template name="navig.content">
1554                       <xsl:with-param name="direction" select="'next'"/>
1555                     </xsl:call-template>
1556                   </a>
1557                 </xsl:if>
1558               </td>
1559             </tr>
1560           </xsl:if>
1561         </table>
1562       </xsl:if>
1563       <xsl:if test="$header.rule != 0">
1564         <hr/>
1565       </xsl:if>
1566     </div>
1567   </xsl:if>
1568 </xsl:template>
1569
1570 <!-- ==================================================================== -->
1571
1572 <xsl:template name="footer.navigation">
1573   <xsl:param name="prev" select="/foo"/>
1574   <xsl:param name="next" select="/foo"/>
1575   <xsl:param name="nav.context"/>
1576
1577   <xsl:variable name="home" select="/*[1]"/>
1578   <xsl:variable name="up" select="parent::*"/>
1579
1580   <xsl:variable name="row1" select="count($prev) &gt; 0
1581                                     or count($up) &gt; 0
1582                                     or count($next) &gt; 0"/>
1583
1584   <xsl:variable name="row2" select="($prev and $navig.showtitles != 0)
1585                                     or (generate-id($home) != generate-id(.)
1586                                         or $nav.context = 'toc')
1587                                     or ($chunk.tocs.and.lots != 0
1588                                         and $nav.context != 'toc')
1589                                     or ($next and $navig.showtitles != 0)"/>
1590
1591   <xsl:if test="$suppress.navigation = '0' and $suppress.footer.navigation = '0'">
1592     <div class="navfooter">
1593       <xsl:if test="$footer.rule != 0">
1594         <hr/>
1595       </xsl:if>
1596
1597       <xsl:if test="$row1 or $row2">
1598         <table width="100%" summary="Navigation footer">
1599           <xsl:if test="$row1">
1600             <tr>
1601               <td width="40%" align="{$direction.align.start}">
1602                 <xsl:if test="count($prev)>0">
1603                   <a accesskey="p">
1604                     <xsl:attribute name="href">
1605                       <xsl:call-template name="href.target">
1606                         <xsl:with-param name="object" select="$prev"/>
1607                       </xsl:call-template>
1608                     </xsl:attribute>
1609                     <xsl:call-template name="navig.content">
1610                       <xsl:with-param name="direction" select="'prev'"/>
1611                     </xsl:call-template>
1612                   </a>
1613                 </xsl:if>
1614                 <xsl:text>&#160;</xsl:text>
1615               </td>
1616               <td width="20%" align="center">
1617                 <xsl:choose>
1618                   <xsl:when test="count($up)&gt;0
1619                                   and generate-id($up) != generate-id($home)">
1620                     <a accesskey="u">
1621                       <xsl:attribute name="href">
1622                         <xsl:call-template name="href.target">
1623                           <xsl:with-param name="object" select="$up"/>
1624                         </xsl:call-template>
1625                       </xsl:attribute>
1626                       <xsl:call-template name="navig.content">
1627                         <xsl:with-param name="direction" select="'up'"/>
1628                       </xsl:call-template>
1629                     </a>
1630                   </xsl:when>
1631                   <xsl:otherwise>&#160;</xsl:otherwise>
1632                 </xsl:choose>
1633               </td>
1634               <td width="40%" align="{$direction.align.end}">
1635                 <xsl:text>&#160;</xsl:text>
1636                 <xsl:if test="count($next)>0">
1637                   <a accesskey="n">
1638                     <xsl:attribute name="href">
1639                       <xsl:call-template name="href.target">
1640                         <xsl:with-param name="object" select="$next"/>
1641                       </xsl:call-template>
1642                     </xsl:attribute>
1643                     <xsl:call-template name="navig.content">
1644                       <xsl:with-param name="direction" select="'next'"/>
1645                     </xsl:call-template>
1646                   </a>
1647                 </xsl:if>
1648               </td>
1649             </tr>
1650           </xsl:if>
1651
1652           <xsl:if test="$row2">
1653             <tr>
1654               <td width="40%" align="{$direction.align.start}" valign="top">
1655                 <xsl:if test="$navig.showtitles != 0">
1656                   <xsl:apply-templates select="$prev" mode="object.title.markup"/>
1657                 </xsl:if>
1658                 <xsl:text>&#160;</xsl:text>
1659               </td>
1660               <td width="20%" align="center">
1661                 <xsl:choose>
1662                   <xsl:when test="$home != . or $nav.context = 'toc'">
1663                     <a accesskey="h">
1664                       <xsl:attribute name="href">
1665                         <xsl:call-template name="href.target">
1666                           <xsl:with-param name="object" select="$home"/>
1667                         </xsl:call-template>
1668                       </xsl:attribute>
1669                       <xsl:call-template name="navig.content">
1670                         <xsl:with-param name="direction" select="'home'"/>
1671                       </xsl:call-template>
1672                     </a>
1673                     <xsl:if test="$chunk.tocs.and.lots != 0 and $nav.context != 'toc'">
1674                       <xsl:text>&#160;|&#160;</xsl:text>
1675                     </xsl:if>
1676                   </xsl:when>
1677                   <xsl:otherwise>&#160;</xsl:otherwise>
1678                 </xsl:choose>
1679
1680                 <xsl:if test="$chunk.tocs.and.lots != 0 and $nav.context != 'toc'">
1681                   <a accesskey="t">
1682                     <xsl:attribute name="href">
1683                       <xsl:apply-templates select="/*[1]"
1684                                            mode="recursive-chunk-filename">
1685                         <xsl:with-param name="recursive" select="true()"/>
1686                       </xsl:apply-templates>
1687                       <xsl:text>-toc</xsl:text>
1688                       <xsl:value-of select="$html.ext"/>
1689                     </xsl:attribute>
1690                     <xsl:call-template name="gentext">
1691                       <xsl:with-param name="key" select="'nav-toc'"/>
1692                     </xsl:call-template>
1693                   </a>
1694                 </xsl:if>
1695               </td>
1696               <td width="40%" align="{$direction.align.end}" valign="top">
1697                 <xsl:text>&#160;</xsl:text>
1698                 <xsl:if test="$navig.showtitles != 0">
1699                   <xsl:apply-templates select="$next" mode="object.title.markup"/>
1700                 </xsl:if>
1701               </td>
1702             </tr>
1703           </xsl:if>
1704         </table>
1705       </xsl:if>
1706     </div>
1707   </xsl:if>
1708 </xsl:template>
1709
1710 <!-- ==================================================================== -->
1711
1712 <xsl:template name="navig.content">
1713     <xsl:param name="direction" select="next"/>
1714     <xsl:variable name="navtext">
1715         <xsl:choose>
1716             <xsl:when test="$direction = 'prev'">
1717                 <xsl:call-template name="gentext.nav.prev"/>
1718             </xsl:when>
1719             <xsl:when test="$direction = 'next'">
1720                 <xsl:call-template name="gentext.nav.next"/>
1721             </xsl:when>
1722             <xsl:when test="$direction = 'up'">
1723                 <xsl:call-template name="gentext.nav.up"/>
1724             </xsl:when>
1725             <xsl:when test="$direction = 'home'">
1726                 <xsl:call-template name="gentext.nav.home"/>
1727             </xsl:when>
1728             <xsl:otherwise>
1729                 <xsl:text>xxx</xsl:text>
1730             </xsl:otherwise>
1731         </xsl:choose>
1732     </xsl:variable>
1733
1734     <xsl:choose>
1735         <xsl:when test="$navig.graphics != 0">
1736             <img>
1737                 <xsl:attribute name="src">
1738                     <xsl:value-of select="$navig.graphics.path"/>
1739                     <xsl:value-of select="$direction"/>
1740                     <xsl:value-of select="$navig.graphics.extension"/>
1741                 </xsl:attribute>
1742                 <xsl:attribute name="alt">
1743                     <xsl:value-of select="$navtext"/>
1744                 </xsl:attribute>
1745             </img>
1746         </xsl:when>
1747         <xsl:otherwise>
1748             <xsl:value-of select="$navtext"/>
1749         </xsl:otherwise>
1750     </xsl:choose>
1751 </xsl:template>
1752
1753 <!-- ==================================================================== -->
1754
1755 <!-- * The following template assumes that the first legalnotice -->
1756 <!-- * instance found in a document applies to the contents of the -->
1757 <!-- * entire document. It generates an HTML link in each chunk, back -->
1758 <!-- * to the file containing the contents of the first legalnotice. -->
1759 <!-- * -->
1760 <!-- * Actually, it may generate multiple link instances in each chunk, -->
1761 <!-- * because it walks through the space-separated list of link -->
1762 <!-- * types specified in the $html.head.legalnotice.link.types param, -->
1763 <!-- * popping off link types and generating links for them until it -->
1764 <!-- * depletes the list. -->
1765   
1766 <xsl:template name="make.legalnotice.head.links">
1767   <!-- * the following ID is used as part of the legalnotice filename; -->
1768   <!-- * we need it in order to construct the filename for use in the -->
1769   <!-- * value of the href attribute on the link -->
1770
1771   <xsl:param name="ln-node" select="(//legalnotice)[1]"/>
1772   
1773   <xsl:param name="linktype">
1774     <xsl:choose>
1775       <xsl:when test="contains($html.head.legalnotice.link.types, ' ')">
1776         <xsl:value-of
1777             select="normalize-space(
1778                     substring-before($html.head.legalnotice.link.types, ' '))"/>
1779       </xsl:when>
1780       <xsl:otherwise>
1781         <xsl:value-of select="$html.head.legalnotice.link.types"/>
1782       </xsl:otherwise>
1783     </xsl:choose>
1784   </xsl:param>
1785   <xsl:param
1786       name="remaining.linktypes"
1787       select="concat(
1788               normalize-space(
1789               substring-after($html.head.legalnotice.link.types, ' ')),' ')"/>
1790   <xsl:if test="not($linktype = '')">
1791
1792     <!-- Compute name of legalnotice file (see titlepage.xsl) -->
1793     <xsl:variable name="file">
1794       <xsl:call-template name="ln.or.rh.filename">
1795         <xsl:with-param name="node" select="$ln-node"/>
1796       </xsl:call-template>
1797     </xsl:variable>
1798    
1799     <link rel="{$linktype}">
1800       <xsl:attribute name="href">
1801         <xsl:value-of select="$file"/>
1802       </xsl:attribute>
1803       <xsl:attribute name="title">
1804         <xsl:apply-templates select="(//legalnotice)[1]"
1805                              mode="object.title.markup.textonly"/>
1806       </xsl:attribute>
1807     </link>
1808     <xsl:call-template name="make.legalnotice.head.links">
1809       <!-- * pop the next value off the list of link types -->
1810       <xsl:with-param
1811           name="linktype"
1812           select="substring-before($remaining.linktypes, ' ')"/>
1813       <!-- * remove the link type from the list of remaining link types -->
1814       <xsl:with-param
1815           name="remaining.linktypes"
1816           select="substring-after($remaining.linktypes, ' ')"/>
1817     </xsl:call-template>
1818   </xsl:if>
1819 </xsl:template>
1820
1821 <!-- ==================================================================== -->
1822 <xsl:template name="chunk-element-content">
1823   <xsl:param name="prev"/>
1824   <xsl:param name="next"/>
1825   <xsl:param name="nav.context"/>
1826   <xsl:param name="content">
1827     <xsl:apply-imports/>
1828   </xsl:param>
1829
1830   <xsl:call-template name="user.preroot"/>
1831
1832   <html>
1833     <xsl:call-template name="html.head">
1834       <xsl:with-param name="prev" select="$prev"/>
1835       <xsl:with-param name="next" select="$next"/>
1836     </xsl:call-template>
1837
1838     <body>
1839       <xsl:call-template name="body.attributes"/>
1840       <xsl:call-template name="user.header.navigation"/>
1841
1842       <xsl:call-template name="header.navigation">
1843         <xsl:with-param name="prev" select="$prev"/>
1844         <xsl:with-param name="next" select="$next"/>
1845         <xsl:with-param name="nav.context" select="$nav.context"/>
1846       </xsl:call-template>
1847
1848       <xsl:call-template name="user.header.content"/>
1849
1850       <xsl:copy-of select="$content"/>
1851
1852       <xsl:call-template name="user.footer.content"/>
1853
1854       <xsl:call-template name="footer.navigation">
1855         <xsl:with-param name="prev" select="$prev"/>
1856         <xsl:with-param name="next" select="$next"/>
1857         <xsl:with-param name="nav.context" select="$nav.context"/>
1858       </xsl:call-template>
1859
1860       <xsl:call-template name="user.footer.navigation"/>
1861     </body>
1862   </html>
1863   <xsl:value-of select="$chunk.append"/>
1864 </xsl:template>
1865
1866 <!-- ==================================================================== -->
1867 <xsl:template name="generate.manifest">
1868   <xsl:param name="node" select="/"/>
1869   <xsl:call-template name="write.text.chunk">
1870     <xsl:with-param name="filename">
1871       <xsl:if test="$manifest.in.base.dir != 0">
1872         <xsl:value-of select="$base.dir"/>
1873       </xsl:if>
1874       <xsl:value-of select="$manifest"/>
1875     </xsl:with-param>
1876     <xsl:with-param name="method" select="'text'"/>
1877     <xsl:with-param name="content">
1878       <xsl:apply-templates select="$node" mode="enumerate-files"/>
1879     </xsl:with-param>
1880     <xsl:with-param name="encoding" select="$chunker.output.encoding"/>
1881   </xsl:call-template>
1882 </xsl:template>
1883
1884 <!-- ==================================================================== -->
1885
1886 <xsl:template name="dbhtml-dir">
1887   <xsl:param name="context" select="."/>
1888   <!-- directories are now inherited from previous levels -->
1889   <xsl:variable name="ppath">
1890     <xsl:if test="$context/parent::*">
1891       <xsl:call-template name="dbhtml-dir">
1892         <xsl:with-param name="context" select="$context/parent::*"/>
1893       </xsl:call-template>
1894     </xsl:if>
1895   </xsl:variable>
1896   <xsl:variable name="path">
1897     <xsl:call-template name="pi.dbhtml_dir">
1898       <xsl:with-param name="node" select="$context"/>
1899     </xsl:call-template>
1900   </xsl:variable>
1901   <xsl:choose>
1902     <xsl:when test="$path = ''">
1903       <xsl:if test="$ppath != ''">
1904         <xsl:value-of select="$ppath"/>
1905       </xsl:if>
1906     </xsl:when>
1907     <xsl:otherwise>
1908       <xsl:if test="$ppath != ''">
1909         <xsl:value-of select="$ppath"/>
1910         <xsl:if test="substring($ppath, string-length($ppath), 1) != '/'">
1911           <xsl:text>/</xsl:text>
1912         </xsl:if>
1913       </xsl:if>
1914       <xsl:value-of select="$path"/>
1915       <xsl:text>/</xsl:text>
1916     </xsl:otherwise>
1917   </xsl:choose>
1918 </xsl:template>
1919
1920 </xsl:stylesheet>