]> git.stg.codes - stg.git/blob - doc/xslt/xhtml/chunktoc.xsl
Set output encoding to utf-8.
[stg.git] / doc / xslt / xhtml / chunktoc.xsl
1 <?xml version="1.0" encoding="ASCII"?>
2 <!--This file was created automatically by html2xhtml-->
3 <!--from the HTML stylesheets.-->
4 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" xmlns:exsl="http://exslt.org/common" xmlns:ng="http://docbook.org/docbook-ng" xmlns:db="http://docbook.org/ns/docbook" xmlns="http://www.w3.org/1999/xhtml" version="1.0" exclude-result-prefixes="doc exsl ng db">
5
6 <!-- ********************************************************************
7      $Id: chunktoc.xsl 8545 2009-12-02 07:22:10Z bobstayton $
8      ********************************************************************
9
10      This file is part of the XSL DocBook Stylesheet distribution.
11      See ../README or http://docbook.sf.net/release/xsl/current/ for
12      copyright 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="pi.dbhtml_filename">
53       <xsl:with-param name="node" select="$chunk"/>
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" select="($chunk/preceding::tocentry                          |$chunk/ancestor::tocentry)[last()]/@linkend"/>
78   <xsl:variable name="next-id" select="($chunk/following::tocentry                          |$chunk/child::tocentry)[1]/@linkend"/>
79
80   <xsl:variable name="prev" select="key('id',$prev-id)"/>
81   <xsl:variable name="next" select="key('id',$next-id)"/>
82
83   <xsl:variable name="ischunk">
84     <xsl:call-template name="chunk"/>
85   </xsl:variable>
86
87   <xsl:variable name="chunkfn">
88     <xsl:if test="$ischunk='1'">
89       <xsl:apply-templates mode="chunk-filename" select="."/>
90     </xsl:if>
91   </xsl:variable>
92
93   <xsl:variable name="filename">
94     <xsl:call-template name="make-relative-filename">
95       <xsl:with-param name="base.dir" select="$base.dir"/>
96       <xsl:with-param name="base.name" select="$chunkfn"/>
97     </xsl:call-template>
98   </xsl:variable>
99
100   <xsl:choose>
101     <xsl:when test="$ischunk = 0">
102       <xsl:apply-imports/>
103     </xsl:when>
104
105     <xsl:otherwise>
106       <xsl:call-template name="write.chunk">
107         <xsl:with-param name="filename" select="$filename"/>
108         <xsl:with-param name="content">
109           <xsl:call-template name="chunk-element-content">
110             <xsl:with-param name="prev" select="$prev"/>
111             <xsl:with-param name="next" select="$next"/>
112           </xsl:call-template>
113         </xsl:with-param>
114         <xsl:with-param name="quiet" select="$chunk.quietly"/>
115       </xsl:call-template>
116     </xsl:otherwise>
117   </xsl:choose>
118 </xsl:template>
119
120 <!-- ==================================================================== -->
121
122 <xsl:template match="set">
123   <xsl:call-template name="process-chunk"/>
124 </xsl:template>
125
126 <xsl:template match="book">
127   <xsl:call-template name="process-chunk"/>
128 </xsl:template>
129
130 <xsl:template match="appendix">
131   <xsl:call-template name="process-chunk"/>
132 </xsl:template>
133
134 <xsl:template match="book/glossary">
135   <xsl:call-template name="process-chunk"/>
136 </xsl:template>
137
138 <xsl:template match="book/bibliography">
139   <xsl:call-template name="process-chunk"/>
140 </xsl:template>
141
142 <xsl:template match="dedication" mode="dedication">
143   <xsl:call-template name="process-chunk"/>
144 </xsl:template>
145
146 <xsl:template match="preface|chapter">
147   <xsl:call-template name="process-chunk"/>
148 </xsl:template>
149
150 <xsl:template match="part|reference">
151   <xsl:call-template name="process-chunk"/>
152 </xsl:template>
153
154 <xsl:template match="refentry">
155   <xsl:call-template name="process-chunk"/>
156 </xsl:template>
157
158 <xsl:template match="colophon">
159   <xsl:call-template name="process-chunk"/>
160 </xsl:template>
161
162 <xsl:template match="article">
163   <xsl:call-template name="process-chunk"/>
164 </xsl:template>
165
166 <xsl:template match="article/glossary">
167   <xsl:call-template name="process-chunk"/>
168 </xsl:template>
169
170 <xsl:template match="article/bibliography">
171   <xsl:call-template name="process-chunk"/>
172 </xsl:template>
173
174 <xsl:template match="sect1|sect2|sect3|sect4|sect5|section">
175   <xsl:variable name="ischunk">
176     <xsl:call-template name="chunk"/>
177   </xsl:variable>
178
179   <xsl:choose>
180     <xsl:when test="$ischunk != 0">
181       <xsl:call-template name="process-chunk"/>
182     </xsl:when>
183     <xsl:otherwise>
184       <xsl:apply-imports/>
185     </xsl:otherwise>
186   </xsl:choose>
187 </xsl:template>
188
189 <xsl:template match="setindex                      |book/index                      |article/index">
190   <!-- some implementations use completely empty index tags to indicate -->
191   <!-- where an automatically generated index should be inserted. so -->
192   <!-- if the index is completely empty, skip it. -->
193   <xsl:if test="count(*)&gt;0 or $generate.index != '0'">
194     <xsl:call-template name="process-chunk"/>
195   </xsl:if>
196 </xsl:template>
197
198 <!-- ==================================================================== -->
199
200 <xsl:template match="/">
201   <!-- * Get a title for current doc so that we let the user -->
202   <!-- * know what document we are processing at this point. -->
203   <xsl:variable name="doc.title">
204     <xsl:call-template name="get.doc.title"/>
205   </xsl:variable>
206   <xsl:choose>
207     <xsl:when test="$chunk.toc = ''">
208       <xsl:message terminate="yes">
209         <xsl:text>The chunk.toc file is not set.</xsl:text>
210       </xsl:message>
211     </xsl:when>
212     <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
213          toss the namespace and continue.  Use the docbook5 namespaced
214          stylesheets for DocBook5 if you don't want to use this feature.-->
215     <!-- include extra test for Xalan quirk -->
216     <xsl:when test="$exsl.node.set.available != 0                     and (*/self::ng:* or */self::db:*)">
217       <xsl:call-template name="log.message">
218         <xsl:with-param name="level">Note</xsl:with-param>
219         <xsl:with-param name="source" select="$doc.title"/>
220         <xsl:with-param name="context-desc">
221           <xsl:text>namesp. cut</xsl:text>
222         </xsl:with-param>
223         <xsl:with-param name="message">
224           <xsl:text>stripped namespace before processing</xsl:text>
225         </xsl:with-param>
226       </xsl:call-template>
227       <xsl:variable name="nons">
228         <xsl:apply-templates mode="stripNS"/>
229       </xsl:variable>
230       <xsl:call-template name="log.message">
231         <xsl:with-param name="level">Note</xsl:with-param>
232         <xsl:with-param name="source" select="$doc.title"/>
233         <xsl:with-param name="context-desc">
234           <xsl:text>namesp. cut</xsl:text>
235         </xsl:with-param>
236         <xsl:with-param name="message">
237           <xsl:text>processing stripped document</xsl:text>
238         </xsl:with-param>
239       </xsl:call-template>
240       <xsl:apply-templates select="exsl:node-set($nons)"/>
241     </xsl:when>
242     <!-- Can't process unless namespace removed -->
243     <xsl:when test="*/self::ng:* or */self::db:*">
244       <xsl:message terminate="yes">
245         <xsl:text>Unable to strip the namespace from DB5 document,</xsl:text>
246         <xsl:text> cannot proceed.</xsl:text>
247       </xsl:message>
248     </xsl:when>
249     <xsl:otherwise>
250       <xsl:choose>
251         <xsl:when test="$rootid != ''">
252           <xsl:choose>
253             <xsl:when test="count(key('id',$rootid)) = 0">
254               <xsl:message terminate="yes">
255                 <xsl:text>ID '</xsl:text>
256                 <xsl:value-of select="$rootid"/>
257                 <xsl:text>' not found in document.</xsl:text>
258               </xsl:message>
259             </xsl:when>
260             <xsl:otherwise>
261               <xsl:if test="$collect.xref.targets = 'yes' or                             $collect.xref.targets = 'only'">
262                 <xsl:apply-templates select="key('id', $rootid)" mode="collect.targets"/>
263               </xsl:if>
264               <xsl:if test="$collect.xref.targets != 'only'">
265                 <xsl:apply-templates select="key('id',$rootid)" mode="process.root"/>
266                 <xsl:if test="$tex.math.in.alt != ''">
267                   <xsl:apply-templates select="key('id',$rootid)" mode="collect.tex.math"/>
268                 </xsl:if>
269                 <xsl:if test="$generate.manifest != 0">
270                   <xsl:call-template name="generate.manifest">
271                     <xsl:with-param name="node" select="key('id',$rootid)"/>
272                   </xsl:call-template>
273                 </xsl:if>
274               </xsl:if>
275             </xsl:otherwise>
276           </xsl:choose>
277         </xsl:when>
278         <xsl:otherwise>
279           <xsl:if test="$collect.xref.targets = 'yes' or                         $collect.xref.targets = 'only'">
280             <xsl:apply-templates select="/" mode="collect.targets"/>
281           </xsl:if>
282           <xsl:if test="$collect.xref.targets != 'only'">
283             <xsl:apply-templates select="/" mode="process.root"/>
284             <xsl:if test="$tex.math.in.alt != ''">
285               <xsl:apply-templates select="/" mode="collect.tex.math"/>
286             </xsl:if>
287             <xsl:if test="$generate.manifest != 0">
288               <xsl:call-template name="generate.manifest">
289                 <xsl:with-param name="node" select="/"/>
290               </xsl:call-template>
291             </xsl:if>
292           </xsl:if>
293         </xsl:otherwise>
294       </xsl:choose>
295     </xsl:otherwise>
296   </xsl:choose>
297 </xsl:template>
298
299 <xsl:template match="*" mode="process.root">
300   <xsl:apply-templates select="."/>
301 </xsl:template>
302
303 <xsl:template name="make.lots">
304   <xsl:param name="toc.params" select="''"/>
305   <xsl:param name="toc"/>
306
307   <xsl:variable name="lots">
308     <xsl:if test="contains($toc.params, 'toc')">
309       <xsl:copy-of select="$toc"/>
310     </xsl:if>
311
312     <xsl:if test="contains($toc.params, 'figure')">
313       <xsl:choose>
314         <xsl:when test="$chunk.separate.lots != '0'">
315           <xsl:call-template name="make.lot.chunk">
316             <xsl:with-param name="type" select="'figure'"/>
317             <xsl:with-param name="lot">
318               <xsl:call-template name="list.of.titles">
319                 <xsl:with-param name="titles" select="'figure'"/>
320                 <xsl:with-param name="nodes" select=".//figure"/>
321               </xsl:call-template>
322             </xsl:with-param>
323           </xsl:call-template>
324         </xsl:when>
325         <xsl:otherwise>
326           <xsl:call-template name="list.of.titles">
327             <xsl:with-param name="titles" select="'figure'"/>
328             <xsl:with-param name="nodes" select=".//figure"/>
329           </xsl:call-template>
330         </xsl:otherwise>
331       </xsl:choose>
332     </xsl:if>
333
334     <xsl:if test="contains($toc.params, 'table')">
335       <xsl:choose>
336         <xsl:when test="$chunk.separate.lots != '0'">
337           <xsl:call-template name="make.lot.chunk">
338             <xsl:with-param name="type" select="'table'"/>
339             <xsl:with-param name="lot">
340               <xsl:call-template name="list.of.titles">
341                 <xsl:with-param name="titles" select="'table'"/>
342                 <xsl:with-param name="nodes" select=".//table"/>
343               </xsl:call-template>
344             </xsl:with-param>
345           </xsl:call-template>
346         </xsl:when>
347         <xsl:otherwise>
348           <xsl:call-template name="list.of.titles">
349             <xsl:with-param name="titles" select="'table'"/>
350             <xsl:with-param name="nodes" select=".//table"/>
351           </xsl:call-template>
352         </xsl:otherwise>
353       </xsl:choose>
354     </xsl:if>
355
356     <xsl:if test="contains($toc.params, 'example')">
357       <xsl:choose>
358         <xsl:when test="$chunk.separate.lots != '0'">
359           <xsl:call-template name="make.lot.chunk">
360             <xsl:with-param name="type" select="'example'"/>
361             <xsl:with-param name="lot">
362               <xsl:call-template name="list.of.titles">
363                 <xsl:with-param name="titles" select="'example'"/>
364                 <xsl:with-param name="nodes" select=".//example"/>
365               </xsl:call-template>
366             </xsl:with-param>
367           </xsl:call-template>
368         </xsl:when>
369         <xsl:otherwise>
370           <xsl:call-template name="list.of.titles">
371             <xsl:with-param name="titles" select="'example'"/>
372             <xsl:with-param name="nodes" select=".//example"/>
373           </xsl:call-template>
374         </xsl:otherwise>
375       </xsl:choose>
376     </xsl:if>
377
378     <xsl:if test="contains($toc.params, 'equation')">
379       <xsl:choose>
380         <xsl:when test="$chunk.separate.lots != '0'">
381           <xsl:call-template name="make.lot.chunk">
382             <xsl:with-param name="type" select="'equation'"/>
383             <xsl:with-param name="lot">
384               <xsl:call-template name="list.of.titles">
385                 <xsl:with-param name="titles" select="'equation'"/>
386                 <xsl:with-param name="nodes" select=".//equation"/>
387               </xsl:call-template>
388             </xsl:with-param>
389           </xsl:call-template>
390         </xsl:when>
391         <xsl:otherwise>
392           <xsl:call-template name="list.of.titles">
393             <xsl:with-param name="titles" select="'equation'"/>
394             <xsl:with-param name="nodes" select=".//equation"/>
395           </xsl:call-template>
396         </xsl:otherwise>
397       </xsl:choose>
398     </xsl:if>
399
400     <xsl:if test="contains($toc.params, 'procedure')">
401       <xsl:choose>
402         <xsl:when test="$chunk.separate.lots != '0'">
403           <xsl:call-template name="make.lot.chunk">
404             <xsl:with-param name="type" select="'procedure'"/>
405             <xsl:with-param name="lot">
406               <xsl:call-template name="list.of.titles">
407                 <xsl:with-param name="titles" select="'procedure'"/>
408                 <xsl:with-param name="nodes" select=".//procedure[title]"/>
409               </xsl:call-template>
410             </xsl:with-param>
411           </xsl:call-template>
412         </xsl:when>
413         <xsl:otherwise>
414           <xsl:call-template name="list.of.titles">
415             <xsl:with-param name="titles" select="'procedure'"/>
416             <xsl:with-param name="nodes" select=".//procedure[title]"/>
417           </xsl:call-template>
418         </xsl:otherwise>
419       </xsl:choose>
420     </xsl:if>
421   </xsl:variable>
422
423   <xsl:if test="string($lots) != ''">
424     <xsl:choose>
425       <xsl:when test="$chunk.tocs.and.lots != 0 and not(parent::*)">
426         <xsl:call-template name="write.chunk">
427           <xsl:with-param name="filename">
428             <xsl:call-template name="make-relative-filename">
429               <xsl:with-param name="base.dir" select="$base.dir"/>
430               <xsl:with-param name="base.name">
431                 <xsl:call-template name="dbhtml-dir"/>
432                 <xsl:apply-templates select="." mode="recursive-chunk-filename">
433                   <xsl:with-param name="recursive" select="true()"/>
434                 </xsl:apply-templates>
435                 <xsl:text>-toc</xsl:text>
436                 <xsl:value-of select="$html.ext"/>
437               </xsl:with-param>
438             </xsl:call-template>
439           </xsl:with-param>
440           <xsl:with-param name="content">
441             <xsl:call-template name="chunk-element-content">
442               <xsl:with-param name="prev" select="/foo"/>
443               <xsl:with-param name="next" select="/foo"/>
444               <xsl:with-param name="nav.context" select="'toc'"/>
445               <xsl:with-param name="content">
446                 <h1>
447                   <xsl:apply-templates select="." mode="object.title.markup"/>
448                 </h1>
449                 <xsl:copy-of select="$lots"/>
450               </xsl:with-param>
451             </xsl:call-template>
452           </xsl:with-param>
453           <xsl:with-param name="quiet" select="$chunk.quietly"/>
454         </xsl:call-template>
455       </xsl:when>
456       <xsl:otherwise>
457         <xsl:copy-of select="$lots"/>
458       </xsl:otherwise>
459     </xsl:choose>
460   </xsl:if>
461 </xsl:template>
462
463 <xsl:template name="make.lot.chunk">
464   <xsl:param name="type" select="''"/>
465   <xsl:param name="lot"/>
466
467   <xsl:if test="string($lot) != ''">
468     <xsl:variable name="filename">
469       <xsl:call-template name="make-relative-filename">
470         <xsl:with-param name="base.dir" select="$base.dir"/>
471         <xsl:with-param name="base.name">
472           <xsl:call-template name="dbhtml-dir"/>
473           <xsl:value-of select="$type"/>
474           <xsl:text>-toc</xsl:text>
475           <xsl:value-of select="$html.ext"/>
476         </xsl:with-param>
477       </xsl:call-template>
478     </xsl:variable>
479
480     <xsl:variable name="href">
481       <xsl:call-template name="make-relative-filename">
482         <xsl:with-param name="base.name">
483           <xsl:call-template name="dbhtml-dir"/>
484           <xsl:value-of select="$type"/>
485           <xsl:text>-toc</xsl:text>
486           <xsl:value-of select="$html.ext"/>
487         </xsl:with-param>
488       </xsl:call-template>
489     </xsl:variable>
490
491     <xsl:call-template name="write.chunk">
492       <xsl:with-param name="filename" select="$filename"/>
493       <xsl:with-param name="content">
494         <xsl:call-template name="chunk-element-content">
495           <xsl:with-param name="prev" select="/foo"/>
496           <xsl:with-param name="next" select="/foo"/>
497           <xsl:with-param name="nav.context" select="'toc'"/>
498           <xsl:with-param name="content">
499             <xsl:copy-of select="$lot"/>
500           </xsl:with-param>
501         </xsl:call-template>
502       </xsl:with-param>
503       <xsl:with-param name="quiet" select="$chunk.quietly"/>
504     </xsl:call-template>
505     <!-- And output a link to this file -->
506     <div>
507       <xsl:attribute name="class">
508         <xsl:text>ListofTitles</xsl:text>
509       </xsl:attribute>
510       <a href="{$href}">
511         <xsl:call-template name="gentext">
512           <xsl:with-param name="key">
513             <xsl:choose>
514               <xsl:when test="$type='table'">ListofTables</xsl:when>
515               <xsl:when test="$type='figure'">ListofFigures</xsl:when>
516               <xsl:when test="$type='equation'">ListofEquations</xsl:when>
517               <xsl:when test="$type='example'">ListofExamples</xsl:when>
518               <xsl:when test="$type='procedure'">ListofProcedures</xsl:when>
519               <xsl:otherwise>ListofUnknown</xsl:otherwise>
520             </xsl:choose>
521           </xsl:with-param>
522         </xsl:call-template>
523       </a>
524     </div>
525   </xsl:if>
526 </xsl:template>
527
528 </xsl:stylesheet>