]> git.evergreen-ils.org Git - working/Evergreen.git/blob - stylesheets/styleguide/docbook-xsl-1.75.2/xhtml-1_1/chunktoc.xsl
stylesheet changes.
[working/Evergreen.git] / stylesheets / styleguide / docbook-xsl-1.75.2 / xhtml-1_1 / 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="http://www.w3.org/1999/xhtml" version="1.0" exclude-result-prefixes="doc">
5
6 <!-- ********************************************************************
7      $Id: chunktoc.xsl 8399 2009-04-08 07:37:42Z 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="book/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/appendix">
167   <xsl:call-template name="process-chunk"/>
168 </xsl:template>
169
170 <xsl:template match="article/glossary">
171   <xsl:call-template name="process-chunk"/>
172 </xsl:template>
173
174 <xsl:template match="article/bibliography">
175   <xsl:call-template name="process-chunk"/>
176 </xsl:template>
177
178 <xsl:template match="sect1|sect2|sect3|sect4|sect5|section">
179   <xsl:variable name="ischunk">
180     <xsl:call-template name="chunk"/>
181   </xsl:variable>
182
183   <xsl:choose>
184     <xsl:when test="$ischunk != 0">
185       <xsl:call-template name="process-chunk"/>
186     </xsl:when>
187     <xsl:otherwise>
188       <xsl:apply-imports/>
189     </xsl:otherwise>
190   </xsl:choose>
191 </xsl:template>
192
193 <xsl:template match="setindex                      |book/index                      |article/index">
194   <!-- some implementations use completely empty index tags to indicate -->
195   <!-- where an automatically generated index should be inserted. so -->
196   <!-- if the index is completely empty, skip it. -->
197   <xsl:if test="count(*)&gt;0 or $generate.index != '0'">
198     <xsl:call-template name="process-chunk"/>
199   </xsl:if>
200 </xsl:template>
201
202 <!-- ==================================================================== -->
203
204 <xsl:template match="/">
205   <!-- * Get a title for current doc so that we let the user -->
206   <!-- * know what document we are processing at this point. -->
207   <xsl:variable name="doc.title">
208     <xsl:call-template name="get.doc.title"/>
209   </xsl:variable>
210   <xsl:choose>
211     <xsl:when test="$chunk.toc = ''">
212       <xsl:message terminate="yes">
213         <xsl:text>The chunk.toc file is not set.</xsl:text>
214       </xsl:message>
215     </xsl:when>
216     <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
217          toss the namespace and continue.  Use the docbook5 namespaced
218          stylesheets for DocBook5 if you don't want to use this feature.-->
219     <!-- include extra test for Xalan quirk -->
220     <xsl:when test="$exsl.node.set.available != 0                     and (*/self::ng:* or */self::db:*)">
221       <xsl:call-template name="log.message">
222         <xsl:with-param name="level">Note</xsl:with-param>
223         <xsl:with-param name="source" select="$doc.title"/>
224         <xsl:with-param name="context-desc">
225           <xsl:text>namesp. cut</xsl:text>
226         </xsl:with-param>
227         <xsl:with-param name="message">
228           <xsl:text>stripped namespace before processing</xsl:text>
229         </xsl:with-param>
230       </xsl:call-template>
231       <xsl:variable name="nons">
232         <xsl:apply-templates mode="stripNS"/>
233       </xsl:variable>
234       <xsl:call-template name="log.message">
235         <xsl:with-param name="level">Note</xsl:with-param>
236         <xsl:with-param name="source" select="$doc.title"/>
237         <xsl:with-param name="context-desc">
238           <xsl:text>namesp. cut</xsl:text>
239         </xsl:with-param>
240         <xsl:with-param name="message">
241           <xsl:text>processing stripped document</xsl:text>
242         </xsl:with-param>
243       </xsl:call-template>
244       <xsl:apply-templates select="exsl:node-set($nons)"/>
245     </xsl:when>
246     <!-- Can't process unless namespace removed -->
247     <xsl:when test="*/self::ng:* or */self::db:*">
248       <xsl:message terminate="yes">
249         <xsl:text>Unable to strip the namespace from DB5 document,</xsl:text>
250         <xsl:text> cannot proceed.</xsl:text>
251       </xsl:message>
252     </xsl:when>
253     <xsl:otherwise>
254       <xsl:choose>
255         <xsl:when test="$rootid != ''">
256           <xsl:choose>
257             <xsl:when test="count(key('id',$rootid)) = 0">
258               <xsl:message terminate="yes">
259                 <xsl:text>ID '</xsl:text>
260                 <xsl:value-of select="$rootid"/>
261                 <xsl:text>' not found in document.</xsl:text>
262               </xsl:message>
263             </xsl:when>
264             <xsl:otherwise>
265               <xsl:if test="$collect.xref.targets = 'yes' or                             $collect.xref.targets = 'only'">
266                 <xsl:apply-templates select="key('id', $rootid)" mode="collect.targets"/>
267               </xsl:if>
268               <xsl:if test="$collect.xref.targets != 'only'">
269                 <xsl:apply-templates select="key('id',$rootid)" mode="process.root"/>
270                 <xsl:if test="$tex.math.in.alt != ''">
271                   <xsl:apply-templates select="key('id',$rootid)" mode="collect.tex.math"/>
272                 </xsl:if>
273                 <xsl:if test="$generate.manifest != 0">
274                   <xsl:call-template name="generate.manifest">
275                     <xsl:with-param name="node" select="key('id',$rootid)"/>
276                   </xsl:call-template>
277                 </xsl:if>
278               </xsl:if>
279             </xsl:otherwise>
280           </xsl:choose>
281         </xsl:when>
282         <xsl:otherwise>
283           <xsl:if test="$collect.xref.targets = 'yes' or                         $collect.xref.targets = 'only'">
284             <xsl:apply-templates select="/" mode="collect.targets"/>
285           </xsl:if>
286           <xsl:if test="$collect.xref.targets != 'only'">
287             <xsl:apply-templates select="/" mode="process.root"/>
288             <xsl:if test="$tex.math.in.alt != ''">
289               <xsl:apply-templates select="/" mode="collect.tex.math"/>
290             </xsl:if>
291             <xsl:if test="$generate.manifest != 0">
292               <xsl:call-template name="generate.manifest">
293                 <xsl:with-param name="node" select="/"/>
294               </xsl:call-template>
295             </xsl:if>
296           </xsl:if>
297         </xsl:otherwise>
298       </xsl:choose>
299     </xsl:otherwise>
300   </xsl:choose>
301 </xsl:template>
302
303 <xsl:template match="*" mode="process.root">
304   <xsl:apply-templates select="."/>
305 </xsl:template>
306
307 <xsl:template name="make.lots">
308   <xsl:param name="toc.params" select="''"/>
309   <xsl:param name="toc"/>
310
311   <xsl:variable name="lots">
312     <xsl:if test="contains($toc.params, 'toc')">
313       <xsl:copy-of select="$toc"/>
314     </xsl:if>
315
316     <xsl:if test="contains($toc.params, 'figure')">
317       <xsl:choose>
318         <xsl:when test="$chunk.separate.lots != '0'">
319           <xsl:call-template name="make.lot.chunk">
320             <xsl:with-param name="type" select="'figure'"/>
321             <xsl:with-param name="lot">
322               <xsl:call-template name="list.of.titles">
323                 <xsl:with-param name="titles" select="'figure'"/>
324                 <xsl:with-param name="nodes" select=".//figure"/>
325               </xsl:call-template>
326             </xsl:with-param>
327           </xsl:call-template>
328         </xsl:when>
329         <xsl:otherwise>
330           <xsl:call-template name="list.of.titles">
331             <xsl:with-param name="titles" select="'figure'"/>
332             <xsl:with-param name="nodes" select=".//figure"/>
333           </xsl:call-template>
334         </xsl:otherwise>
335       </xsl:choose>
336     </xsl:if>
337
338     <xsl:if test="contains($toc.params, 'table')">
339       <xsl:choose>
340         <xsl:when test="$chunk.separate.lots != '0'">
341           <xsl:call-template name="make.lot.chunk">
342             <xsl:with-param name="type" select="'table'"/>
343             <xsl:with-param name="lot">
344               <xsl:call-template name="list.of.titles">
345                 <xsl:with-param name="titles" select="'table'"/>
346                 <xsl:with-param name="nodes" select=".//table"/>
347               </xsl:call-template>
348             </xsl:with-param>
349           </xsl:call-template>
350         </xsl:when>
351         <xsl:otherwise>
352           <xsl:call-template name="list.of.titles">
353             <xsl:with-param name="titles" select="'table'"/>
354             <xsl:with-param name="nodes" select=".//table"/>
355           </xsl:call-template>
356         </xsl:otherwise>
357       </xsl:choose>
358     </xsl:if>
359
360     <xsl:if test="contains($toc.params, 'example')">
361       <xsl:choose>
362         <xsl:when test="$chunk.separate.lots != '0'">
363           <xsl:call-template name="make.lot.chunk">
364             <xsl:with-param name="type" select="'example'"/>
365             <xsl:with-param name="lot">
366               <xsl:call-template name="list.of.titles">
367                 <xsl:with-param name="titles" select="'example'"/>
368                 <xsl:with-param name="nodes" select=".//example"/>
369               </xsl:call-template>
370             </xsl:with-param>
371           </xsl:call-template>
372         </xsl:when>
373         <xsl:otherwise>
374           <xsl:call-template name="list.of.titles">
375             <xsl:with-param name="titles" select="'example'"/>
376             <xsl:with-param name="nodes" select=".//example"/>
377           </xsl:call-template>
378         </xsl:otherwise>
379       </xsl:choose>
380     </xsl:if>
381
382     <xsl:if test="contains($toc.params, 'equation')">
383       <xsl:choose>
384         <xsl:when test="$chunk.separate.lots != '0'">
385           <xsl:call-template name="make.lot.chunk">
386             <xsl:with-param name="type" select="'equation'"/>
387             <xsl:with-param name="lot">
388               <xsl:call-template name="list.of.titles">
389                 <xsl:with-param name="titles" select="'equation'"/>
390                 <xsl:with-param name="nodes" select=".//equation"/>
391               </xsl:call-template>
392             </xsl:with-param>
393           </xsl:call-template>
394         </xsl:when>
395         <xsl:otherwise>
396           <xsl:call-template name="list.of.titles">
397             <xsl:with-param name="titles" select="'equation'"/>
398             <xsl:with-param name="nodes" select=".//equation"/>
399           </xsl:call-template>
400         </xsl:otherwise>
401       </xsl:choose>
402     </xsl:if>
403
404     <xsl:if test="contains($toc.params, 'procedure')">
405       <xsl:choose>
406         <xsl:when test="$chunk.separate.lots != '0'">
407           <xsl:call-template name="make.lot.chunk">
408             <xsl:with-param name="type" select="'procedure'"/>
409             <xsl:with-param name="lot">
410               <xsl:call-template name="list.of.titles">
411                 <xsl:with-param name="titles" select="'procedure'"/>
412                 <xsl:with-param name="nodes" select=".//procedure[title]"/>
413               </xsl:call-template>
414             </xsl:with-param>
415           </xsl:call-template>
416         </xsl:when>
417         <xsl:otherwise>
418           <xsl:call-template name="list.of.titles">
419             <xsl:with-param name="titles" select="'procedure'"/>
420             <xsl:with-param name="nodes" select=".//procedure[title]"/>
421           </xsl:call-template>
422         </xsl:otherwise>
423       </xsl:choose>
424     </xsl:if>
425   </xsl:variable>
426
427   <xsl:if test="string($lots) != ''">
428     <xsl:choose>
429       <xsl:when test="$chunk.tocs.and.lots != 0 and not(parent::*)">
430         <xsl:call-template name="write.chunk">
431           <xsl:with-param name="filename">
432             <xsl:call-template name="make-relative-filename">
433               <xsl:with-param name="base.dir" select="$base.dir"/>
434               <xsl:with-param name="base.name">
435                 <xsl:call-template name="dbhtml-dir"/>
436                 <xsl:apply-templates select="." mode="recursive-chunk-filename">
437                   <xsl:with-param name="recursive" select="true()"/>
438                 </xsl:apply-templates>
439                 <xsl:text>-toc</xsl:text>
440                 <xsl:value-of select="$html.ext"/>
441               </xsl:with-param>
442             </xsl:call-template>
443           </xsl:with-param>
444           <xsl:with-param name="content">
445             <xsl:call-template name="chunk-element-content">
446               <xsl:with-param name="prev" select="/foo"/>
447               <xsl:with-param name="next" select="/foo"/>
448               <xsl:with-param name="nav.context" select="'toc'"/>
449               <xsl:with-param name="content">
450                 <h1>
451                   <xsl:apply-templates select="." mode="object.title.markup"/>
452                 </h1>
453                 <xsl:copy-of select="$lots"/>
454               </xsl:with-param>
455             </xsl:call-template>
456           </xsl:with-param>
457           <xsl:with-param name="quiet" select="$chunk.quietly"/>
458         </xsl:call-template>
459       </xsl:when>
460       <xsl:otherwise>
461         <xsl:copy-of select="$lots"/>
462       </xsl:otherwise>
463     </xsl:choose>
464   </xsl:if>
465 </xsl:template>
466
467 <xsl:template name="make.lot.chunk">
468   <xsl:param name="type" select="''"/>
469   <xsl:param name="lot"/>
470
471   <xsl:if test="string($lot) != ''">
472     <xsl:variable name="filename">
473       <xsl:call-template name="make-relative-filename">
474         <xsl:with-param name="base.dir" select="$base.dir"/>
475         <xsl:with-param name="base.name">
476           <xsl:call-template name="dbhtml-dir"/>
477           <xsl:value-of select="$type"/>
478           <xsl:text>-toc</xsl:text>
479           <xsl:value-of select="$html.ext"/>
480         </xsl:with-param>
481       </xsl:call-template>
482     </xsl:variable>
483
484     <xsl:variable name="href">
485       <xsl:call-template name="make-relative-filename">
486         <xsl:with-param name="base.name">
487           <xsl:call-template name="dbhtml-dir"/>
488           <xsl:value-of select="$type"/>
489           <xsl:text>-toc</xsl:text>
490           <xsl:value-of select="$html.ext"/>
491         </xsl:with-param>
492       </xsl:call-template>
493     </xsl:variable>
494
495     <xsl:call-template name="write.chunk">
496       <xsl:with-param name="filename" select="$filename"/>
497       <xsl:with-param name="content">
498         <xsl:call-template name="chunk-element-content">
499           <xsl:with-param name="prev" select="/foo"/>
500           <xsl:with-param name="next" select="/foo"/>
501           <xsl:with-param name="nav.context" select="'toc'"/>
502           <xsl:with-param name="content">
503             <xsl:copy-of select="$lot"/>
504           </xsl:with-param>
505         </xsl:call-template>
506       </xsl:with-param>
507       <xsl:with-param name="quiet" select="$chunk.quietly"/>
508     </xsl:call-template>
509     <!-- And output a link to this file -->
510     <div>
511       <xsl:attribute name="class">
512         <xsl:text>ListofTitles</xsl:text>
513       </xsl:attribute>
514       <a href="{$href}">
515         <xsl:call-template name="gentext">
516           <xsl:with-param name="key">
517             <xsl:choose>
518               <xsl:when test="$type='table'">ListofTables</xsl:when>
519               <xsl:when test="$type='figure'">ListofFigures</xsl:when>
520               <xsl:when test="$type='equation'">ListofEquations</xsl:when>
521               <xsl:when test="$type='example'">ListofExamples</xsl:when>
522               <xsl:when test="$type='procedure'">ListofProcedures</xsl:when>
523               <xsl:otherwise>ListofUnknown</xsl:otherwise>
524             </xsl:choose>
525           </xsl:with-param>
526         </xsl:call-template>
527       </a>
528     </div>
529   </xsl:if>
530 </xsl:template>
531
532 </xsl:stylesheet>