source: trunk/Distribution/XSL/html/chunktoc.xsl@ 3

Last change on this file since 3 was 2, checked in by jkacer, 18 years ago

Added all DocBook Framework stuff:

  • DocBook DTD
  • Transformation software FOP 0.20.5 and Saxon 6
  • XSL styles
  • Rexx scripts

Also added some WarpIN-related stuff for creation of WarpIN installation packages.
This state corresponds to version 1.0.0 from November 2005, just slightly modified to carry versioning information (Rexx scripts).

File size: 15.7 KB
Line 
1<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
3 version="1.0"
4 exclude-result-prefixes="doc">
5
6<!-- ********************************************************************
7 $Id: chunktoc.xsl,v 1.6 2005/05/31 07:46:52 bobstayton 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:import href="docbook.xsl"/>
19<xsl:import href="chunk-common.xsl"/>
20
21<xsl:template name="chunk">
22 <xsl:param name="node" select="."/>
23 <!-- returns 1 if $node is a chunk -->
24
25 <xsl:variable name="id">
26 <xsl:call-template name="object.id">
27 <xsl:with-param name="object" select="$node"/>
28 </xsl:call-template>
29 </xsl:variable>
30
31 <xsl:variable name="chunks" select="document($chunk.toc,/)"/>
32
33 <xsl:choose>
34 <xsl:when test="$chunks//tocentry[@linkend=$id]">1</xsl:when>
35 <xsl:otherwise>0</xsl:otherwise>
36 </xsl:choose>
37</xsl:template>
38
39<!-- ==================================================================== -->
40
41<xsl:template match="*" mode="chunk-filename">
42 <!-- returns the filename of a chunk -->
43
44 <xsl:variable name="id">
45 <xsl:call-template name="object.id"/>
46 </xsl:variable>
47
48 <xsl:variable name="chunks" select="document($chunk.toc,/)"/>
49
50 <xsl:variable name="chunk" select="$chunks//tocentry[@linkend=$id]"/>
51 <xsl:variable name="filename">
52 <xsl:call-template name="dbhtml-filename">
53 <xsl:with-param name="pis" select="$chunk/processing-instruction('dbhtml')"/>
54 </xsl:call-template>
55 </xsl:variable>
56
57 <xsl:choose>
58 <xsl:when test="$chunk">
59 <xsl:value-of select="$filename"/>
60 </xsl:when>
61 <xsl:otherwise>
62 <xsl:apply-templates select="parent::*" mode="chunk-filename"/>
63 </xsl:otherwise>
64 </xsl:choose>
65</xsl:template>
66
67<!-- ==================================================================== -->
68
69<xsl:template name="process-chunk">
70 <xsl:variable name="id">
71 <xsl:call-template name="object.id"/>
72 </xsl:variable>
73
74 <xsl:variable name="chunks" select="document($chunk.toc,/)"/>
75
76 <xsl:variable name="chunk" select="$chunks//tocentry[@linkend=$id]"/>
77 <xsl:variable name="prev-id"
78 select="($chunk/preceding::tocentry
79 |$chunk/ancestor::tocentry)[last()]/@linkend"/>
80 <xsl:variable name="next-id"
81 select="($chunk/following::tocentry
82 |$chunk/child::tocentry)[1]/@linkend"/>
83
84 <xsl:variable name="prev" select="key('id',$prev-id)"/>
85 <xsl:variable name="next" select="key('id',$next-id)"/>
86
87 <xsl:variable name="ischunk">
88 <xsl:call-template name="chunk"/>
89 </xsl:variable>
90
91 <xsl:variable name="chunkfn">
92 <xsl:if test="$ischunk='1'">
93 <xsl:apply-templates mode="chunk-filename" select="."/>
94 </xsl:if>
95 </xsl:variable>
96
97 <xsl:variable name="filename">
98 <xsl:call-template name="make-relative-filename">
99 <xsl:with-param name="base.dir" select="$base.dir"/>
100 <xsl:with-param name="base.name" select="$chunkfn"/>
101 </xsl:call-template>
102 </xsl:variable>
103
104 <xsl:choose>
105 <xsl:when test="$ischunk = 0">
106 <xsl:apply-imports/>
107 </xsl:when>
108
109 <xsl:otherwise>
110 <xsl:call-template name="write.chunk">
111 <xsl:with-param name="filename" select="$filename"/>
112 <xsl:with-param name="content">
113 <xsl:call-template name="chunk-element-content">
114 <xsl:with-param name="prev" select="$prev"/>
115 <xsl:with-param name="next" select="$next"/>
116 </xsl:call-template>
117 </xsl:with-param>
118 <xsl:with-param name="quiet" select="$chunk.quietly"/>
119 </xsl:call-template>
120 </xsl:otherwise>
121 </xsl:choose>
122</xsl:template>
123
124<!-- ==================================================================== -->
125
126<xsl:template match="set">
127 <xsl:call-template name="process-chunk"/>
128</xsl:template>
129
130<xsl:template match="book">
131 <xsl:call-template name="process-chunk"/>
132</xsl:template>
133
134<xsl:template match="book/appendix">
135 <xsl:call-template name="process-chunk"/>
136</xsl:template>
137
138<xsl:template match="book/glossary">
139 <xsl:call-template name="process-chunk"/>
140</xsl:template>
141
142<xsl:template match="book/bibliography">
143 <xsl:call-template name="process-chunk"/>
144</xsl:template>
145
146<xsl:template match="dedication" mode="dedication">
147 <xsl:call-template name="process-chunk"/>
148</xsl:template>
149
150<xsl:template match="preface|chapter">
151 <xsl:call-template name="process-chunk"/>
152</xsl:template>
153
154<xsl:template match="part|reference">
155 <xsl:call-template name="process-chunk"/>
156</xsl:template>
157
158<xsl:template match="refentry">
159 <xsl:call-template name="process-chunk"/>
160</xsl:template>
161
162<xsl:template match="colophon">
163 <xsl:call-template name="process-chunk"/>
164</xsl:template>
165
166<xsl:template match="article">
167 <xsl:call-template name="process-chunk"/>
168</xsl:template>
169
170<xsl:template match="article/appendix">
171 <xsl:call-template name="process-chunk"/>
172</xsl:template>
173
174<xsl:template match="article/glossary">
175 <xsl:call-template name="process-chunk"/>
176</xsl:template>
177
178<xsl:template match="article/bibliography">
179 <xsl:call-template name="process-chunk"/>
180</xsl:template>
181
182<xsl:template match="sect1|sect2|sect3|sect4|sect5|section">
183 <xsl:variable name="ischunk">
184 <xsl:call-template name="chunk"/>
185 </xsl:variable>
186
187 <xsl:choose>
188 <xsl:when test="$ischunk != 0">
189 <xsl:call-template name="process-chunk"/>
190 </xsl:when>
191 <xsl:otherwise>
192 <xsl:apply-imports/>
193 </xsl:otherwise>
194 </xsl:choose>
195</xsl:template>
196
197<xsl:template match="setindex
198 |book/index
199 |article/index">
200 <!-- some implementations use completely empty index tags to indicate -->
201 <!-- where an automatically generated index should be inserted. so -->
202 <!-- if the index is completely empty, skip it. -->
203 <xsl:if test="count(*)>0 or $generate.index != '0'">
204 <xsl:call-template name="process-chunk"/>
205 </xsl:if>
206</xsl:template>
207
208<!-- ==================================================================== -->
209
210<xsl:template match="/">
211 <xsl:choose>
212 <xsl:when test="$chunk.toc = ''">
213 <xsl:message terminate="yes">
214 <xsl:text>The chunk.toc file is not set.</xsl:text>
215 </xsl:message>
216 </xsl:when>
217
218 <xsl:when test="$rootid != ''">
219 <xsl:choose>
220 <xsl:when test="count(key('id',$rootid)) = 0">
221 <xsl:message terminate="yes">
222 <xsl:text>ID '</xsl:text>
223 <xsl:value-of select="$rootid"/>
224 <xsl:text>' not found in document.</xsl:text>
225 </xsl:message>
226 </xsl:when>
227 <xsl:otherwise>
228 <xsl:apply-templates select="key('id',$rootid)"/>
229 </xsl:otherwise>
230 </xsl:choose>
231 </xsl:when>
232
233 <xsl:otherwise>
234 <xsl:apply-templates select="/" mode="process.root"/>
235 </xsl:otherwise>
236 </xsl:choose>
237</xsl:template>
238
239<xsl:template match="*" mode="process.root">
240 <xsl:apply-templates select="."/>
241</xsl:template>
242
243<xsl:template name="make.lots">
244 <xsl:param name="toc.params" select="''"/>
245 <xsl:param name="toc"/>
246
247 <xsl:variable name="lots">
248 <xsl:if test="contains($toc.params, 'toc')">
249 <xsl:copy-of select="$toc"/>
250 </xsl:if>
251
252 <xsl:if test="contains($toc.params, 'figure')">
253 <xsl:choose>
254 <xsl:when test="$chunk.separate.lots != '0'">
255 <xsl:call-template name="make.lot.chunk">
256 <xsl:with-param name="type" select="'figure'"/>
257 <xsl:with-param name="lot">
258 <xsl:call-template name="list.of.titles">
259 <xsl:with-param name="titles" select="'figure'"/>
260 <xsl:with-param name="nodes" select=".//figure"/>
261 </xsl:call-template>
262 </xsl:with-param>
263 </xsl:call-template>
264 </xsl:when>
265 <xsl:otherwise>
266 <xsl:call-template name="list.of.titles">
267 <xsl:with-param name="titles" select="'figure'"/>
268 <xsl:with-param name="nodes" select=".//figure"/>
269 </xsl:call-template>
270 </xsl:otherwise>
271 </xsl:choose>
272 </xsl:if>
273
274 <xsl:if test="contains($toc.params, 'table')">
275 <xsl:choose>
276 <xsl:when test="$chunk.separate.lots != '0'">
277 <xsl:call-template name="make.lot.chunk">
278 <xsl:with-param name="type" select="'table'"/>
279 <xsl:with-param name="lot">
280 <xsl:call-template name="list.of.titles">
281 <xsl:with-param name="titles" select="'table'"/>
282 <xsl:with-param name="nodes" select=".//table"/>
283 </xsl:call-template>
284 </xsl:with-param>
285 </xsl:call-template>
286 </xsl:when>
287 <xsl:otherwise>
288 <xsl:call-template name="list.of.titles">
289 <xsl:with-param name="titles" select="'table'"/>
290 <xsl:with-param name="nodes" select=".//table"/>
291 </xsl:call-template>
292 </xsl:otherwise>
293 </xsl:choose>
294 </xsl:if>
295
296 <xsl:if test="contains($toc.params, 'example')">
297 <xsl:choose>
298 <xsl:when test="$chunk.separate.lots != '0'">
299 <xsl:call-template name="make.lot.chunk">
300 <xsl:with-param name="type" select="'example'"/>
301 <xsl:with-param name="lot">
302 <xsl:call-template name="list.of.titles">
303 <xsl:with-param name="titles" select="'example'"/>
304 <xsl:with-param name="nodes" select=".//example"/>
305 </xsl:call-template>
306 </xsl:with-param>
307 </xsl:call-template>
308 </xsl:when>
309 <xsl:otherwise>
310 <xsl:call-template name="list.of.titles">
311 <xsl:with-param name="titles" select="'example'"/>
312 <xsl:with-param name="nodes" select=".//example"/>
313 </xsl:call-template>
314 </xsl:otherwise>
315 </xsl:choose>
316 </xsl:if>
317
318 <xsl:if test="contains($toc.params, 'equation')">
319 <xsl:choose>
320 <xsl:when test="$chunk.separate.lots != '0'">
321 <xsl:call-template name="make.lot.chunk">
322 <xsl:with-param name="type" select="'equation'"/>
323 <xsl:with-param name="lot">
324 <xsl:call-template name="list.of.titles">
325 <xsl:with-param name="titles" select="'equation'"/>
326 <xsl:with-param name="nodes" select=".//equation"/>
327 </xsl:call-template>
328 </xsl:with-param>
329 </xsl:call-template>
330 </xsl:when>
331 <xsl:otherwise>
332 <xsl:call-template name="list.of.titles">
333 <xsl:with-param name="titles" select="'equation'"/>
334 <xsl:with-param name="nodes" select=".//equation"/>
335 </xsl:call-template>
336 </xsl:otherwise>
337 </xsl:choose>
338 </xsl:if>
339
340 <xsl:if test="contains($toc.params, 'procedure')">
341 <xsl:choose>
342 <xsl:when test="$chunk.separate.lots != '0'">
343 <xsl:call-template name="make.lot.chunk">
344 <xsl:with-param name="type" select="'procedure'"/>
345 <xsl:with-param name="lot">
346 <xsl:call-template name="list.of.titles">
347 <xsl:with-param name="titles" select="'procedure'"/>
348 <xsl:with-param name="nodes" select=".//procedure[title]"/>
349 </xsl:call-template>
350 </xsl:with-param>
351 </xsl:call-template>
352 </xsl:when>
353 <xsl:otherwise>
354 <xsl:call-template name="list.of.titles">
355 <xsl:with-param name="titles" select="'procedure'"/>
356 <xsl:with-param name="nodes" select=".//procedure[title]"/>
357 </xsl:call-template>
358 </xsl:otherwise>
359 </xsl:choose>
360 </xsl:if>
361 </xsl:variable>
362
363 <xsl:if test="string($lots) != ''">
364 <xsl:choose>
365 <xsl:when test="$chunk.tocs.and.lots != 0 and not(parent::*)">
366 <xsl:call-template name="write.chunk">
367 <xsl:with-param name="filename">
368 <xsl:call-template name="make-relative-filename">
369 <xsl:with-param name="base.dir" select="$base.dir"/>
370 <xsl:with-param name="base.name">
371 <xsl:call-template name="dbhtml-dir"/>
372 <xsl:apply-templates select="." mode="recursive-chunk-filename">
373 <xsl:with-param name="recursive" select="true()"/>
374 </xsl:apply-templates>
375 <xsl:text>-toc</xsl:text>
376 <xsl:value-of select="$html.ext"/>
377 </xsl:with-param>
378 </xsl:call-template>
379 </xsl:with-param>
380 <xsl:with-param name="content">
381 <xsl:call-template name="chunk-element-content">
382 <xsl:with-param name="prev" select="/foo"/>
383 <xsl:with-param name="next" select="/foo"/>
384 <xsl:with-param name="nav.context" select="'toc'"/>
385 <xsl:with-param name="content">
386 <h1>
387 <xsl:apply-templates select="." mode="object.title.markup"/>
388 </h1>
389 <xsl:copy-of select="$lots"/>
390 </xsl:with-param>
391 </xsl:call-template>
392 </xsl:with-param>
393 <xsl:with-param name="quiet" select="$chunk.quietly"/>
394 </xsl:call-template>
395 </xsl:when>
396 <xsl:otherwise>
397 <xsl:copy-of select="$lots"/>
398 </xsl:otherwise>
399 </xsl:choose>
400 </xsl:if>
401</xsl:template>
402
403<xsl:template name="make.lot.chunk">
404 <xsl:param name="type" select="''"/>
405 <xsl:param name="lot"/>
406
407 <xsl:if test="string($lot) != ''">
408 <xsl:variable name="filename">
409 <xsl:call-template name="make-relative-filename">
410 <xsl:with-param name="base.dir" select="$base.dir"/>
411 <xsl:with-param name="base.name">
412 <xsl:call-template name="dbhtml-dir"/>
413 <xsl:value-of select="$type"/>
414 <xsl:text>-toc</xsl:text>
415 <xsl:value-of select="$html.ext"/>
416 </xsl:with-param>
417 </xsl:call-template>
418 </xsl:variable>
419
420 <xsl:variable name="href">
421 <xsl:call-template name="make-relative-filename">
422 <xsl:with-param name="base.name">
423 <xsl:call-template name="dbhtml-dir"/>
424 <xsl:value-of select="$type"/>
425 <xsl:text>-toc</xsl:text>
426 <xsl:value-of select="$html.ext"/>
427 </xsl:with-param>
428 </xsl:call-template>
429 </xsl:variable>
430
431 <xsl:call-template name="write.chunk">
432 <xsl:with-param name="filename" select="$filename"/>
433 <xsl:with-param name="content">
434 <xsl:call-template name="chunk-element-content">
435 <xsl:with-param name="prev" select="/foo"/>
436 <xsl:with-param name="next" select="/foo"/>
437 <xsl:with-param name="nav.context" select="'toc'"/>
438 <xsl:with-param name="content">
439 <xsl:copy-of select="$lot"/>
440 </xsl:with-param>
441 </xsl:call-template>
442 </xsl:with-param>
443 <xsl:with-param name="quiet" select="$chunk.quietly"/>
444 </xsl:call-template>
445 <!-- And output a link to this file -->
446 <div>
447 <xsl:attribute name="class">
448 <xsl:text>ListofTitles</xsl:text>
449 </xsl:attribute>
450 <a href="{$href}">
451 <xsl:call-template name="gentext">
452 <xsl:with-param name="key">
453 <xsl:choose>
454 <xsl:when test="$type='table'">ListofTables</xsl:when>
455 <xsl:when test="$type='figure'">ListofFigures</xsl:when>
456 <xsl:when test="$type='equation'">ListofEquations</xsl:when>
457 <xsl:when test="$type='example'">ListofExamples</xsl:when>
458 <xsl:when test="$type='procedure'">ListofProcedures</xsl:when>
459 <xsl:otherwise>ListofUnknown</xsl:otherwise>
460 </xsl:choose>
461 </xsl:with-param>
462 </xsl:call-template>
463 </a>
464 </div>
465 </xsl:if>
466</xsl:template>
467
468</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.