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