]> git.stg.codes - stg.git/blob - doc/xslt/xhtml/toc.xsl
Set output encoding to utf-8.
[stg.git] / doc / xslt / xhtml / toc.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="http://www.w3.org/1999/xhtml" version="1.0">
5
6 <!-- ********************************************************************
7      $Id: toc.xsl 8421 2009-05-04 07:49:49Z 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:template match="set/toc | book/toc | part/toc">
19   <xsl:variable name="toc.params">
20     <xsl:call-template name="find.path.params">
21       <xsl:with-param name="node" select="parent::*"/>
22       <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
23     </xsl:call-template>
24   </xsl:variable>
25
26   <!-- Do not output the toc element if one is already generated
27        by the use of $generate.toc parameter, or if
28        generating a source toc is turned off -->
29   <xsl:if test="not(contains($toc.params, 'toc')) and                 ($process.source.toc != 0 or $process.empty.source.toc != 0)">
30     <xsl:variable name="content">
31       <xsl:choose>
32         <xsl:when test="* and $process.source.toc != 0">
33           <xsl:apply-templates/>
34         </xsl:when>
35         <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">
36           <!-- trick to switch context node to parent element -->
37           <xsl:for-each select="parent::*">
38             <xsl:choose>
39               <xsl:when test="self::set">
40                 <xsl:call-template name="set.toc">
41                   <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
42                 </xsl:call-template>
43               </xsl:when>
44               <xsl:when test="self::book">
45                 <xsl:call-template name="division.toc">
46                   <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
47                 </xsl:call-template>
48               </xsl:when>
49               <xsl:when test="self::part">
50                 <xsl:call-template name="division.toc">
51                   <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
52                 </xsl:call-template>
53               </xsl:when>
54             </xsl:choose>
55           </xsl:for-each>
56         </xsl:when>
57       </xsl:choose>
58     </xsl:variable>
59
60     <xsl:if test="string-length(normalize-space($content)) != 0">
61       <xsl:copy-of select="$content"/>
62     </xsl:if>
63   </xsl:if>
64 </xsl:template>
65   
66 <xsl:template match="chapter/toc | appendix/toc | preface/toc | article/toc">
67   <xsl:variable name="toc.params">
68     <xsl:call-template name="find.path.params">
69       <xsl:with-param name="node" select="parent::*"/>
70       <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
71     </xsl:call-template>
72   </xsl:variable>
73
74   <!-- Do not output the toc element if one is already generated
75        by the use of $generate.toc parameter, or if
76        generating a source toc is turned off -->
77   <xsl:if test="not(contains($toc.params, 'toc')) and                 ($process.source.toc != 0 or $process.empty.source.toc != 0)">
78     <xsl:choose>
79       <xsl:when test="* and $process.source.toc != 0">
80         <div>
81           <xsl:apply-templates select="." mode="common.html.attributes"/>
82           <xsl:apply-templates select="title"/> 
83           <dl>
84             <xsl:apply-templates select="." mode="common.html.attributes"/>
85             <xsl:apply-templates select="*[not(self::title)]"/> 
86           </dl>
87         </div>
88         <xsl:call-template name="component.toc.separator"/>
89       </xsl:when>
90       <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">
91         <!-- trick to switch context node to section element -->
92         <xsl:for-each select="parent::*">
93           <xsl:call-template name="component.toc">
94             <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
95           </xsl:call-template>
96         </xsl:for-each>
97         <xsl:call-template name="component.toc.separator"/>
98       </xsl:when>
99     </xsl:choose>
100   </xsl:if>
101 </xsl:template>
102
103 <xsl:template match="section/toc                     |sect1/toc                     |sect2/toc                     |sect3/toc                     |sect4/toc                     |sect5/toc">
104
105   <xsl:variable name="toc.params">
106     <xsl:call-template name="find.path.params">
107       <xsl:with-param name="node" select="parent::*"/>
108       <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
109     </xsl:call-template>
110   </xsl:variable>
111
112   <!-- Do not output the toc element if one is already generated
113        by the use of $generate.toc parameter, or if
114        generating a source toc is turned off -->
115   <xsl:if test="not(contains($toc.params, 'toc')) and                 ($process.source.toc != 0 or $process.empty.source.toc != 0)">
116     <xsl:choose>
117       <xsl:when test="* and $process.source.toc != 0">
118         <div>
119           <xsl:apply-templates select="." mode="common.html.attributes"/>
120           <xsl:apply-templates select="title"/> 
121           <dl>
122             <xsl:apply-templates select="." mode="common.html.attributes"/>
123             <xsl:apply-templates select="*[not(self::title)]"/> 
124           </dl>
125         </div>
126         <xsl:call-template name="section.toc.separator"/>
127       </xsl:when>
128       <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">
129         <!-- trick to switch context node to section element -->
130         <xsl:for-each select="parent::*">
131           <xsl:call-template name="section.toc">
132             <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
133           </xsl:call-template>
134         </xsl:for-each>
135         <xsl:call-template name="section.toc.separator"/>
136       </xsl:when>
137     </xsl:choose>
138   </xsl:if>
139 </xsl:template>
140
141 <!-- ==================================================================== -->
142
143 <xsl:template match="tocpart|tocchap                      |toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
144   <xsl:variable name="sub-toc">
145     <xsl:if test="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
146       <xsl:choose>
147         <xsl:when test="$toc.list.type = 'dl'">
148           <dd>
149             <xsl:apply-templates select="." mode="common.html.attributes"/>
150             <xsl:element name="{$toc.list.type}" namespace="http://www.w3.org/1999/xhtml">
151               <xsl:apply-templates select="." mode="common.html.attributes"/>
152               <xsl:apply-templates select="tocchap|toclevel1|toclevel2|                                            toclevel3|toclevel4|toclevel5"/>
153             </xsl:element>
154           </dd>
155         </xsl:when>
156         <xsl:otherwise>
157           <xsl:element name="{$toc.list.type}" namespace="http://www.w3.org/1999/xhtml">
158             <xsl:apply-templates select="." mode="common.html.attributes"/>
159             <xsl:apply-templates select="tocchap|toclevel1|toclevel2|                                          toclevel3|toclevel4|toclevel5"/>
160           </xsl:element>
161         </xsl:otherwise>
162       </xsl:choose>
163     </xsl:if>
164   </xsl:variable>
165
166   <xsl:apply-templates select="tocentry[position() != last()]"/>
167
168   <xsl:choose>
169     <xsl:when test="$toc.list.type = 'dl'">
170       <dt>
171         <xsl:apply-templates select="." mode="common.html.attributes"/>
172         <xsl:apply-templates select="tocentry[position() = last()]"/>
173       </dt>
174       <xsl:copy-of select="$sub-toc"/>
175     </xsl:when>
176     <xsl:otherwise>
177       <li>
178         <xsl:apply-templates select="." mode="common.html.attributes"/>
179         <xsl:apply-templates select="tocentry[position() = last()]"/>
180         <xsl:copy-of select="$sub-toc"/>
181       </li>
182     </xsl:otherwise>
183   </xsl:choose>
184 </xsl:template>
185
186 <xsl:template match="tocentry|tocdiv|lotentry|tocfront|tocback">
187   <xsl:choose>
188     <xsl:when test="$toc.list.type = 'dl'">
189       <dt>
190         <xsl:apply-templates select="." mode="common.html.attributes"/>
191         <xsl:call-template name="tocentry-content"/>
192       </dt>
193     </xsl:when>
194     <xsl:otherwise>
195       <li>
196         <xsl:apply-templates select="." mode="common.html.attributes"/>
197         <xsl:call-template name="tocentry-content"/>
198       </li>
199     </xsl:otherwise>
200   </xsl:choose>
201 </xsl:template>
202
203 <xsl:template match="tocentry[position() = last()]" priority="2">
204   <xsl:call-template name="tocentry-content"/>
205 </xsl:template>
206
207 <xsl:template name="tocentry-content">
208   <xsl:variable name="targets" select="key('id',@linkend)"/>
209   <xsl:variable name="target" select="$targets[1]"/>
210
211   <xsl:choose>
212     <xsl:when test="@linkend">
213       <xsl:call-template name="check.id.unique">
214         <xsl:with-param name="linkend" select="@linkend"/>
215       </xsl:call-template>
216       <a>
217         <xsl:attribute name="href">
218           <xsl:call-template name="href.target">
219             <xsl:with-param name="object" select="$target"/>
220           </xsl:call-template>
221         </xsl:attribute>
222         <xsl:apply-templates/>
223       </a>
224     </xsl:when>
225     <xsl:otherwise>
226       <xsl:apply-templates/>
227     </xsl:otherwise>
228   </xsl:choose>
229 </xsl:template>
230
231 <xsl:template match="toc/title">
232   <div>
233     <xsl:apply-templates select="." mode="common.html.attributes"/>
234     <xsl:apply-templates/>
235   </div>
236 </xsl:template>
237
238 <xsl:template match="toc/subtitle">
239   <div>
240     <xsl:apply-templates select="." mode="common.html.attributes"/>
241     <xsl:apply-templates/>
242   </div>
243 </xsl:template>
244
245 <xsl:template match="toc/titleabbrev">
246 </xsl:template>
247
248 <!-- ==================================================================== -->
249
250 <!-- A lot element must have content, because there is no attribute
251      to select what kind of list should be generated -->
252 <xsl:template match="book/lot | part/lot">
253   <!-- Don't generate a page sequence unless there is content -->
254   <xsl:variable name="content">
255     <xsl:choose>
256       <xsl:when test="* and $process.source.toc != 0">
257         <div>
258           <xsl:apply-templates select="." mode="common.html.attributes"/>
259           <xsl:apply-templates/>
260         </div>
261       </xsl:when>
262       <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
263         <xsl:call-template name="process.empty.lot"/>
264       </xsl:when>
265     </xsl:choose>
266   </xsl:variable>
267
268   <xsl:if test="string-length(normalize-space($content)) != 0">
269     <xsl:copy-of select="$content"/>
270   </xsl:if>
271 </xsl:template>
272   
273 <xsl:template match="chapter/lot | appendix/lot | preface/lot | article/lot">
274   <xsl:choose>
275     <xsl:when test="* and $process.source.toc != 0">
276       <div>
277         <xsl:apply-templates select="." mode="common.html.attributes"/>
278         <xsl:apply-templates/>
279       </div>
280       <xsl:call-template name="component.toc.separator"/>
281     </xsl:when>
282     <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
283       <xsl:call-template name="process.empty.lot"/>
284     </xsl:when>
285   </xsl:choose>
286 </xsl:template>
287
288 <xsl:template match="section/lot                     |sect1/lot                     |sect2/lot                     |sect3/lot                     |sect4/lot                     |sect5/lot">
289   <xsl:choose>
290     <xsl:when test="* and $process.source.toc != 0">
291       <div>
292         <xsl:apply-templates select="." mode="common.html.attributes"/>
293         <xsl:apply-templates/>
294       </div>
295       <xsl:call-template name="section.toc.separator"/>
296     </xsl:when>
297     <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
298       <xsl:call-template name="process.empty.lot"/>
299     </xsl:when>
300   </xsl:choose>
301 </xsl:template>
302
303 <xsl:template name="process.empty.lot">
304   <!-- An empty lot element does not provide any information to indicate
305        what should be included in it.  You can customize this
306        template to generate a lot based on @role or something -->
307   <xsl:message>
308     <xsl:text>Warning: don't know what to generate for </xsl:text>
309     <xsl:text>lot that has no children.</xsl:text>
310   </xsl:message>
311 </xsl:template>
312
313 <xsl:template match="lot/title">
314   <div>
315     <xsl:apply-templates select="." mode="common.html.attributes"/>
316     <xsl:apply-templates/>
317   </div>
318 </xsl:template>
319
320 <xsl:template match="lot/subtitle">
321   <div>
322     <xsl:apply-templates select="." mode="common.html.attributes"/>
323     <xsl:apply-templates/>
324   </div>
325 </xsl:template>
326
327 <xsl:template match="lot/titleabbrev">
328 </xsl:template>
329
330 </xsl:stylesheet>