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: sections.xsl,v 1.32 2006/04/30 09:02:34 bobstayton Exp $
7     ********************************************************************
8
9     This file is part of the XSL DocBook Stylesheet distribution.
10     See ../README or http://nwalsh.com/docbook/xsl/ for copyright
11     and other information.
12
13     ******************************************************************** -->
14
15<!-- ==================================================================== -->
16
17<xsl:template match="section">
18  <xsl:variable name="depth" select="count(ancestor::section)+1"/>
19
20  <xsl:call-template name="id.warning"/>
21
22  <div class="{name(.)}">
23    <xsl:call-template name="dir">
24      <xsl:with-param name="inherit" select="1"/>
25    </xsl:call-template>
26    <xsl:call-template name="language.attribute"/>
27    <xsl:call-template name="section.titlepage"/>
28
29    <xsl:variable name="toc.params">
30      <xsl:call-template name="find.path.params">
31        <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
32      </xsl:call-template>
33    </xsl:variable>
34
35    <xsl:if test="contains($toc.params, 'toc')
36                  and $depth &lt;= $generate.section.toc.level">
37      <xsl:call-template name="section.toc">
38        <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
39      </xsl:call-template>
40      <xsl:call-template name="section.toc.separator"/>
41    </xsl:if>
42    <xsl:apply-templates/>
43    <xsl:call-template name="process.chunk.footnotes"/>
44  </div>
45</xsl:template>
46
47<xsl:template name="section.title">
48  <!-- the context node should be the title of a section when called -->
49  <xsl:variable name="section" select="(ancestor::section
50                                        |ancestor::simplesect
51                                        |ancestor::sect1
52                                        |ancestor::sect2
53                                        |ancestor::sect3
54                                        |ancestor::sect4
55                                        |ancestor::sect5)[last()]"/>
56
57  <xsl:variable name="renderas">
58    <xsl:choose>
59      <xsl:when test="$section/@renderas = 'sect1'">1</xsl:when>
60      <xsl:when test="$section/@renderas = 'sect2'">2</xsl:when>
61      <xsl:when test="$section/@renderas = 'sect3'">3</xsl:when>
62      <xsl:when test="$section/@renderas = 'sect4'">4</xsl:when>
63      <xsl:when test="$section/@renderas = 'sect5'">5</xsl:when>
64      <xsl:otherwise><xsl:value-of select="''"/></xsl:otherwise>
65    </xsl:choose>
66  </xsl:variable>
67
68  <xsl:variable name="level">
69    <xsl:choose>
70      <xsl:when test="$renderas != ''">
71        <xsl:value-of select="$renderas"/>
72      </xsl:when>
73      <xsl:otherwise>
74        <xsl:call-template name="section.level">
75          <xsl:with-param name="node" select="$section"/>
76        </xsl:call-template>
77      </xsl:otherwise>
78    </xsl:choose>
79  </xsl:variable>
80
81  <xsl:call-template name="section.heading">
82    <xsl:with-param name="section" select=".."/>
83    <xsl:with-param name="level" select="$level"/>
84    <xsl:with-param name="title">
85      <xsl:apply-templates select="$section" mode="object.title.markup">
86        <xsl:with-param name="allow-anchors" select="1"/>
87      </xsl:apply-templates>
88    </xsl:with-param>
89  </xsl:call-template>
90</xsl:template>
91
92<xsl:template match="section/title" mode="titlepage.mode" priority="2">
93  <xsl:call-template name="section.title"/>
94</xsl:template>
95
96<xsl:template match="sect1">
97  <xsl:call-template name="id.warning"/>
98
99  <div class="{name(.)}">
100    <xsl:call-template name="dir">
101      <xsl:with-param name="inherit" select="1"/>
102    </xsl:call-template>
103    <xsl:call-template name="language.attribute"/>
104
105    <xsl:choose>
106      <xsl:when test="@renderas = 'sect2'">
107        <xsl:call-template name="sect2.titlepage"/>
108      </xsl:when>
109      <xsl:when test="@renderas = 'sect3'">
110        <xsl:call-template name="sect3.titlepage"/>
111      </xsl:when>
112      <xsl:when test="@renderas = 'sect4'">
113        <xsl:call-template name="sect4.titlepage"/>
114      </xsl:when>
115      <xsl:when test="@renderas = 'sect5'">
116        <xsl:call-template name="sect5.titlepage"/>
117      </xsl:when>
118      <xsl:otherwise>
119        <xsl:call-template name="sect1.titlepage"/>
120      </xsl:otherwise>
121    </xsl:choose>
122
123    <xsl:variable name="toc.params">
124      <xsl:call-template name="find.path.params">
125        <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
126      </xsl:call-template>
127    </xsl:variable>
128
129    <xsl:if test="contains($toc.params, 'toc')
130                  and $generate.section.toc.level &gt;= 1">
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:call-template name="section.toc.separator"/>
135    </xsl:if>
136    <xsl:apply-templates/>
137    <xsl:call-template name="process.chunk.footnotes"/>
138  </div>
139</xsl:template>
140
141<xsl:template match="sect1/title" mode="titlepage.mode" priority="2">
142  <xsl:call-template name="section.title"/>
143</xsl:template>
144
145<xsl:template match="sect2">
146  <xsl:call-template name="id.warning"/>
147
148  <div class="{name(.)}">
149    <xsl:call-template name="dir">
150      <xsl:with-param name="inherit" select="1"/>
151    </xsl:call-template>
152    <xsl:call-template name="language.attribute"/>
153
154    <xsl:choose>
155      <xsl:when test="@renderas = 'sect1'">
156        <xsl:call-template name="sect1.titlepage"/>
157      </xsl:when>
158      <xsl:when test="@renderas = 'sect3'">
159        <xsl:call-template name="sect3.titlepage"/>
160      </xsl:when>
161      <xsl:when test="@renderas = 'sect4'">
162        <xsl:call-template name="sect4.titlepage"/>
163      </xsl:when>
164      <xsl:when test="@renderas = 'sect5'">
165        <xsl:call-template name="sect5.titlepage"/>
166      </xsl:when>
167      <xsl:otherwise>
168        <xsl:call-template name="sect2.titlepage"/>
169      </xsl:otherwise>
170    </xsl:choose>
171
172    <xsl:variable name="toc.params">
173      <xsl:call-template name="find.path.params">
174        <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
175      </xsl:call-template>
176    </xsl:variable>
177
178    <xsl:if test="contains($toc.params, 'toc')
179                  and $generate.section.toc.level &gt;= 2">
180      <xsl:call-template name="section.toc">
181        <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
182      </xsl:call-template>
183      <xsl:call-template name="section.toc.separator"/>
184    </xsl:if>
185    <xsl:apply-templates/>
186    <xsl:call-template name="process.chunk.footnotes"/>
187  </div>
188</xsl:template>
189
190<xsl:template match="sect2/title" mode="titlepage.mode" priority="2">
191  <xsl:call-template name="section.title"/>
192</xsl:template>
193
194<xsl:template match="sect3">
195  <xsl:call-template name="id.warning"/>
196
197  <div class="{name(.)}">
198    <xsl:call-template name="dir">
199      <xsl:with-param name="inherit" select="1"/>
200    </xsl:call-template>
201    <xsl:call-template name="language.attribute"/>
202
203    <xsl:choose>
204      <xsl:when test="@renderas = 'sect1'">
205        <xsl:call-template name="sect1.titlepage"/>
206      </xsl:when>
207      <xsl:when test="@renderas = 'sect2'">
208        <xsl:call-template name="sect2.titlepage"/>
209      </xsl:when>
210      <xsl:when test="@renderas = 'sect4'">
211        <xsl:call-template name="sect4.titlepage"/>
212      </xsl:when>
213      <xsl:when test="@renderas = 'sect5'">
214        <xsl:call-template name="sect5.titlepage"/>
215      </xsl:when>
216      <xsl:otherwise>
217        <xsl:call-template name="sect3.titlepage"/>
218      </xsl:otherwise>
219    </xsl:choose>
220
221    <xsl:variable name="toc.params">
222      <xsl:call-template name="find.path.params">
223        <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
224      </xsl:call-template>
225    </xsl:variable>
226
227    <xsl:if test="contains($toc.params, 'toc')
228                  and $generate.section.toc.level &gt;= 3">
229      <xsl:call-template name="section.toc">
230        <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
231      </xsl:call-template>
232      <xsl:call-template name="section.toc.separator"/>
233    </xsl:if>
234    <xsl:apply-templates/>
235    <xsl:call-template name="process.chunk.footnotes"/>
236  </div>
237</xsl:template>
238
239<xsl:template match="sect3/title" mode="titlepage.mode" priority="2">
240  <xsl:call-template name="section.title"/>
241</xsl:template>
242
243<xsl:template match="sect4">
244  <xsl:call-template name="id.warning"/>
245
246  <div class="{name(.)}">
247    <xsl:call-template name="dir">
248      <xsl:with-param name="inherit" select="1"/>
249    </xsl:call-template>
250    <xsl:call-template name="language.attribute"/>
251
252    <xsl:choose>
253      <xsl:when test="@renderas = 'sect1'">
254        <xsl:call-template name="sect1.titlepage"/>
255      </xsl:when>
256      <xsl:when test="@renderas = 'sect2'">
257        <xsl:call-template name="sect2.titlepage"/>
258      </xsl:when>
259      <xsl:when test="@renderas = 'sect3'">
260        <xsl:call-template name="sect3.titlepage"/>
261      </xsl:when>
262      <xsl:when test="@renderas = 'sect5'">
263        <xsl:call-template name="sect5.titlepage"/>
264      </xsl:when>
265      <xsl:otherwise>
266        <xsl:call-template name="sect4.titlepage"/>
267      </xsl:otherwise>
268    </xsl:choose>
269
270    <xsl:variable name="toc.params">
271      <xsl:call-template name="find.path.params">
272        <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
273      </xsl:call-template>
274    </xsl:variable>
275
276    <xsl:if test="contains($toc.params, 'toc')
277                  and $generate.section.toc.level &gt;= 4">
278      <xsl:call-template name="section.toc">
279        <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
280      </xsl:call-template>
281      <xsl:call-template name="section.toc.separator"/>
282    </xsl:if>
283    <xsl:apply-templates/>
284    <xsl:call-template name="process.chunk.footnotes"/>
285  </div>
286</xsl:template>
287
288<xsl:template match="sect4/title" mode="titlepage.mode" priority="2">
289  <xsl:call-template name="section.title"/>
290</xsl:template>
291
292<xsl:template match="sect5">
293  <xsl:call-template name="id.warning"/>
294
295  <div class="{name(.)}">
296    <xsl:call-template name="dir">
297      <xsl:with-param name="inherit" select="1"/>
298    </xsl:call-template>
299    <xsl:call-template name="language.attribute"/>
300
301    <xsl:choose>
302      <xsl:when test="@renderas = 'sect1'">
303        <xsl:call-template name="sect1.titlepage"/>
304      </xsl:when>
305      <xsl:when test="@renderas = 'sect2'">
306        <xsl:call-template name="sect2.titlepage"/>
307      </xsl:when>
308      <xsl:when test="@renderas = 'sect3'">
309        <xsl:call-template name="sect3.titlepage"/>
310      </xsl:when>
311      <xsl:when test="@renderas = 'sect4'">
312        <xsl:call-template name="sect4.titlepage"/>
313      </xsl:when>
314      <xsl:otherwise>
315        <xsl:call-template name="sect5.titlepage"/>
316      </xsl:otherwise>
317    </xsl:choose>
318
319    <xsl:variable name="toc.params">
320      <xsl:call-template name="find.path.params">
321        <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
322      </xsl:call-template>
323    </xsl:variable>
324
325    <xsl:if test="contains($toc.params, 'toc')
326                  and $generate.section.toc.level &gt;= 5">
327      <xsl:call-template name="section.toc">
328        <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
329      </xsl:call-template>
330      <xsl:call-template name="section.toc.separator"/>
331    </xsl:if>
332    <xsl:apply-templates/>
333    <xsl:call-template name="process.chunk.footnotes"/>
334  </div>
335</xsl:template>
336
337<xsl:template match="sect5/title" mode="titlepage.mode" priority="2">
338  <xsl:call-template name="section.title"/>
339</xsl:template>
340
341<xsl:template match="simplesect">
342  <xsl:call-template name="id.warning"/>
343
344  <div class="{name(.)}">
345    <xsl:call-template name="dir">
346      <xsl:with-param name="inherit" select="1"/>
347    </xsl:call-template>
348    <xsl:call-template name="language.attribute"/>
349    <xsl:call-template name="simplesect.titlepage"/>
350    <xsl:apply-templates/>
351  </div>
352</xsl:template>
353
354<xsl:template match="simplesect/title" mode="titlepage.mode" priority="2">
355  <xsl:call-template name="section.title"/>
356</xsl:template>
357
358<xsl:template match="section/title"></xsl:template>
359<xsl:template match="section/titleabbrev"></xsl:template>
360<xsl:template match="section/subtitle"></xsl:template>
361<xsl:template match="sectioninfo"></xsl:template>
362
363<xsl:template match="sect1/title"></xsl:template>
364<xsl:template match="sect1/titleabbrev"></xsl:template>
365<xsl:template match="sect1/subtitle"></xsl:template>
366<xsl:template match="sect1info"></xsl:template>
367
368<xsl:template match="sect2/title"></xsl:template>
369<xsl:template match="sect2/subtitle"></xsl:template>
370<xsl:template match="sect2/titleabbrev"></xsl:template>
371<xsl:template match="sect2info"></xsl:template>
372
373<xsl:template match="sect3/title"></xsl:template>
374<xsl:template match="sect3/subtitle"></xsl:template>
375<xsl:template match="sect3/titleabbrev"></xsl:template>
376<xsl:template match="sect3info"></xsl:template>
377
378<xsl:template match="sect4/title"></xsl:template>
379<xsl:template match="sect4/subtitle"></xsl:template>
380<xsl:template match="sect4/titleabbrev"></xsl:template>
381<xsl:template match="sect4info"></xsl:template>
382
383<xsl:template match="sect5/title"></xsl:template>
384<xsl:template match="sect5/subtitle"></xsl:template>
385<xsl:template match="sect5/titleabbrev"></xsl:template>
386<xsl:template match="sect5info"></xsl:template>
387
388<xsl:template match="simplesect/title"></xsl:template>
389<xsl:template match="simplesect/subtitle"></xsl:template>
390<xsl:template match="simplesect/titleabbrev"></xsl:template>
391
392<!-- ==================================================================== -->
393
394<xsl:template name="section.heading">
395  <xsl:param name="section" select="."/>
396  <xsl:param name="level" select="1"/>
397  <xsl:param name="allow-anchors" select="1"/>
398  <xsl:param name="title"/>
399  <xsl:param name="class" select="'title'"/>
400
401  <xsl:variable name="id">
402    <xsl:choose>
403      <!-- if title is in an *info wrapper, get the grandparent -->
404      <xsl:when test="contains(local-name(..), 'info')">
405        <xsl:call-template name="object.id">
406          <xsl:with-param name="object" select="../.."/>
407        </xsl:call-template>
408      </xsl:when>
409      <xsl:otherwise>
410        <xsl:call-template name="object.id">
411          <xsl:with-param name="object" select=".."/>
412        </xsl:call-template>
413      </xsl:otherwise>
414    </xsl:choose>
415  </xsl:variable>
416
417  <!-- HTML H level is one higher than section level -->
418  <xsl:variable name="hlevel">
419    <xsl:choose>
420      <!-- highest valid HTML H level is H6; so anything nested deeper
421           than 5 levels down just becomes H6 -->
422      <xsl:when test="$level &gt; 5">6</xsl:when>
423      <xsl:otherwise>
424	<xsl:value-of select="$level + 1"/>
425      </xsl:otherwise>
426    </xsl:choose>
427  </xsl:variable>
428  <xsl:element name="h{$hlevel}">
429    <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
430    <xsl:if test="$css.decoration != '0'">
431      <xsl:if test="$hlevel&lt;3">
432        <xsl:attribute name="style">clear: both</xsl:attribute>
433      </xsl:if>
434    </xsl:if>
435    <xsl:if test="$allow-anchors != 0">
436      <xsl:call-template name="anchor">
437        <xsl:with-param name="node" select="$section"/>
438        <xsl:with-param name="conditional" select="0"/>
439      </xsl:call-template>
440    </xsl:if>
441    <xsl:copy-of select="$title"/>
442  </xsl:element>
443</xsl:template>
444
445<!-- ==================================================================== -->
446
447<xsl:template match="bridgehead">
448  <xsl:variable name="container"
449                select="(ancestor::appendix
450                        |ancestor::article
451                        |ancestor::bibliography
452                        |ancestor::chapter
453                        |ancestor::glossary
454                        |ancestor::glossdiv
455                        |ancestor::index
456                        |ancestor::partintro
457                        |ancestor::preface
458                        |ancestor::refsect1
459                        |ancestor::refsect2
460                        |ancestor::refsect3
461                        |ancestor::sect1
462                        |ancestor::sect2
463                        |ancestor::sect3
464                        |ancestor::sect4
465                        |ancestor::sect5
466                        |ancestor::section
467                        |ancestor::setindex
468                        |ancestor::simplesect)[last()]"/>
469
470  <xsl:variable name="clevel">
471    <xsl:choose>
472      <xsl:when test="local-name($container) = 'appendix'
473                      or local-name($container) = 'chapter'
474                      or local-name($container) = 'article'
475                      or local-name($container) = 'bibliography'
476                      or local-name($container) = 'glossary'
477                      or local-name($container) = 'index'
478                      or local-name($container) = 'partintro'
479                      or local-name($container) = 'preface'
480                      or local-name($container) = 'setindex'">1</xsl:when>
481      <xsl:when test="local-name($container) = 'glossdiv'">
482        <xsl:value-of select="count(ancestor::glossdiv)+1"/>
483      </xsl:when>
484      <xsl:when test="local-name($container) = 'sect1'
485                      or local-name($container) = 'sect2'
486                      or local-name($container) = 'sect3'
487                      or local-name($container) = 'sect4'
488                      or local-name($container) = 'sect5'
489                      or local-name($container) = 'refsect1'
490                      or local-name($container) = 'refsect2'
491                      or local-name($container) = 'refsect3'
492                      or local-name($container) = 'section'
493                      or local-name($container) = 'simplesect'">
494        <xsl:variable name="slevel">
495          <xsl:call-template name="section.level">
496            <xsl:with-param name="node" select="$container"/>
497          </xsl:call-template>
498        </xsl:variable>
499        <xsl:value-of select="$slevel + 1"/>
500      </xsl:when>
501      <xsl:otherwise>1</xsl:otherwise>
502    </xsl:choose>
503  </xsl:variable>
504
505  <!-- HTML H level is one higher than section level -->
506  <xsl:variable name="hlevel">
507    <xsl:choose>
508      <xsl:when test="@renderas = 'sect1'">2</xsl:when>
509      <xsl:when test="@renderas = 'sect2'">3</xsl:when>
510      <xsl:when test="@renderas = 'sect3'">4</xsl:when>
511      <xsl:when test="@renderas = 'sect4'">5</xsl:when>
512      <xsl:when test="@renderas = 'sect5'">6</xsl:when>
513      <xsl:otherwise>
514        <xsl:value-of select="$clevel + 1"/>
515      </xsl:otherwise>
516    </xsl:choose>
517  </xsl:variable>
518
519  <xsl:element name="h{$hlevel}">
520    <xsl:call-template name="anchor">
521      <xsl:with-param name="conditional" select="0"/>
522    </xsl:call-template>
523    <xsl:apply-templates/>
524  </xsl:element>
525</xsl:template>
526
527<xsl:template match="section/subtitle" mode="titlepage.mode" priority="2">
528  <xsl:call-template name="section.subtitle"/>
529</xsl:template>
530
531<xsl:template match="simplesect/subtitle" mode="titlepage.mode" priority="2">
532  <xsl:call-template name="section.subtitle"/>
533</xsl:template>
534
535<xsl:template match="sect1/subtitle" mode="titlepage.mode" priority="2">
536  <xsl:call-template name="section.subtitle"/>
537</xsl:template>
538
539<xsl:template match="sect2/subtitle" mode="titlepage.mode" priority="2">
540  <xsl:call-template name="section.subtitle"/>
541</xsl:template>
542
543<xsl:template match="sect3/subtitle" mode="titlepage.mode" priority="2">
544  <xsl:call-template name="section.subtitle"/>
545</xsl:template>
546
547<xsl:template match="sect4/subtitle" mode="titlepage.mode" priority="2">
548  <xsl:call-template name="section.subtitle"/>
549</xsl:template>
550
551<xsl:template match="sect5/subtitle" mode="titlepage.mode" priority="2">
552  <xsl:call-template name="section.subtitle"/>
553</xsl:template>
554
555<xsl:template name="section.subtitle">
556  <!-- the context node should be the subtitle of a section when called -->
557  <xsl:variable name="section" select="(ancestor::section
558                                        |ancestor::simplesect
559                                        |ancestor::sect1
560                                        |ancestor::sect2
561                                        |ancestor::sect3
562                                        |ancestor::sect4
563                                        |ancestor::sect5)[last()]"/>
564
565  <xsl:variable name="level">
566    <xsl:call-template name="section.level">
567      <xsl:with-param name="node" select="$section"/>
568    </xsl:call-template>
569  </xsl:variable>
570
571  <xsl:call-template name="section.heading">
572    <xsl:with-param name="section" select=".."/>
573    <xsl:with-param name="allow-anchors" select="0"/>
574    <!-- subtitle heading level one higher than section level -->
575    <xsl:with-param name="level" select="$level + 1"/>
576    <xsl:with-param name="class" select="'subtitle'"/>
577    <xsl:with-param name="title">
578      <xsl:apply-templates select="$section" mode="object.subtitle.markup">
579        <xsl:with-param name="allow-anchors" select="0"/>
580      </xsl:apply-templates>
581    </xsl:with-param>
582  </xsl:call-template>
583</xsl:template>
584
585</xsl:stylesheet>
586
587