Whamcloud - gitweb
LUDOC-120 presentation: build bits for webhelp.
[doc/manual.git] / webhelp / 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="http://www.w3.org/1999/xhtml" version="1.0" exclude-result-prefixes="doc">
5
6 <!-- ********************************************************************
7      $Id: chunktoc.xsl 9866 2014-01-29 02:55:52Z 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-no-doctype.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="$chunk.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="topic">
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                      |book/index                      |article/index">
198   <!-- some implementations use completely empty index tags to indicate -->
199   <!-- where an automatically generated index should be inserted. so -->
200   <!-- if the index is completely empty, skip it. -->
201   <xsl:if test="count(*)&gt;0 or $generate.index != '0'">
202     <xsl:call-template name="process-chunk"/>
203   </xsl:if>
204 </xsl:template>
205
206 <!-- ==================================================================== -->
207
208 <xsl:template match="/">
209   <!-- * Get a title for current doc so that we let the user -->
210   <!-- * know what document we are processing at this point. -->
211   <xsl:variable name="doc.title">
212     <xsl:call-template name="get.doc.title"/>
213   </xsl:variable>
214   <xsl:choose>
215     <xsl:when test="$chunk.toc = ''">
216       <xsl:message terminate="yes">
217         <xsl:text>The chunk.toc file is not set.</xsl:text>
218       </xsl:message>
219     </xsl:when>
220     <xsl:when test="$exsl.node.set.available != 0 and                    namespace-uri(/*) = 'http://docbook.org/ns/docbook'">
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:apply-templates select="exsl:node-set($no.namespace)"/>
232     </xsl:when>
233     <!-- Can't process unless namespace is correct -->
234     <xsl:when test="namespace-uri(/*) = 'http://docbook.org/ns/docbook'">
235       <xsl:message terminate="yes">
236         <xsl:text>Unable to strip the namespace from DB5 document,</xsl:text>
237         <xsl:text> cannot proceed.</xsl:text>
238       </xsl:message>
239     </xsl:when>
240     <xsl:otherwise>
241       <xsl:choose>
242         <xsl:when test="$rootid != ''">
243           <xsl:choose>
244             <xsl:when test="count(key('id',$rootid)) = 0">
245               <xsl:message terminate="yes">
246                 <xsl:text>ID '</xsl:text>
247                 <xsl:value-of select="$rootid"/>
248                 <xsl:text>' not found in document.</xsl:text>
249               </xsl:message>
250             </xsl:when>
251             <xsl:otherwise>
252               <xsl:if test="$collect.xref.targets = 'yes' or                             $collect.xref.targets = 'only'">
253                 <xsl:apply-templates select="key('id', $rootid)" mode="collect.targets"/>
254               </xsl:if>
255               <xsl:if test="$collect.xref.targets != 'only'">
256                 <xsl:apply-templates select="key('id',$rootid)" mode="process.root"/>
257                 <xsl:if test="$tex.math.in.alt != ''">
258                   <xsl:apply-templates select="key('id',$rootid)" 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="key('id',$rootid)"/>
263                   </xsl:call-template>
264                 </xsl:if>
265               </xsl:if>
266             </xsl:otherwise>
267           </xsl:choose>
268         </xsl:when>
269         <xsl:otherwise>
270           <xsl:if test="$collect.xref.targets = 'yes' or                         $collect.xref.targets = 'only'">
271             <xsl:apply-templates select="/" mode="collect.targets"/>
272           </xsl:if>
273           <xsl:if test="$collect.xref.targets != 'only'">
274             <xsl:apply-templates select="/" mode="process.root"/>
275             <xsl:if test="$tex.math.in.alt != ''">
276               <xsl:apply-templates select="/" mode="collect.tex.math"/>
277             </xsl:if>
278             <xsl:if test="$generate.manifest != 0">
279               <xsl:call-template name="generate.manifest">
280                 <xsl:with-param name="node" select="/"/>
281               </xsl:call-template>
282             </xsl:if>
283           </xsl:if>
284         </xsl:otherwise>
285       </xsl:choose>
286     </xsl:otherwise>
287   </xsl:choose>
288 </xsl:template>
289
290 <xsl:template match="*" mode="process.root">
291   <xsl:apply-templates select="."/>
292   <xsl:call-template name="generate.css"/>
293 </xsl:template>
294
295 <xsl:template name="make.lots">
296   <xsl:param name="toc.params" select="''"/>
297   <xsl:param name="toc"/>
298
299   <xsl:variable name="lots">
300     <xsl:if test="contains($toc.params, 'toc')">
301       <xsl:copy-of select="$toc"/>
302     </xsl:if>
303
304     <xsl:if test="contains($toc.params, 'figure')">
305       <xsl:choose>
306         <xsl:when test="$chunk.separate.lots != '0'">
307           <xsl:call-template name="make.lot.chunk">
308             <xsl:with-param name="type" select="'figure'"/>
309             <xsl:with-param name="lot">
310               <xsl:call-template name="list.of.titles">
311                 <xsl:with-param name="titles" select="'figure'"/>
312                 <xsl:with-param name="nodes" select=".//figure"/>
313               </xsl:call-template>
314             </xsl:with-param>
315           </xsl:call-template>
316         </xsl:when>
317         <xsl:otherwise>
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:otherwise>
323       </xsl:choose>
324     </xsl:if>
325
326     <xsl:if test="contains($toc.params, 'table')">
327       <xsl:choose>
328         <xsl:when test="$chunk.separate.lots != '0'">
329           <xsl:call-template name="make.lot.chunk">
330             <xsl:with-param name="type" select="'table'"/>
331             <xsl:with-param name="lot">
332               <xsl:call-template name="list.of.titles">
333                 <xsl:with-param name="titles" select="'table'"/>
334                 <xsl:with-param name="nodes" select=".//table"/>
335               </xsl:call-template>
336             </xsl:with-param>
337           </xsl:call-template>
338         </xsl:when>
339         <xsl:otherwise>
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:otherwise>
345       </xsl:choose>
346     </xsl:if>
347
348     <xsl:if test="contains($toc.params, 'example')">
349       <xsl:choose>
350         <xsl:when test="$chunk.separate.lots != '0'">
351           <xsl:call-template name="make.lot.chunk">
352             <xsl:with-param name="type" select="'example'"/>
353             <xsl:with-param name="lot">
354               <xsl:call-template name="list.of.titles">
355                 <xsl:with-param name="titles" select="'example'"/>
356                 <xsl:with-param name="nodes" select=".//example"/>
357               </xsl:call-template>
358             </xsl:with-param>
359           </xsl:call-template>
360         </xsl:when>
361         <xsl:otherwise>
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:otherwise>
367       </xsl:choose>
368     </xsl:if>
369
370     <xsl:if test="contains($toc.params, 'equation')">
371       <xsl:choose>
372         <xsl:when test="$chunk.separate.lots != '0'">
373           <xsl:call-template name="make.lot.chunk">
374             <xsl:with-param name="type" select="'equation'"/>
375             <xsl:with-param name="lot">
376               <xsl:call-template name="list.of.titles">
377                 <xsl:with-param name="titles" select="'equation'"/>
378                 <xsl:with-param name="nodes" select=".//equation"/>
379               </xsl:call-template>
380             </xsl:with-param>
381           </xsl:call-template>
382         </xsl:when>
383         <xsl:otherwise>
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:otherwise>
389       </xsl:choose>
390     </xsl:if>
391
392     <xsl:if test="contains($toc.params, 'procedure')">
393       <xsl:choose>
394         <xsl:when test="$chunk.separate.lots != '0'">
395           <xsl:call-template name="make.lot.chunk">
396             <xsl:with-param name="type" select="'procedure'"/>
397             <xsl:with-param name="lot">
398               <xsl:call-template name="list.of.titles">
399                 <xsl:with-param name="titles" select="'procedure'"/>
400                 <xsl:with-param name="nodes" select=".//procedure[title]"/>
401               </xsl:call-template>
402             </xsl:with-param>
403           </xsl:call-template>
404         </xsl:when>
405         <xsl:otherwise>
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:otherwise>
411       </xsl:choose>
412     </xsl:if>
413   </xsl:variable>
414
415   <xsl:if test="string($lots) != ''">
416     <xsl:choose>
417       <xsl:when test="$chunk.tocs.and.lots != 0 and not(parent::*)">
418         <xsl:call-template name="write.chunk">
419           <xsl:with-param name="filename">
420             <xsl:call-template name="make-relative-filename">
421               <xsl:with-param name="base.dir" select="$chunk.base.dir"/>
422               <xsl:with-param name="base.name">
423                 <xsl:call-template name="dbhtml-dir"/>
424                 <xsl:apply-templates select="." mode="recursive-chunk-filename">
425                   <xsl:with-param name="recursive" select="true()"/>
426                 </xsl:apply-templates>
427                 <xsl:text>-toc</xsl:text>
428                 <xsl:value-of select="$html.ext"/>
429               </xsl:with-param>
430             </xsl:call-template>
431           </xsl:with-param>
432           <xsl:with-param name="content">
433             <xsl:call-template name="chunk-element-content">
434               <xsl:with-param name="prev" select="/foo"/>
435               <xsl:with-param name="next" select="/foo"/>
436               <xsl:with-param name="nav.context" select="'toc'"/>
437               <xsl:with-param name="content">
438                 <h1>
439                   <xsl:apply-templates select="." mode="object.title.markup"/>
440                 </h1>
441                 <xsl:copy-of select="$lots"/>
442               </xsl:with-param>
443             </xsl:call-template>
444           </xsl:with-param>
445           <xsl:with-param name="quiet" select="$chunk.quietly"/>
446         </xsl:call-template>
447       </xsl:when>
448       <xsl:otherwise>
449         <xsl:copy-of select="$lots"/>
450       </xsl:otherwise>
451     </xsl:choose>
452   </xsl:if>
453 </xsl:template>
454
455 <xsl:template name="make.lot.chunk">
456   <xsl:param name="type" select="''"/>
457   <xsl:param name="lot"/>
458
459   <xsl:if test="string($lot) != ''">
460     <xsl:variable name="filename">
461       <xsl:call-template name="make-relative-filename">
462         <xsl:with-param name="base.dir" select="$chunk.base.dir"/>
463         <xsl:with-param name="base.name">
464           <xsl:call-template name="dbhtml-dir"/>
465           <xsl:value-of select="$type"/>
466           <xsl:text>-toc</xsl:text>
467           <xsl:value-of select="$html.ext"/>
468         </xsl:with-param>
469       </xsl:call-template>
470     </xsl:variable>
471
472     <xsl:variable name="href">
473       <xsl:call-template name="make-relative-filename">
474         <xsl:with-param name="base.dir" select="''"/>
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:call-template name="write.chunk">
485       <xsl:with-param name="filename" select="$filename"/>
486       <xsl:with-param name="content">
487         <xsl:call-template name="chunk-element-content">
488           <xsl:with-param name="prev" select="/foo"/>
489           <xsl:with-param name="next" select="/foo"/>
490           <xsl:with-param name="nav.context" select="'toc'"/>
491           <xsl:with-param name="content">
492             <xsl:copy-of select="$lot"/>
493           </xsl:with-param>
494         </xsl:call-template>
495       </xsl:with-param>
496       <xsl:with-param name="quiet" select="$chunk.quietly"/>
497     </xsl:call-template>
498     <!-- And output a link to this file -->
499     <div>
500       <xsl:attribute name="class">
501         <xsl:text>ListofTitles</xsl:text>
502       </xsl:attribute>
503       <a href="{$href}">
504         <xsl:call-template name="gentext">
505           <xsl:with-param name="key">
506             <xsl:choose>
507               <xsl:when test="$type='table'">ListofTables</xsl:when>
508               <xsl:when test="$type='figure'">ListofFigures</xsl:when>
509               <xsl:when test="$type='equation'">ListofEquations</xsl:when>
510               <xsl:when test="$type='example'">ListofExamples</xsl:when>
511               <xsl:when test="$type='procedure'">ListofProcedures</xsl:when>
512               <xsl:otherwise>ListofUnknown</xsl:otherwise>
513             </xsl:choose>
514           </xsl:with-param>
515         </xsl:call-template>
516       </a>
517     </div>
518   </xsl:if>
519 </xsl:template>
520
521 </xsl:stylesheet>