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