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