Rocco Rutte:
[apps/madmutt.git] / doc / xslt / xhtml / autotoc.xsl
1 <?xml version="1.0" encoding="US-ASCII"?>
2 <!--This file was created automatically by html2xhtml-->
3 <!--from the HTML stylesheets. Do not edit this file.-->
4 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
5
6 <!-- ********************************************************************
7      $Id$
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 <xsl:variable name="toc.listitem.type">
17   <xsl:choose>
18     <xsl:when test="$toc.list.type = 'dl'">dt</xsl:when>
19     <xsl:otherwise>li</xsl:otherwise>
20   </xsl:choose>
21 </xsl:variable>
22
23 <!-- this is just hack because dl and ul aren't completely isomorphic -->
24 <xsl:variable name="toc.dd.type">
25   <xsl:choose>
26     <xsl:when test="$toc.list.type = 'dl'">dd</xsl:when>
27     <xsl:otherwise/>
28   </xsl:choose>
29 </xsl:variable>
30
31 <xsl:template name="make.toc">
32   <xsl:param name="toc-context" select="."/>
33   <xsl:param name="toc.title.p" select="true()"/>
34   <xsl:param name="nodes" select="/NOT-AN-ELEMENT"/>
35
36   <xsl:variable name="toc.title">
37     <xsl:if test="$toc.title.p">
38       <p>
39         <b>
40           <xsl:call-template name="gentext">
41             <xsl:with-param name="key">TableofContents</xsl:with-param>
42           </xsl:call-template>
43         </b>
44       </p>
45     </xsl:if>
46   </xsl:variable>
47
48   <xsl:choose>
49     <xsl:when test="$manual.toc != ''">
50       <xsl:variable name="id">
51         <xsl:call-template name="object.id"/>
52       </xsl:variable>
53       <xsl:variable name="toc" select="document($manual.toc, .)"/>
54       <xsl:variable name="tocentry" select="$toc//tocentry[@linkend=$id]"/>
55       <xsl:if test="$tocentry and $tocentry/*">
56         <div class="toc">
57           <xsl:copy-of select="$toc.title"/>
58           <xsl:element name="{$toc.list.type}" namespace="http://www.w3.org/1999/xhtml">
59             <xsl:call-template name="manual-toc">
60               <xsl:with-param name="tocentry" select="$tocentry/*[1]"/>
61             </xsl:call-template>
62           </xsl:element>
63         </div>
64       </xsl:if>
65     </xsl:when>
66     <xsl:otherwise>
67       <xsl:if test="$nodes">
68         <div class="toc">
69           <xsl:copy-of select="$toc.title"/>
70           <xsl:element name="{$toc.list.type}" namespace="http://www.w3.org/1999/xhtml">
71             <xsl:apply-templates select="$nodes" mode="toc">
72               <xsl:with-param name="toc-context" select="$toc-context"/>
73             </xsl:apply-templates>
74           </xsl:element>
75         </div>
76       </xsl:if>
77     </xsl:otherwise>
78   </xsl:choose>
79 </xsl:template>
80
81 <xsl:template name="make.lots">
82   <xsl:param name="toc.params" select="''"/>
83   <xsl:param name="toc"/>
84
85   <xsl:if test="contains($toc.params, 'toc')">
86     <xsl:copy-of select="$toc"/>
87   </xsl:if>
88
89   <xsl:if test="contains($toc.params, 'figure')">
90     <xsl:call-template name="list.of.titles">
91       <xsl:with-param name="titles" select="'figure'"/>
92       <xsl:with-param name="nodes" select=".//figure"/>
93     </xsl:call-template>
94   </xsl:if>
95
96   <xsl:if test="contains($toc.params, 'table')">
97     <xsl:call-template name="list.of.titles">
98       <xsl:with-param name="titles" select="'table'"/>
99       <xsl:with-param name="nodes" select=".//table"/>
100     </xsl:call-template>
101   </xsl:if>
102
103   <xsl:if test="contains($toc.params, 'example')">
104     <xsl:call-template name="list.of.titles">
105       <xsl:with-param name="titles" select="'example'"/>
106       <xsl:with-param name="nodes" select=".//example"/>
107     </xsl:call-template>
108   </xsl:if>
109
110   <xsl:if test="contains($toc.params, 'equation')">
111     <xsl:call-template name="list.of.titles">
112       <xsl:with-param name="titles" select="'equation'"/>
113       <xsl:with-param name="nodes" select=".//equation[title]"/>
114     </xsl:call-template>
115   </xsl:if>
116
117   <xsl:if test="contains($toc.params, 'procedure')">
118     <xsl:call-template name="list.of.titles">
119       <xsl:with-param name="titles" select="'procedure'"/>
120       <xsl:with-param name="nodes" select=".//procedure[title]"/>
121     </xsl:call-template>
122   </xsl:if>
123 </xsl:template>
124
125 <!-- ====================================================================== -->
126
127 <xsl:template name="set.toc">
128   <xsl:param name="toc-context" select="."/>
129
130   <xsl:call-template name="make.toc">
131     <xsl:with-param name="toc-context" select="$toc-context"/>
132     <xsl:with-param name="nodes" select="book|setindex"/>
133   </xsl:call-template>
134 </xsl:template>
135
136 <xsl:template name="division.toc">
137   <xsl:param name="toc-context" select="."/>
138
139   <xsl:call-template name="make.toc">
140     <xsl:with-param name="toc-context" select="$toc-context"/>
141     <xsl:with-param name="nodes" select="part|reference                                          |preface|chapter|appendix                                          |article                                          |bibliography|glossary|index                                          |refentry                                          |bridgehead[$bridgehead.in.toc != 0]"/>
142
143   </xsl:call-template>
144 </xsl:template>
145
146 <xsl:template name="component.toc">
147   <xsl:param name="toc-context" select="."/>
148   <xsl:param name="toc.title.p" select="true()"/>
149
150   <xsl:call-template name="make.toc">
151     <xsl:with-param name="toc-context" select="$toc-context"/>
152     <xsl:with-param name="toc.title.p" select="$toc.title.p"/>
153     <xsl:with-param name="nodes" select="section|sect1                                          |simplesect[$simplesect.in.toc != 0]                                          |refentry                                          |article|bibliography|glossary                                          |appendix|index                                          |bridgehead[not(@renderas)                                                      and $bridgehead.in.toc != 0]                                          |.//bridgehead[@renderas='sect1'                                                         and $bridgehead.in.toc != 0]"/>
154   </xsl:call-template>
155 </xsl:template>
156
157 <xsl:template name="component.toc.separator">
158   <!-- Customize to output something between
159        component.toc and first output -->
160 </xsl:template>
161
162 <xsl:template name="section.toc">
163   <xsl:param name="toc-context" select="."/>
164   <xsl:param name="toc.title.p" select="true()"/>
165
166   <xsl:call-template name="make.toc">
167     <xsl:with-param name="toc-context" select="$toc-context"/>
168     <xsl:with-param name="toc.title.p" select="$toc.title.p"/>
169     <xsl:with-param name="nodes" select="section|sect1|sect2|sect3|sect4|sect5|refentry                            |bridgehead[$bridgehead.in.toc != 0]"/>
170
171   </xsl:call-template>
172 </xsl:template>
173
174 <xsl:template name="section.toc.separator">
175   <!-- Customize to output something between
176        section.toc and first output -->
177 </xsl:template>
178 <!-- ==================================================================== -->
179
180 <xsl:template name="subtoc">
181   <xsl:param name="toc-context" select="."/>
182   <xsl:param name="nodes" select="NOT-AN-ELEMENT"/>
183
184   <xsl:variable name="subtoc">
185     <xsl:element name="{$toc.list.type}" namespace="http://www.w3.org/1999/xhtml">
186       <xsl:apply-templates mode="toc" select="$nodes">
187         <xsl:with-param name="toc-context" select="$toc-context"/>
188       </xsl:apply-templates>
189     </xsl:element>
190   </xsl:variable>
191
192   <xsl:variable name="depth">
193     <xsl:choose>
194       <xsl:when test="local-name(.) = 'section'">
195         <xsl:value-of select="count(ancestor::section) + 1"/>
196       </xsl:when>
197       <xsl:when test="local-name(.) = 'sect1'">1</xsl:when>
198       <xsl:when test="local-name(.) = 'sect2'">2</xsl:when>
199       <xsl:when test="local-name(.) = 'sect3'">3</xsl:when>
200       <xsl:when test="local-name(.) = 'sect4'">4</xsl:when>
201       <xsl:when test="local-name(.) = 'sect5'">5</xsl:when>
202       <xsl:when test="local-name(.) = 'refsect1'">1</xsl:when>
203       <xsl:when test="local-name(.) = 'refsect2'">2</xsl:when>
204       <xsl:when test="local-name(.) = 'refsect3'">3</xsl:when>
205       <xsl:when test="local-name(.) = 'simplesect'">
206         <!-- sigh... -->
207         <xsl:choose>
208           <xsl:when test="local-name(..) = 'section'">
209             <xsl:value-of select="count(ancestor::section)"/>
210           </xsl:when>
211           <xsl:when test="local-name(..) = 'sect1'">2</xsl:when>
212           <xsl:when test="local-name(..) = 'sect2'">3</xsl:when>
213           <xsl:when test="local-name(..) = 'sect3'">4</xsl:when>
214           <xsl:when test="local-name(..) = 'sect4'">5</xsl:when>
215           <xsl:when test="local-name(..) = 'sect5'">6</xsl:when>
216           <xsl:when test="local-name(..) = 'refsect1'">2</xsl:when>
217           <xsl:when test="local-name(..) = 'refsect2'">3</xsl:when>
218           <xsl:when test="local-name(..) = 'refsect3'">4</xsl:when>
219           <xsl:otherwise>1</xsl:otherwise>
220         </xsl:choose>
221       </xsl:when>
222       <xsl:otherwise>0</xsl:otherwise>
223     </xsl:choose>
224   </xsl:variable>
225
226   <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
227
228   <xsl:variable name="subtoc.list">
229     <xsl:choose>
230       <xsl:when test="$toc.dd.type = ''">
231         <xsl:copy-of select="$subtoc"/>
232       </xsl:when>
233       <xsl:otherwise>
234         <xsl:element name="{$toc.dd.type}" namespace="http://www.w3.org/1999/xhtml">
235           <xsl:copy-of select="$subtoc"/>
236         </xsl:element>
237       </xsl:otherwise>
238     </xsl:choose>
239   </xsl:variable>
240
241   <xsl:element name="{$toc.listitem.type}" namespace="http://www.w3.org/1999/xhtml">
242     <xsl:call-template name="toc.line">
243       <xsl:with-param name="toc-context" select="$toc-context"/>
244     </xsl:call-template>
245     <xsl:if test="$toc.listitem.type = 'li'                   and $toc.section.depth &gt; $depth and count($nodes)&gt;0                   and $toc.max.depth &gt; $depth.from.context">
246       <xsl:copy-of select="$subtoc.list"/>
247     </xsl:if>
248   </xsl:element>
249   <xsl:if test="$toc.listitem.type != 'li'                 and $toc.section.depth &gt; $depth and count($nodes)&gt;0                 and $toc.max.depth &gt; $depth.from.context">
250     <xsl:copy-of select="$subtoc.list"/>
251   </xsl:if>
252 </xsl:template>
253
254 <xsl:template name="toc.line">
255   <xsl:param name="toc-context" select="."/>
256   <xsl:param name="depth" select="1"/>
257   <xsl:param name="depth.from.context" select="8"/>
258
259  <span>
260   <xsl:attribute name="class"><xsl:value-of select="local-name(.)"/></xsl:attribute>
261   <a>
262     <xsl:attribute name="href">
263       <xsl:call-template name="href.target">
264         <xsl:with-param name="context" select="$toc-context"/>
265       </xsl:call-template>
266     </xsl:attribute>
267     
268     <xsl:variable name="label">
269       <xsl:apply-templates select="." mode="label.markup"/>
270     </xsl:variable>
271     <xsl:copy-of select="$label"/>
272     <xsl:if test="$label != ''">
273       <xsl:value-of select="$autotoc.label.separator"/>
274     </xsl:if>
275
276     <xsl:apply-templates select="." mode="titleabbrev.markup"/>
277   </a>
278   </span>
279 </xsl:template>
280
281 <xsl:template match="book" mode="toc">
282   <xsl:param name="toc-context" select="."/>
283
284   <xsl:call-template name="subtoc">
285     <xsl:with-param name="toc-context" select="$toc-context"/>
286     <xsl:with-param name="nodes" select="part|reference                                          |preface|chapter|appendix                                          |article                                          |bibliography|glossary|index                                          |refentry                                          |bridgehead[$bridgehead.in.toc != 0]"/>
287   </xsl:call-template>
288 </xsl:template>
289
290 <xsl:template match="setindex" mode="toc">
291   <xsl:param name="toc-context" select="."/>
292
293   <!-- If the setindex tag is not empty, it should be it in the TOC -->
294   <xsl:if test="* or $generate.index != 0">
295     <xsl:call-template name="subtoc">
296       <xsl:with-param name="toc-context" select="$toc-context"/>
297     </xsl:call-template>
298   </xsl:if>
299 </xsl:template>
300
301 <xsl:template match="part|reference" mode="toc">
302   <xsl:param name="toc-context" select="."/>
303
304   <xsl:call-template name="subtoc">
305     <xsl:with-param name="toc-context" select="$toc-context"/>
306     <xsl:with-param name="nodes" select="appendix|chapter|article                                          |index|glossary|bibliography                                          |preface|reference|refentry                                          |bridgehead[$bridgehead.in.toc != 0]"/>
307   </xsl:call-template>
308 </xsl:template>
309
310 <xsl:template match="preface|chapter|appendix|article" mode="toc">
311   <xsl:param name="toc-context" select="."/>
312
313   <xsl:call-template name="subtoc">
314     <xsl:with-param name="toc-context" select="$toc-context"/>
315     <xsl:with-param name="nodes" select="section|sect1                                          |simplesect[$simplesect.in.toc != 0]                                          |refentry                                          |glossary|bibliography|index                                          |bridgehead[$bridgehead.in.toc != 0]"/>
316   </xsl:call-template>
317 </xsl:template>
318
319 <xsl:template match="sect1" mode="toc">
320   <xsl:param name="toc-context" select="."/>
321   <xsl:call-template name="subtoc">
322     <xsl:with-param name="toc-context" select="$toc-context"/>
323     <xsl:with-param name="nodes" select="sect2                                          |bridgehead[$bridgehead.in.toc != 0]"/>
324   </xsl:call-template>
325 </xsl:template>
326
327 <xsl:template match="sect2" mode="toc">
328   <xsl:param name="toc-context" select="."/>
329
330   <xsl:call-template name="subtoc">
331     <xsl:with-param name="toc-context" select="$toc-context"/>
332     <xsl:with-param name="nodes" select="sect3                                          |bridgehead[$bridgehead.in.toc != 0]"/>
333   </xsl:call-template>
334 </xsl:template>
335
336 <xsl:template match="sect3" mode="toc">
337   <xsl:param name="toc-context" select="."/>
338
339   <xsl:call-template name="subtoc">
340     <xsl:with-param name="toc-context" select="$toc-context"/>
341     <xsl:with-param name="nodes" select="sect4                                          |bridgehead[$bridgehead.in.toc != 0]"/>
342   </xsl:call-template>
343 </xsl:template>
344
345 <xsl:template match="sect4" mode="toc">
346   <xsl:param name="toc-context" select="."/>
347
348   <xsl:call-template name="subtoc">
349     <xsl:with-param name="toc-context" select="$toc-context"/>
350     <xsl:with-param name="nodes" select="sect5                                          |bridgehead[$bridgehead.in.toc != 0]"/>
351   </xsl:call-template>
352 </xsl:template>
353
354 <xsl:template match="sect5" mode="toc">
355   <xsl:param name="toc-context" select="."/>
356
357   <xsl:call-template name="subtoc">
358     <xsl:with-param name="toc-context" select="$toc-context"/>
359   </xsl:call-template>
360 </xsl:template>
361
362 <xsl:template match="simplesect" mode="toc">
363   <xsl:param name="toc-context" select="."/>
364
365   <xsl:call-template name="subtoc">
366     <xsl:with-param name="toc-context" select="$toc-context"/>
367   </xsl:call-template>
368 </xsl:template>
369
370 <xsl:template match="section" mode="toc">
371   <xsl:param name="toc-context" select="."/>
372
373   <xsl:call-template name="subtoc">
374     <xsl:with-param name="toc-context" select="$toc-context"/>
375     <xsl:with-param name="nodes" select="section                                          |bridgehead[$bridgehead.in.toc != 0]"/>
376   </xsl:call-template>
377 </xsl:template>
378
379 <xsl:template match="bridgehead" mode="toc">
380   <xsl:param name="toc-context" select="."/>
381
382   <xsl:if test="$bridgehead.in.toc != 0">
383     <xsl:call-template name="subtoc">
384       <xsl:with-param name="toc-context" select="$toc-context"/>
385     </xsl:call-template>
386   </xsl:if>
387 </xsl:template>
388
389 <xsl:template match="bibliography|glossary" mode="toc">
390   <xsl:param name="toc-context" select="."/>
391
392   <xsl:call-template name="subtoc">
393     <xsl:with-param name="toc-context" select="$toc-context"/>
394   </xsl:call-template>
395 </xsl:template>
396
397 <xsl:template match="index" mode="toc">
398   <xsl:param name="toc-context" select="."/>
399
400   <!-- If the index tag is not empty, it should be it in the TOC -->
401   <xsl:if test="* or $generate.index != 0">
402     <xsl:call-template name="subtoc">
403       <xsl:with-param name="toc-context" select="$toc-context"/>
404     </xsl:call-template>
405   </xsl:if>
406 </xsl:template>
407
408 <xsl:template match="refentry" mode="toc">
409   <xsl:param name="toc-context" select="."/>
410
411   <xsl:variable name="refmeta" select=".//refmeta"/>
412   <xsl:variable name="refentrytitle" select="$refmeta//refentrytitle"/>
413   <xsl:variable name="refnamediv" select=".//refnamediv"/>
414   <xsl:variable name="refname" select="$refnamediv//refname"/>
415   <xsl:variable name="refdesc" select="$refnamediv//refdescriptor"/>
416   <xsl:variable name="title">
417     <xsl:choose>
418       <xsl:when test="$refentrytitle">
419         <xsl:apply-templates select="$refentrytitle[1]" mode="titleabbrev.markup"/>
420       </xsl:when>
421       <xsl:when test="$refdesc">
422         <xsl:apply-templates select="$refdesc" mode="titleabbrev.markup"/>
423       </xsl:when>
424       <xsl:when test="$refname">
425         <xsl:apply-templates select="$refname[1]" mode="titleabbrev.markup"/>
426       </xsl:when>
427     </xsl:choose>
428   </xsl:variable>
429
430   <xsl:element name="{$toc.listitem.type}" namespace="http://www.w3.org/1999/xhtml">
431     <span class="refentrytitle">
432       <a>
433         <xsl:attribute name="href">
434           <xsl:call-template name="href.target"/>
435         </xsl:attribute>
436         <xsl:copy-of select="$title"/>
437       </a>
438     </span>
439     <span class="refpurpose">
440       <xsl:if test="$annotate.toc != 0">
441         <xsl:text> - </xsl:text>
442         <xsl:value-of select="refnamediv/refpurpose"/>
443       </xsl:if>
444     </span>
445   </xsl:element>
446 </xsl:template>
447
448 <xsl:template match="title" mode="toc">
449   <xsl:param name="toc-context" select="."/>
450
451   <a>
452     <xsl:attribute name="href">
453       <xsl:call-template name="href.target">
454         <xsl:with-param name="object" select=".."/>
455       </xsl:call-template>
456     </xsl:attribute>
457     <xsl:apply-templates/>
458   </a>
459 </xsl:template>
460
461 <xsl:template name="manual-toc">
462   <xsl:param name="toc-context" select="."/>
463   <xsl:param name="tocentry"/>
464
465   <!-- be careful, we don't want to change the current document to the other tree! -->
466
467   <xsl:if test="$tocentry">
468     <xsl:variable name="node" select="key('id', $tocentry/@linkend)"/>
469
470     <xsl:element name="{$toc.listitem.type}" namespace="http://www.w3.org/1999/xhtml">
471       <xsl:variable name="label">
472         <xsl:apply-templates select="$node" mode="label.markup"/>
473       </xsl:variable>
474       <xsl:copy-of select="$label"/>
475       <xsl:if test="$label != ''">
476         <xsl:value-of select="$autotoc.label.separator"/>
477       </xsl:if>
478       <a>
479         <xsl:attribute name="href">
480           <xsl:call-template name="href.target">
481             <xsl:with-param name="object" select="$node"/>
482           </xsl:call-template>
483         </xsl:attribute>
484         <xsl:apply-templates select="$node" mode="titleabbrev.markup"/>
485       </a>
486     </xsl:element>
487
488     <xsl:if test="$tocentry/*">
489       <xsl:element name="{$toc.list.type}" namespace="http://www.w3.org/1999/xhtml">
490         <xsl:call-template name="manual-toc">
491           <xsl:with-param name="tocentry" select="$tocentry/*[1]"/>
492         </xsl:call-template>
493       </xsl:element>
494     </xsl:if>
495
496     <xsl:if test="$tocentry/following-sibling::*">
497       <xsl:call-template name="manual-toc">
498         <xsl:with-param name="tocentry" select="$tocentry/following-sibling::*[1]"/>
499       </xsl:call-template>
500     </xsl:if>
501   </xsl:if>
502 </xsl:template>
503
504 <!-- ==================================================================== -->
505
506 <xsl:template name="list.of.titles">
507   <xsl:param name="toc-context" select="."/>
508   <xsl:param name="titles" select="'table'"/>
509   <xsl:param name="nodes" select=".//table"/>
510
511   <xsl:if test="$nodes">
512     <div class="list-of-{$titles}s">
513       <p>
514         <b>
515           <xsl:call-template name="gentext">
516             <xsl:with-param name="key">
517               <xsl:choose>
518                 <xsl:when test="$titles='table'">ListofTables</xsl:when>
519                 <xsl:when test="$titles='figure'">ListofFigures</xsl:when>
520                 <xsl:when test="$titles='equation'">ListofEquations</xsl:when>
521                 <xsl:when test="$titles='example'">ListofExamples</xsl:when>
522                 <xsl:when test="$titles='procedure'">ListofProcedures</xsl:when>
523                 <xsl:otherwise>ListofUnknown</xsl:otherwise>
524               </xsl:choose>
525             </xsl:with-param>
526           </xsl:call-template>
527         </b>
528       </p>
529
530       <xsl:element name="{$toc.list.type}" namespace="http://www.w3.org/1999/xhtml">
531         <xsl:apply-templates select="$nodes" mode="toc">
532           <xsl:with-param name="toc-context" select="$toc-context"/>
533         </xsl:apply-templates>
534       </xsl:element>
535     </div>
536   </xsl:if>
537 </xsl:template>
538
539 <xsl:template match="figure|table|example|equation|procedure" mode="toc">
540   <xsl:param name="toc-context" select="."/>
541
542   <xsl:element name="{$toc.listitem.type}" namespace="http://www.w3.org/1999/xhtml">
543     <xsl:variable name="label">
544       <xsl:apply-templates select="." mode="label.markup"/>
545     </xsl:variable>
546     <xsl:copy-of select="$label"/>
547     <xsl:if test="$label != ''">
548       <xsl:value-of select="$autotoc.label.separator"/>
549     </xsl:if>
550     <a>
551       <xsl:attribute name="href">
552         <xsl:call-template name="href.target"/>
553       </xsl:attribute>
554       <xsl:apply-templates select="." mode="titleabbrev.markup"/>
555     </a>
556   </xsl:element>
557 </xsl:template>
558
559 </xsl:stylesheet>