1<?xml version="1.0" encoding="US-ASCII"?>
2<!--This file was created automatically by xsl2profile-->
3<!--from the DocBook XSL stylesheets. Do not edit this file.-->
4<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:cf="http://docbook.sourceforge.net/xmlns/chunkfast/1.0" xmlns:ng="http://docbook.org/docbook-ng" xmlns:db="http://docbook.org/ns/docbook" xmlns:exslt="http://exslt.org/common" exslt:dummy="dummy" ng:dummy="dummy" db:dummy="dummy" extension-element-prefixes="exslt" version="1.0" exclude-result-prefixes="exsl cf ng db exslt">
5
6<!-- ********************************************************************
7     $Id: chunk-code.xsl,v 1.15 2006/05/04 12:46:45 kosek Exp $
8     ********************************************************************
9
10     This file is part of the XSL DocBook Stylesheet distribution.
11     See ../README or http://nwalsh.com/docbook/xsl/ for copyright
12     and other information.
13
14     ******************************************************************** -->
15
16<!-- ==================================================================== -->
17
18<xsl:param name="onechunk" select="0"/>
19<xsl:param name="refentry.separator" select="0"/>
20<xsl:param name="chunk.fast" select="0"/>
21
22<xsl:key name="genid" match="*" use="generate-id()"/>
23
24<!-- ==================================================================== -->
25
26<xsl:variable name="chunk.hierarchy">
27  <xsl:if test="$chunk.fast != 0">
28    <xsl:choose>
29      <xsl:when test="function-available('exsl:node-set')">
30        <xsl:message>Computing chunks...</xsl:message>
31        <xsl:apply-templates select="/*" mode="find.chunks"/>
32      </xsl:when>
33      <xsl:otherwise>
34        <xsl:message>
35          <xsl:text>Fast chunking requires exsl:node-set(). </xsl:text>
36          <xsl:text>Using "slow" chunking.</xsl:text>
37        </xsl:message>
38      </xsl:otherwise>
39    </xsl:choose>
40  </xsl:if>
41</xsl:variable>
42
43<xsl:template match="*" mode="find.chunks">
44  <xsl:variable name="chunk">
45    <xsl:call-template name="chunk"/>
46  </xsl:variable>
47
48  <xsl:choose>
49    <xsl:when test="$chunk != 0">
50      <cf:div class="{local-name(.)}" id="{generate-id()}">
51        <xsl:apply-templates select="*" mode="find.chunks"/>
52      </cf:div>
53    </xsl:when>
54    <xsl:otherwise>
55      <xsl:apply-templates select="*" mode="find.chunks"/>
56    </xsl:otherwise>
57  </xsl:choose>
58</xsl:template>
59
60<!-- ==================================================================== -->
61
62<xsl:template name="process-chunk-element">
63  <xsl:param name="content">
64    <xsl:apply-imports/>
65  </xsl:param>
66
67  <xsl:choose>
68    <xsl:when test="$chunk.fast != 0 and function-available('exsl:node-set')">
69      <xsl:variable name="chunks" select="exsl:node-set($chunk.hierarchy)//cf:div"/>
70      <xsl:variable name="genid" select="generate-id()"/>
71
72      <xsl:variable name="div" select="$chunks[@id=$genid]"/>
73
74      <xsl:variable name="prevdiv" select="($div/preceding-sibling::cf:div|$div/preceding::cf:div|$div/parent::cf:div)[last()]"/>
75      <xsl:variable name="prev" select="key('genid', $prevdiv/@id)"/>
76
77      <xsl:variable name="nextdiv" select="($div/following-sibling::cf:div|$div/following::cf:div|$div/cf:div)[1]"/>
78      <xsl:variable name="next" select="key('genid', $nextdiv/@id)"/>
79
80      <xsl:choose>
81        <xsl:when test="$onechunk != 0 and parent::*">
82          <xsl:copy-of select="$content"/>
83        </xsl:when>
84        <xsl:otherwise>
85          <xsl:call-template name="process-chunk">
86            <xsl:with-param name="prev" select="$prev"/>
87            <xsl:with-param name="next" select="$next"/>
88            <xsl:with-param name="content" select="$content"/>
89          </xsl:call-template>
90        </xsl:otherwise>
91      </xsl:choose>
92    </xsl:when>
93    <xsl:otherwise>
94      <xsl:choose>
95        <xsl:when test="$onechunk != 0 and not(parent::*)">
96          <xsl:call-template name="chunk-all-sections">
97            <xsl:with-param name="content" select="$content"/>
98          </xsl:call-template>
99        </xsl:when>
100        <xsl:when test="$onechunk != 0">
101          <xsl:copy-of select="$content"/>
102        </xsl:when>
103        <xsl:when test="$chunk.first.sections = 0">
104          <xsl:call-template name="chunk-first-section-with-parent">
105            <xsl:with-param name="content" select="$content"/>
106          </xsl:call-template>
107        </xsl:when>
108        <xsl:otherwise>
109          <xsl:call-template name="chunk-all-sections">
110            <xsl:with-param name="content" select="$content"/>
111          </xsl:call-template>
112        </xsl:otherwise>
113      </xsl:choose>
114    </xsl:otherwise>
115  </xsl:choose>
116</xsl:template>
117
118<xsl:template name="process-chunk">
119  <xsl:param name="prev" select="."/>
120  <xsl:param name="next" select="."/>
121  <xsl:param name="content">
122    <xsl:apply-imports/>
123  </xsl:param>
124
125  <xsl:variable name="ischunk">
126    <xsl:call-template name="chunk"/>
127  </xsl:variable>
128
129  <xsl:variable name="chunkfn">
130    <xsl:if test="$ischunk='1'">
131      <xsl:apply-templates mode="chunk-filename" select="."/>
132    </xsl:if>
133  </xsl:variable>
134
135  <xsl:if test="$ischunk='0'">
136    <xsl:message>
137      <xsl:text>Error </xsl:text>
138      <xsl:value-of select="name(.)"/>
139      <xsl:text> is not a chunk!</xsl:text>
140    </xsl:message>
141  </xsl:if>
142
143  <xsl:variable name="filename">
144    <xsl:call-template name="make-relative-filename">
145      <xsl:with-param name="base.dir" select="$base.dir"/>
146      <xsl:with-param name="base.name" select="$chunkfn"/>
147    </xsl:call-template>
148  </xsl:variable>
149
150  <xsl:call-template name="write.chunk">
151    <xsl:with-param name="filename" select="$filename"/>
152    <xsl:with-param name="content">
153      <xsl:call-template name="chunk-element-content">
154        <xsl:with-param name="prev" select="$prev"/>
155        <xsl:with-param name="next" select="$next"/>
156        <xsl:with-param name="content" select="$content"/>
157      </xsl:call-template>
158    </xsl:with-param>
159    <xsl:with-param name="quiet" select="$chunk.quietly"/>
160  </xsl:call-template>
161</xsl:template>
162
163<xsl:template name="chunk-first-section-with-parent">
164  <xsl:param name="content">
165    <xsl:apply-imports/>
166  </xsl:param>
167
168  <!-- These xpath expressions are really hairy. The trick is to pick sections -->
169  <!-- that are not first children and are not the children of first children -->
170
171  <!-- Break these variables into pieces to work around
172       http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6063 -->
173
174  <xsl:variable name="prev-v1" select="(ancestor::sect1[$chunk.section.depth &gt; 0                                and preceding-sibling::sect1][1]               |ancestor::sect2[$chunk.section.depth &gt; 1                                and preceding-sibling::sect2                                and parent::sect1[preceding-sibling::sect1]][1]               |ancestor::sect3[$chunk.section.depth &gt; 2                                and preceding-sibling::sect3                                and parent::sect2[preceding-sibling::sect2]                                and ancestor::sect1[preceding-sibling::sect1]][1]               |ancestor::sect4[$chunk.section.depth &gt; 3                                and preceding-sibling::sect4                                and parent::sect3[preceding-sibling::sect2]                                and ancestor::sect2[preceding-sibling::sect2]                                and ancestor::sect1[preceding-sibling::sect1]][1]               |ancestor::sect5[$chunk.section.depth &gt; 4                                and preceding-sibling::sect5                                and parent::sect4[preceding-sibling::sect4]                                and ancestor::sect3[preceding-sibling::sect3]                                and ancestor::sect2[preceding-sibling::sect2]                                and ancestor::sect1[preceding-sibling::sect1]][1]               |ancestor::section[$chunk.section.depth &gt; count(ancestor::section)                                 and not(ancestor::section[not(preceding-sibling::section)])][1])[last()]"/>
175
176  <xsl:variable name="prev-v2" select="(preceding::sect1[$chunk.section.depth &gt; 0                                and preceding-sibling::sect1][1]               |preceding::sect2[$chunk.section.depth &gt; 1                                and preceding-sibling::sect2                                and parent::sect1[preceding-sibling::sect1]][1]               |preceding::sect3[$chunk.section.depth &gt; 2                                and preceding-sibling::sect3                                and parent::sect2[preceding-sibling::sect2]                                and ancestor::sect1[preceding-sibling::sect1]][1]               |preceding::sect4[$chunk.section.depth &gt; 3                                and preceding-sibling::sect4                                and parent::sect3[preceding-sibling::sect2]                                and ancestor::sect2[preceding-sibling::sect2]                                and ancestor::sect1[preceding-sibling::sect1]][1]               |preceding::sect5[$chunk.section.depth &gt; 4                                and preceding-sibling::sect5                                and parent::sect4[preceding-sibling::sect4]                                and ancestor::sect3[preceding-sibling::sect3]                                and ancestor::sect2[preceding-sibling::sect2]                                and ancestor::sect1[preceding-sibling::sect1]][1]               |preceding::section[$chunk.section.depth &gt; count(ancestor::section)                                  and preceding-sibling::section                                  and not(ancestor::section[not(preceding-sibling::section)])][1])[last()]"/>
177
178  <xsl:variable name="prev" select="(preceding::book[1]              |preceding::preface[1]              |preceding::chapter[1]              |preceding::appendix[1]              |preceding::part[1]              |preceding::reference[1]              |preceding::refentry[1]              |preceding::colophon[1]              |preceding::article[1]              |preceding::bibliography[parent::article or parent::book or parent::part][1]              |preceding::glossary[parent::article or parent::book or parent::part][1]              |preceding::index[$generate.index != 0]                         [parent::article or parent::book or parent::part][1]              |preceding::setindex[$generate.index != 0][1]              |ancestor::set              |ancestor::book[1]              |ancestor::preface[1]              |ancestor::chapter[1]              |ancestor::appendix[1]              |ancestor::part[1]              |ancestor::reference[1]              |ancestor::article[1]              |$prev-v1              |$prev-v2)[last()]"/>
179
180  <xsl:variable name="next-v1" select="(following::sect1[$chunk.section.depth &gt; 0                                and preceding-sibling::sect1][1]               |following::sect2[$chunk.section.depth &gt; 1                                and preceding-sibling::sect2                                and parent::sect1[preceding-sibling::sect1]][1]               |following::sect3[$chunk.section.depth &gt; 2                                and preceding-sibling::sect3                                and parent::sect2[preceding-sibling::sect2]                                and ancestor::sect1[preceding-sibling::sect1]][1]               |following::sect4[$chunk.section.depth &gt; 3                                and preceding-sibling::sect4                                and parent::sect3[preceding-sibling::sect2]                                and ancestor::sect2[preceding-sibling::sect2]                                and ancestor::sect1[preceding-sibling::sect1]][1]               |following::sect5[$chunk.section.depth &gt; 4                                and preceding-sibling::sect5                                and parent::sect4[preceding-sibling::sect4]                                and ancestor::sect3[preceding-sibling::sect3]                                and ancestor::sect2[preceding-sibling::sect2]                                and ancestor::sect1[preceding-sibling::sect1]][1]               |following::section[$chunk.section.depth &gt; count(ancestor::section)                                  and preceding-sibling::section                                  and not(ancestor::section[not(preceding-sibling::section)])][1])[1]"/>
181
182  <xsl:variable name="next-v2" select="(descendant::sect1[$chunk.section.depth &gt; 0                                and preceding-sibling::sect1][1]               |descendant::sect2[$chunk.section.depth &gt; 1                                and preceding-sibling::sect2                                and parent::sect1[preceding-sibling::sect1]][1]               |descendant::sect3[$chunk.section.depth &gt; 2                                and preceding-sibling::sect3                                and parent::sect2[preceding-sibling::sect2]                                and ancestor::sect1[preceding-sibling::sect1]][1]               |descendant::sect4[$chunk.section.depth &gt; 3                                and preceding-sibling::sect4                                and parent::sect3[preceding-sibling::sect2]                                and ancestor::sect2[preceding-sibling::sect2]                                and ancestor::sect1[preceding-sibling::sect1]][1]               |descendant::sect5[$chunk.section.depth &gt; 4                                and preceding-sibling::sect5                                and parent::sect4[preceding-sibling::sect4]                                and ancestor::sect3[preceding-sibling::sect3]                                and ancestor::sect2[preceding-sibling::sect2]                                and ancestor::sect1[preceding-sibling::sect1]][1]               |descendant::section[$chunk.section.depth &gt; count(ancestor::section)                                  and preceding-sibling::section                                  and not(ancestor::section[not(preceding-sibling::section)])])[1]"/>
183
184  <xsl:variable name="next" select="(following::book[1]              |following::preface[1]              |following::chapter[1]              |following::appendix[1]              |following::part[1]              |following::reference[1]              |following::refentry[1]              |following::colophon[1]              |following::bibliography[parent::article or parent::book or parent::part][1]              |following::glossary[parent::article or parent::book or parent::part][1]              |following::index[$generate.index != 0]                         [parent::article or parent::book or parent::part][1]              |following::article[1]              |following::setindex[$generate.index != 0][1]              |descendant::book[1]              |descendant::preface[1]              |descendant::chapter[1]              |descendant::appendix[1]              |descendant::article[1]              |descendant::bibliography[parent::article or parent::book or parent::part][1]              |descendant::glossary[parent::article or parent::book or parent::part][1]              |descendant::index[$generate.index != 0]                         [parent::article or parent::book or parent::part][1]              |descendant::colophon[1]              |descendant::setindex[$generate.index != 0][1]              |descendant::part[1]              |descendant::reference[1]              |descendant::refentry[1]              |$next-v1              |$next-v2)[1]"/>
185
186  <xsl:call-template name="process-chunk">
187    <xsl:with-param name="prev" select="$prev"/>
188    <xsl:with-param name="next" select="$next"/>
189    <xsl:with-param name="content" select="$content"/>
190  </xsl:call-template>
191</xsl:template>
192
193<xsl:template name="chunk-all-sections">
194  <xsl:param name="content">
195    <xsl:apply-imports/>
196  </xsl:param>
197
198  <xsl:variable name="prev-v1" select="(preceding::sect1[$chunk.section.depth &gt; 0][1]              |preceding::sect2[$chunk.section.depth &gt; 1][1]              |preceding::sect3[$chunk.section.depth &gt; 2][1]              |preceding::sect4[$chunk.section.depth &gt; 3][1]              |preceding::sect5[$chunk.section.depth &gt; 4][1]              |preceding::section[$chunk.section.depth &gt; count(ancestor::section)][1])[last()]"/>
199
200  <xsl:variable name="prev-v2" select="(ancestor::sect1[$chunk.section.depth &gt; 0][1]              |ancestor::sect2[$chunk.section.depth &gt; 1][1]              |ancestor::sect3[$chunk.section.depth &gt; 2][1]              |ancestor::sect4[$chunk.section.depth &gt; 3][1]              |ancestor::sect5[$chunk.section.depth &gt; 4][1]              |ancestor::section[$chunk.section.depth &gt; count(ancestor::section)][1])[last()]"/>
201
202  <xsl:variable name="prev" select="(preceding::book[1]              |preceding::preface[1]              |preceding::chapter[1]              |preceding::appendix[1]              |preceding::part[1]              |preceding::reference[1]              |preceding::refentry[1]              |preceding::colophon[1]              |preceding::article[1]              |preceding::bibliography[parent::article or parent::book or parent::part][1]              |preceding::glossary[parent::article or parent::book or parent::part][1]              |preceding::index[$generate.index != 0]                         [parent::article or parent::book or parent::part][1]              |preceding::setindex[$generate.index != 0][1]              |ancestor::set              |ancestor::book[1]              |ancestor::preface[1]              |ancestor::chapter[1]              |ancestor::appendix[1]              |ancestor::part[1]              |ancestor::reference[1]              |ancestor::article[1]              |$prev-v1              |$prev-v2)[last()]"/>
203
204  <xsl:variable name="next-v1" select="(following::sect1[$chunk.section.depth &gt; 0][1]              |following::sect2[$chunk.section.depth &gt; 1][1]              |following::sect3[$chunk.section.depth &gt; 2][1]              |following::sect4[$chunk.section.depth &gt; 3][1]              |following::sect5[$chunk.section.depth &gt; 4][1]              |following::section[$chunk.section.depth &gt; count(ancestor::section)][1])[1]"/>
205
206  <xsl:variable name="next-v2" select="(descendant::sect1[$chunk.section.depth &gt; 0][1]              |descendant::sect2[$chunk.section.depth &gt; 1][1]              |descendant::sect3[$chunk.section.depth &gt; 2][1]              |descendant::sect4[$chunk.section.depth &gt; 3][1]              |descendant::sect5[$chunk.section.depth &gt; 4][1]              |descendant::section[$chunk.section.depth                                    &gt; count(ancestor::section)][1])[1]"/>
207
208  <xsl:variable name="next" select="(following::book[1]              |following::preface[1]              |following::chapter[1]              |following::appendix[1]              |following::part[1]              |following::reference[1]              |following::refentry[1]              |following::colophon[1]              |following::bibliography[parent::article or parent::book or parent::part][1]              |following::glossary[parent::article or parent::book or parent::part][1]              |following::index[$generate.index != 0]                         [parent::article or parent::book][1]              |following::article[1]              |following::setindex[$generate.index != 0][1]              |descendant::book[1]              |descendant::preface[1]              |descendant::chapter[1]              |descendant::appendix[1]              |descendant::article[1]              |descendant::bibliography[parent::article or parent::book][1]              |descendant::glossary[parent::article or parent::book or parent::part][1]              |descendant::index[$generate.index != 0]                         [parent::article or parent::book][1]              |descendant::colophon[1]              |descendant::setindex[$generate.index != 0][1]              |descendant::part[1]              |descendant::reference[1]              |descendant::refentry[1]              |$next-v1              |$next-v2)[1]"/>
209
210  <xsl:call-template name="process-chunk">
211    <xsl:with-param name="prev" select="$prev"/>
212    <xsl:with-param name="next" select="$next"/>
213    <xsl:with-param name="content" select="$content"/>
214  </xsl:call-template>
215</xsl:template>
216
217<!-- ==================================================================== -->
218
219<xslo:include xmlns:xslo="http://www.w3.org/1999/XSL/Transform" href="../profiling/profile-mode.xsl"/><xslo:variable xmlns:xslo="http://www.w3.org/1999/XSL/Transform" name="profiled-content"><xslo:choose><xslo:when test="*/self::ng:* or */self::db:*"><xslo:message>Stripping NS from DocBook 5/NG document.</xslo:message><xslo:variable name="stripped-content"><xslo:apply-templates select="/" mode="stripNS"/></xslo:variable><xslo:message>Processing stripped document.</xslo:message><xslo:apply-templates select="exslt:node-set($stripped-content)" mode="profile"/></xslo:when><xslo:otherwise><xslo:apply-templates select="/" mode="profile"/></xslo:otherwise></xslo:choose></xslo:variable><xslo:variable xmlns:xslo="http://www.w3.org/1999/XSL/Transform" name="profiled-nodes" select="exslt:node-set($profiled-content)"/><xsl:template match="/">
220  <xsl:choose>
221    <xsl:when test="false()"/>
222    <xsl:otherwise>
223      <xsl:choose>
224	<xsl:when test="$rootid != ''">
225	  <xsl:choose>
226	    <xsl:when test="count($profiled-nodes//*[@id=$rootid]) = 0">
227	      <xsl:message terminate="yes">
228		<xsl:text>ID '</xsl:text>
229		<xsl:value-of select="$rootid"/>
230		<xsl:text>' not found in document.</xsl:text>
231	      </xsl:message>
232	    </xsl:when>
233	    <xsl:otherwise>
234	      <xsl:if test="$collect.xref.targets = 'yes' or        $collect.xref.targets = 'only'">
235		<xsl:apply-templates select="key('id', $rootid)" mode="collect.targets"/>
236	      </xsl:if>
237	      <xsl:if test="$collect.xref.targets != 'only'">
238		<xsl:apply-templates select="$profiled-nodes//*[@id=$rootid]" mode="process.root"/>
239		<xsl:if test="$tex.math.in.alt != ''">
240		  <xsl:apply-templates select="$profiled-nodes//*[@id=$rootid]" mode="collect.tex.math"/>
241		</xsl:if>
242		<xsl:if test="$generate.manifest != 0">
243		  <xsl:call-template name="generate.manifest">
244		    <xsl:with-param name="node" select="key('id',$rootid)"/>
245		  </xsl:call-template>
246		</xsl:if>
247	      </xsl:if>
248	    </xsl:otherwise>
249	  </xsl:choose>
250	</xsl:when>
251	<xsl:otherwise>
252	  <xsl:if test="$collect.xref.targets = 'yes' or    $collect.xref.targets = 'only'">
253	    <xsl:apply-templates select="$profiled-nodes" mode="collect.targets"/>
254	  </xsl:if>
255	  <xsl:if test="$collect.xref.targets != 'only'">
256	    <xsl:apply-templates select="$profiled-nodes" mode="process.root"/>
257	    <xsl:if test="$tex.math.in.alt != ''">
258	      <xsl:apply-templates select="$profiled-nodes" mode="collect.tex.math"/>
259	    </xsl:if>
260	    <xsl:if test="$generate.manifest != 0">
261	      <xsl:call-template name="generate.manifest">
262		<xsl:with-param name="node" select="$profiled-nodes"/>
263	      </xsl:call-template>
264	    </xsl:if>
265	  </xsl:if>
266	</xsl:otherwise>
267      </xsl:choose>
268    </xsl:otherwise>
269  </xsl:choose>
270</xsl:template>
271
272<xsl:template match="*" mode="process.root">
273  <xsl:apply-templates select="."/>
274</xsl:template>
275
276<!-- ====================================================================== -->
277
278<xsl:template match="set|book|part|preface|chapter|appendix                      |article                      |reference|refentry                      |book/glossary|article/glossary|part/glossary                      |book/bibliography|article/bibliography|part/bibliography                      |colophon">
279  <xsl:choose>
280    <xsl:when test="$onechunk != 0 and parent::*">
281      <xsl:apply-imports/>
282    </xsl:when>
283    <xsl:otherwise>
284      <xsl:call-template name="process-chunk-element"/>
285    </xsl:otherwise>
286  </xsl:choose>
287</xsl:template>
288
289<xsl:template match="sect1|sect2|sect3|sect4|sect5|section">
290  <xsl:variable name="ischunk">
291    <xsl:call-template name="chunk"/>
292  </xsl:variable>
293
294  <xsl:choose>
295    <xsl:when test="not(parent::*)">
296      <xsl:call-template name="process-chunk-element"/>
297    </xsl:when>
298    <xsl:when test="$ischunk = 0">
299      <xsl:apply-imports/>
300    </xsl:when>
301    <xsl:otherwise>
302      <xsl:call-template name="process-chunk-element"/>
303    </xsl:otherwise>
304  </xsl:choose>
305</xsl:template>
306
307<xsl:template match="setindex                      |book/index                      |article/index                      |part/index">
308  <!-- some implementations use completely empty index tags to indicate -->
309  <!-- where an automatically generated index should be inserted. so -->
310  <!-- if the index is completely empty, skip it. -->
311  <xsl:if test="count(*)&gt;0 or $generate.index != '0'">
312    <xsl:call-template name="process-chunk-element"/>
313  </xsl:if>
314</xsl:template>
315
316<!-- ==================================================================== -->
317
318<xsl:template name="make.lots">
319  <xsl:param name="toc.params" select="''"/>
320  <xsl:param name="toc"/>
321
322  <xsl:variable name="lots">
323    <xsl:if test="contains($toc.params, 'toc')">
324      <xsl:copy-of select="$toc"/>
325    </xsl:if>
326
327    <xsl:if test="contains($toc.params, 'figure')">
328      <xsl:choose>
329        <xsl:when test="$chunk.separate.lots != '0'">
330          <xsl:call-template name="make.lot.chunk">
331            <xsl:with-param name="type" select="'figure'"/>
332            <xsl:with-param name="lot">
333              <xsl:call-template name="list.of.titles">
334                <xsl:with-param name="titles" select="'figure'"/>
335                <xsl:with-param name="nodes" select=".//figure"/>
336              </xsl:call-template>
337            </xsl:with-param>
338          </xsl:call-template>
339        </xsl:when>
340        <xsl:otherwise>
341          <xsl:call-template name="list.of.titles">
342            <xsl:with-param name="titles" select="'figure'"/>
343            <xsl:with-param name="nodes" select=".//figure"/>
344          </xsl:call-template>
345        </xsl:otherwise>
346      </xsl:choose>
347    </xsl:if>
348
349    <xsl:if test="contains($toc.params, 'table')">
350      <xsl:choose>
351        <xsl:when test="$chunk.separate.lots != '0'">
352          <xsl:call-template name="make.lot.chunk">
353            <xsl:with-param name="type" select="'table'"/>
354            <xsl:with-param name="lot">
355              <xsl:call-template name="list.of.titles">
356                <xsl:with-param name="titles" select="'table'"/>
357                <xsl:with-param name="nodes" select=".//table"/>
358              </xsl:call-template>
359            </xsl:with-param>
360          </xsl:call-template>
361        </xsl:when>
362        <xsl:otherwise>
363          <xsl:call-template name="list.of.titles">
364            <xsl:with-param name="titles" select="'table'"/>
365            <xsl:with-param name="nodes" select=".//table"/>
366          </xsl:call-template>
367        </xsl:otherwise>
368      </xsl:choose>
369    </xsl:if>
370
371    <xsl:if test="contains($toc.params, 'example')">
372      <xsl:choose>
373        <xsl:when test="$chunk.separate.lots != '0'">
374          <xsl:call-template name="make.lot.chunk">
375            <xsl:with-param name="type" select="'example'"/>
376            <xsl:with-param name="lot">
377              <xsl:call-template name="list.of.titles">
378                <xsl:with-param name="titles" select="'example'"/>
379                <xsl:with-param name="nodes" select=".//example"/>
380              </xsl:call-template>
381            </xsl:with-param>
382          </xsl:call-template>
383        </xsl:when>
384        <xsl:otherwise>
385          <xsl:call-template name="list.of.titles">
386            <xsl:with-param name="titles" select="'example'"/>
387            <xsl:with-param name="nodes" select=".//example"/>
388          </xsl:call-template>
389        </xsl:otherwise>
390      </xsl:choose>
391    </xsl:if>
392
393    <xsl:if test="contains($toc.params, 'equation')">
394      <xsl:choose>
395        <xsl:when test="$chunk.separate.lots != '0'">
396          <xsl:call-template name="make.lot.chunk">
397            <xsl:with-param name="type" select="'equation'"/>
398            <xsl:with-param name="lot">
399              <xsl:call-template name="list.of.titles">
400                <xsl:with-param name="titles" select="'equation'"/>
401                <xsl:with-param name="nodes" select=".//equation"/>
402              </xsl:call-template>
403            </xsl:with-param>
404          </xsl:call-template>
405        </xsl:when>
406        <xsl:otherwise>
407          <xsl:call-template name="list.of.titles">
408            <xsl:with-param name="titles" select="'equation'"/>
409            <xsl:with-param name="nodes" select=".//equation"/>
410          </xsl:call-template>
411        </xsl:otherwise>
412      </xsl:choose>
413    </xsl:if>
414
415    <xsl:if test="contains($toc.params, 'procedure')">
416      <xsl:choose>
417        <xsl:when test="$chunk.separate.lots != '0'">
418          <xsl:call-template name="make.lot.chunk">
419            <xsl:with-param name="type" select="'procedure'"/>
420            <xsl:with-param name="lot">
421              <xsl:call-template name="list.of.titles">
422                <xsl:with-param name="titles" select="'procedure'"/>
423                <xsl:with-param name="nodes" select=".//procedure[title]"/>
424              </xsl:call-template>
425            </xsl:with-param>
426          </xsl:call-template>
427        </xsl:when>
428        <xsl:otherwise>
429          <xsl:call-template name="list.of.titles">
430            <xsl:with-param name="titles" select="'procedure'"/>
431            <xsl:with-param name="nodes" select=".//procedure[title]"/>
432          </xsl:call-template>
433        </xsl:otherwise>
434      </xsl:choose>
435    </xsl:if>
436  </xsl:variable>
437
438  <xsl:if test="string($lots) != ''">
439    <xsl:choose>
440      <xsl:when test="$chunk.tocs.and.lots != 0 and not(parent::*)">
441        <xsl:call-template name="write.chunk">
442          <xsl:with-param name="filename">
443            <xsl:call-template name="make-relative-filename">
444              <xsl:with-param name="base.dir" select="$base.dir"/>
445              <xsl:with-param name="base.name">
446                <xsl:call-template name="dbhtml-dir"/>
447                <xsl:apply-templates select="." mode="recursive-chunk-filename">
448                  <xsl:with-param name="recursive" select="true()"/>
449                </xsl:apply-templates>
450                <xsl:text>-toc</xsl:text>
451                <xsl:value-of select="$html.ext"/>
452              </xsl:with-param>
453            </xsl:call-template>
454          </xsl:with-param>
455          <xsl:with-param name="content">
456            <xsl:call-template name="chunk-element-content">
457              <xsl:with-param name="prev" select="/foo"/>
458              <xsl:with-param name="next" select="/foo"/>
459              <xsl:with-param name="nav.context" select="'toc'"/>
460              <xsl:with-param name="content">
461		<xsl:if test="$chunk.tocs.and.lots.has.title != 0">
462		  <h1>
463		    <xsl:apply-templates select="." mode="object.title.markup"/>
464		  </h1>
465		</xsl:if>
466                <xsl:copy-of select="$lots"/>
467              </xsl:with-param>
468            </xsl:call-template>
469          </xsl:with-param>
470          <xsl:with-param name="quiet" select="$chunk.quietly"/>
471        </xsl:call-template>
472      </xsl:when>
473      <xsl:otherwise>
474        <xsl:copy-of select="$lots"/>
475      </xsl:otherwise>
476    </xsl:choose>
477  </xsl:if>
478</xsl:template>
479
480<xsl:template name="make.lot.chunk">
481  <xsl:param name="type" select="''"/>
482  <xsl:param name="lot"/>
483
484  <xsl:if test="string($lot) != ''">
485    <xsl:variable name="filename">
486      <xsl:call-template name="make-relative-filename">
487        <xsl:with-param name="base.dir" select="$base.dir"/>
488        <xsl:with-param name="base.name">
489          <xsl:call-template name="dbhtml-dir"/>
490          <xsl:value-of select="$type"/>
491          <xsl:text>-toc</xsl:text>
492          <xsl:value-of select="$html.ext"/>
493        </xsl:with-param>
494      </xsl:call-template>
495    </xsl:variable>
496
497    <xsl:variable name="href">
498      <xsl:call-template name="make-relative-filename">
499        <xsl:with-param name="base.name">
500          <xsl:call-template name="dbhtml-dir"/>
501          <xsl:value-of select="$type"/>
502          <xsl:text>-toc</xsl:text>
503          <xsl:value-of select="$html.ext"/>
504        </xsl:with-param>
505      </xsl:call-template>
506    </xsl:variable>
507
508    <xsl:call-template name="write.chunk">
509      <xsl:with-param name="filename" select="$filename"/>
510      <xsl:with-param name="content">
511        <xsl:call-template name="chunk-element-content">
512          <xsl:with-param name="prev" select="/foo"/>
513          <xsl:with-param name="next" select="/foo"/>
514          <xsl:with-param name="nav.context" select="'toc'"/>
515          <xsl:with-param name="content">
516            <xsl:copy-of select="$lot"/>
517          </xsl:with-param>
518        </xsl:call-template>
519      </xsl:with-param>
520      <xsl:with-param name="quiet" select="$chunk.quietly"/>
521    </xsl:call-template>
522    <!-- And output a link to this file -->
523    <div>
524      <xsl:attribute name="class">
525        <xsl:text>ListofTitles</xsl:text>
526      </xsl:attribute>
527      <a href="{$href}">
528        <xsl:call-template name="gentext">
529          <xsl:with-param name="key">
530            <xsl:choose>
531              <xsl:when test="$type='table'">ListofTables</xsl:when>
532              <xsl:when test="$type='figure'">ListofFigures</xsl:when>
533              <xsl:when test="$type='equation'">ListofEquations</xsl:when>
534              <xsl:when test="$type='example'">ListofExamples</xsl:when>
535              <xsl:when test="$type='procedure'">ListofProcedures</xsl:when>
536              <xsl:otherwise>ListofUnknown</xsl:otherwise>
537            </xsl:choose>
538          </xsl:with-param>
539        </xsl:call-template>
540      </a>
541    </div>
542  </xsl:if>
543</xsl:template>
544
545<!-- ==================================================================== -->
546
547<xsl:template name="in.other.chunk">
548  <xsl:param name="chunk" select="."/>
549  <xsl:param name="node" select="."/>
550
551  <xsl:variable name="is.chunk">
552    <xsl:call-template name="chunk">
553      <xsl:with-param name="node" select="$node"/>
554    </xsl:call-template>
555  </xsl:variable>
556
557<!--
558  <xsl:message>
559    <xsl:text>in.other.chunk: </xsl:text>
560    <xsl:value-of select="name($chunk)"/>
561    <xsl:text> </xsl:text>
562    <xsl:value-of select="name($node)"/>
563    <xsl:text> </xsl:text>
564    <xsl:value-of select="$chunk = $node"/>
565    <xsl:text> </xsl:text>
566    <xsl:value-of select="$is.chunk"/>
567  </xsl:message>
568-->
569
570  <xsl:choose>
571    <xsl:when test="$chunk = $node">0</xsl:when>
572    <xsl:when test="$is.chunk = 1">1</xsl:when>
573    <xsl:when test="count($node) = 0">0</xsl:when>
574    <xsl:otherwise>
575      <xsl:call-template name="in.other.chunk">
576        <xsl:with-param name="chunk" select="$chunk"/>
577        <xsl:with-param name="node" select="$node/parent::*"/>
578      </xsl:call-template>
579    </xsl:otherwise>
580  </xsl:choose>
581</xsl:template>
582
583<xsl:template name="count.footnotes.in.this.chunk">
584  <xsl:param name="node" select="."/>
585  <xsl:param name="footnotes" select="$node//footnote"/>
586  <xsl:param name="count" select="0"/>
587
588<!--
589  <xsl:message>
590    <xsl:text>count.footnotes.in.this.chunk: </xsl:text>
591    <xsl:value-of select="name($node)"/>
592  </xsl:message>
593-->
594
595  <xsl:variable name="in.other.chunk">
596    <xsl:call-template name="in.other.chunk">
597      <xsl:with-param name="chunk" select="$node"/>
598      <xsl:with-param name="node" select="$footnotes[1]"/>
599    </xsl:call-template>
600  </xsl:variable>
601
602  <xsl:choose>
603    <xsl:when test="count($footnotes) = 0">
604      <xsl:value-of select="$count"/>
605    </xsl:when>
606    <xsl:otherwise>
607      <xsl:choose>
608        <xsl:when test="$in.other.chunk != 0">
609          <xsl:call-template name="count.footnotes.in.this.chunk">
610            <xsl:with-param name="node" select="$node"/>
611            <xsl:with-param name="footnotes" select="$footnotes[position() &gt; 1]"/>
612            <xsl:with-param name="count" select="$count"/>
613          </xsl:call-template>
614        </xsl:when>
615        <xsl:when test="$footnotes[1]/ancestor::table                         |$footnotes[1]/ancestor::informaltable">
616          <xsl:call-template name="count.footnotes.in.this.chunk">
617            <xsl:with-param name="node" select="$node"/>
618            <xsl:with-param name="footnotes" select="$footnotes[position() &gt; 1]"/>
619            <xsl:with-param name="count" select="$count"/>
620          </xsl:call-template>
621        </xsl:when>
622        <xsl:otherwise>
623          <xsl:call-template name="count.footnotes.in.this.chunk">
624            <xsl:with-param name="node" select="$node"/>
625            <xsl:with-param name="footnotes" select="$footnotes[position() &gt; 1]"/>
626            <xsl:with-param name="count" select="$count + 1"/>
627          </xsl:call-template>
628        </xsl:otherwise>
629      </xsl:choose>
630    </xsl:otherwise>
631  </xsl:choose>
632</xsl:template>
633
634<xsl:template name="process.footnotes.in.this.chunk">
635  <xsl:param name="node" select="."/>
636  <xsl:param name="footnotes" select="$node//footnote"/>
637
638<!--
639  <xsl:message>process.footnotes.in.this.chunk</xsl:message>
640-->
641
642  <xsl:variable name="in.other.chunk">
643    <xsl:call-template name="in.other.chunk">
644      <xsl:with-param name="chunk" select="$node"/>
645      <xsl:with-param name="node" select="$footnotes[1]"/>
646    </xsl:call-template>
647  </xsl:variable>
648
649  <xsl:choose>
650    <xsl:when test="count($footnotes) = 0">
651      <!-- nop -->
652    </xsl:when>
653    <xsl:otherwise>
654      <xsl:choose>
655        <xsl:when test="$in.other.chunk != 0">
656          <xsl:call-template name="process.footnotes.in.this.chunk">
657            <xsl:with-param name="node" select="$node"/>
658            <xsl:with-param name="footnotes" select="$footnotes[position() &gt; 1]"/>
659          </xsl:call-template>
660        </xsl:when>
661        <xsl:when test="$footnotes[1]/ancestor::table                         |$footnotes[1]/ancestor::informaltable">
662          <xsl:call-template name="process.footnotes.in.this.chunk">
663            <xsl:with-param name="node" select="$node"/>
664            <xsl:with-param name="footnotes" select="$footnotes[position() &gt; 1]"/>
665          </xsl:call-template>
666        </xsl:when>
667        <xsl:otherwise>
668          <xsl:apply-templates select="$footnotes[1]" mode="process.footnote.mode"/>
669          <xsl:call-template name="process.footnotes.in.this.chunk">
670            <xsl:with-param name="node" select="$node"/>
671            <xsl:with-param name="footnotes" select="$footnotes[position() &gt; 1]"/>
672          </xsl:call-template>
673        </xsl:otherwise>
674      </xsl:choose>
675    </xsl:otherwise>
676  </xsl:choose>
677</xsl:template>
678
679<xsl:template name="process.footnotes">
680  <xsl:variable name="footnotes" select=".//footnote"/>
681  <xsl:variable name="fcount">
682    <xsl:call-template name="count.footnotes.in.this.chunk">
683      <xsl:with-param name="node" select="."/>
684      <xsl:with-param name="footnotes" select="$footnotes"/>
685    </xsl:call-template>
686  </xsl:variable>
687
688<!--
689  <xsl:message>
690    <xsl:value-of select="name(.)"/>
691    <xsl:text> fcount: </xsl:text>
692    <xsl:value-of select="$fcount"/>
693  </xsl:message>
694-->
695
696  <!-- Only bother to do this if there's at least one non-table footnote -->
697  <xsl:if test="$fcount &gt; 0">
698    <div class="footnotes">
699      <br/>
700      <hr width="100" align="left"/>
701      <xsl:call-template name="process.footnotes.in.this.chunk">
702        <xsl:with-param name="node" select="."/>
703        <xsl:with-param name="footnotes" select="$footnotes"/>
704      </xsl:call-template>
705    </div>
706  </xsl:if>
707
708  <!-- FIXME: When chunking, only the annotations actually used
709              in this chunk should be referenced. I don't think it
710	      does any harm to reference them all, but it adds
711	      unnecessary bloat to each chunk. -->
712  <xsl:if test="$annotation.support != 0 and //annotation">
713    <div class="annotation-list">
714      <div class="annotation-nocss">
715	<p>The following annotations are from this essay. You are seeing
716	them here because your browser doesn&#8217;t support the user-interface
717	techniques used to make them appear as &#8216;popups&#8217; on modern browsers.</p>
718      </div>
719
720      <xsl:apply-templates select="//annotation" mode="annotation-popup"/>
721    </div>
722  </xsl:if>
723</xsl:template>
724
725<xsl:template name="process.chunk.footnotes">
726  <xsl:variable name="is.chunk">
727    <xsl:call-template name="chunk"/>
728  </xsl:variable>
729  <xsl:if test="$is.chunk = 1">
730    <xsl:call-template name="process.footnotes"/>
731  </xsl:if>
732</xsl:template>
733
734<!-- ====================================================================== -->
735
736<!-- Resolve xml:base attributes -->
737<xsl:template match="@fileref">
738  <!-- need a check for absolute urls -->
739  <xsl:choose>
740    <xsl:when test="contains(., ':')">
741      <!-- it has a uri scheme so it is an absolute uri -->
742      <xsl:value-of select="."/>
743    </xsl:when>
744    <xsl:otherwise>
745      <!-- its a relative uri -->
746      <xsl:call-template name="relative-uri">
747        <xsl:with-param name="destdir">
748          <xsl:call-template name="dbhtml-dir">
749            <xsl:with-param name="context" select=".."/>
750          </xsl:call-template>
751        </xsl:with-param>
752      </xsl:call-template>
753    </xsl:otherwise>
754  </xsl:choose>
755</xsl:template>
756
757</xsl:stylesheet>
758