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