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