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