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