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