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