2 <xsl:stylesheet xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform"
5 <!-- ********************************************************************
6 $Id: sections.xsl,v 1.1 2007/03/10 05:15:13 scott Exp $
7 ********************************************************************
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.
13 ******************************************************************** -->
15 <!-- ==================================================================== -->
17 <xsl:template match=
"section">
18 <xsl:variable name=
"depth" select=
"count(ancestor::section)+1"/>
20 <xsl:call-template name=
"id.warning"/>
23 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
24 <xsl:call-template name=
"dir">
25 <xsl:with-param name=
"inherit" select=
"1"/>
27 <xsl:call-template name=
"language.attribute"/>
28 <xsl:call-template name=
"section.titlepage"/>
30 <xsl:variable name=
"toc.params">
31 <xsl:call-template name=
"find.path.params">
32 <xsl:with-param name=
"table" select=
"normalize-space($generate.toc)"/>
36 <xsl:if test=
"contains($toc.params, 'toc')
37 and $depth <= $generate.section.toc.level">
38 <xsl:call-template name=
"section.toc">
39 <xsl:with-param name=
"toc.title.p" select=
"contains($toc.params, 'title')"/>
41 <xsl:call-template name=
"section.toc.separator"/>
43 <xsl:apply-templates/>
44 <xsl:call-template name=
"process.chunk.footnotes"/>
48 <xsl:template name=
"section.title">
49 <!-- the context node should be the title of a section when called -->
50 <xsl:variable name=
"section" select=
"(ancestor::section
56 |ancestor::sect5)[last()]"/>
58 <xsl:variable name=
"renderas">
60 <xsl:when test=
"$section/@renderas = 'sect1'">1</xsl:when>
61 <xsl:when test=
"$section/@renderas = 'sect2'">2</xsl:when>
62 <xsl:when test=
"$section/@renderas = 'sect3'">3</xsl:when>
63 <xsl:when test=
"$section/@renderas = 'sect4'">4</xsl:when>
64 <xsl:when test=
"$section/@renderas = 'sect5'">5</xsl:when>
65 <xsl:otherwise><xsl:value-of select=
"''"/></xsl:otherwise>
69 <xsl:variable name=
"level">
71 <xsl:when test=
"$renderas != ''">
72 <xsl:value-of select=
"$renderas"/>
75 <xsl:call-template name=
"section.level">
76 <xsl:with-param name=
"node" select=
"$section"/>
82 <xsl:call-template name=
"section.heading">
83 <xsl:with-param name=
"section" select=
"$section"/>
84 <xsl:with-param name=
"level" select=
"$level"/>
85 <xsl:with-param name=
"title">
86 <xsl:apply-templates select=
"$section" mode=
"object.title.markup">
87 <xsl:with-param name=
"allow-anchors" select=
"1"/>
88 </xsl:apply-templates>
93 <xsl:template match=
"section/title
96 mode=
"titlepage.mode" priority=
"2">
97 <xsl:call-template name=
"section.title"/>
100 <xsl:template match=
"sect1">
101 <xsl:call-template name=
"id.warning"/>
104 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
105 <xsl:call-template name=
"dir">
106 <xsl:with-param name=
"inherit" select=
"1"/>
108 <xsl:call-template name=
"language.attribute"/>
111 <xsl:when test=
"@renderas = 'sect2'">
112 <xsl:call-template name=
"sect2.titlepage"/>
114 <xsl:when test=
"@renderas = 'sect3'">
115 <xsl:call-template name=
"sect3.titlepage"/>
117 <xsl:when test=
"@renderas = 'sect4'">
118 <xsl:call-template name=
"sect4.titlepage"/>
120 <xsl:when test=
"@renderas = 'sect5'">
121 <xsl:call-template name=
"sect5.titlepage"/>
124 <xsl:call-template name=
"sect1.titlepage"/>
128 <xsl:variable name=
"toc.params">
129 <xsl:call-template name=
"find.path.params">
130 <xsl:with-param name=
"table" select=
"normalize-space($generate.toc)"/>
134 <xsl:if test=
"contains($toc.params, 'toc')
135 and $generate.section.toc.level >= 1">
136 <xsl:call-template name=
"section.toc">
137 <xsl:with-param name=
"toc.title.p" select=
"contains($toc.params, 'title')"/>
139 <xsl:call-template name=
"section.toc.separator"/>
141 <xsl:apply-templates/>
142 <xsl:call-template name=
"process.chunk.footnotes"/>
146 <xsl:template match=
"sect1/title
149 mode=
"titlepage.mode" priority=
"2">
150 <xsl:call-template name=
"section.title"/>
153 <xsl:template match=
"sect2">
154 <xsl:call-template name=
"id.warning"/>
157 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
158 <xsl:call-template name=
"dir">
159 <xsl:with-param name=
"inherit" select=
"1"/>
161 <xsl:call-template name=
"language.attribute"/>
164 <xsl:when test=
"@renderas = 'sect1'">
165 <xsl:call-template name=
"sect1.titlepage"/>
167 <xsl:when test=
"@renderas = 'sect3'">
168 <xsl:call-template name=
"sect3.titlepage"/>
170 <xsl:when test=
"@renderas = 'sect4'">
171 <xsl:call-template name=
"sect4.titlepage"/>
173 <xsl:when test=
"@renderas = 'sect5'">
174 <xsl:call-template name=
"sect5.titlepage"/>
177 <xsl:call-template name=
"sect2.titlepage"/>
181 <xsl:variable name=
"toc.params">
182 <xsl:call-template name=
"find.path.params">
183 <xsl:with-param name=
"table" select=
"normalize-space($generate.toc)"/>
187 <xsl:if test=
"contains($toc.params, 'toc')
188 and $generate.section.toc.level >= 2">
189 <xsl:call-template name=
"section.toc">
190 <xsl:with-param name=
"toc.title.p" select=
"contains($toc.params, 'title')"/>
192 <xsl:call-template name=
"section.toc.separator"/>
194 <xsl:apply-templates/>
195 <xsl:call-template name=
"process.chunk.footnotes"/>
199 <xsl:template match=
"sect2/title
202 mode=
"titlepage.mode" priority=
"2">
203 <xsl:call-template name=
"section.title"/>
206 <xsl:template match=
"sect3">
207 <xsl:call-template name=
"id.warning"/>
210 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
211 <xsl:call-template name=
"dir">
212 <xsl:with-param name=
"inherit" select=
"1"/>
214 <xsl:call-template name=
"language.attribute"/>
217 <xsl:when test=
"@renderas = 'sect1'">
218 <xsl:call-template name=
"sect1.titlepage"/>
220 <xsl:when test=
"@renderas = 'sect2'">
221 <xsl:call-template name=
"sect2.titlepage"/>
223 <xsl:when test=
"@renderas = 'sect4'">
224 <xsl:call-template name=
"sect4.titlepage"/>
226 <xsl:when test=
"@renderas = 'sect5'">
227 <xsl:call-template name=
"sect5.titlepage"/>
230 <xsl:call-template name=
"sect3.titlepage"/>
234 <xsl:variable name=
"toc.params">
235 <xsl:call-template name=
"find.path.params">
236 <xsl:with-param name=
"table" select=
"normalize-space($generate.toc)"/>
240 <xsl:if test=
"contains($toc.params, 'toc')
241 and $generate.section.toc.level >= 3">
242 <xsl:call-template name=
"section.toc">
243 <xsl:with-param name=
"toc.title.p" select=
"contains($toc.params, 'title')"/>
245 <xsl:call-template name=
"section.toc.separator"/>
247 <xsl:apply-templates/>
248 <xsl:call-template name=
"process.chunk.footnotes"/>
252 <xsl:template match=
"sect3/title
255 mode=
"titlepage.mode" priority=
"2">
256 <xsl:call-template name=
"section.title"/>
259 <xsl:template match=
"sect4">
260 <xsl:call-template name=
"id.warning"/>
263 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
264 <xsl:call-template name=
"dir">
265 <xsl:with-param name=
"inherit" select=
"1"/>
267 <xsl:call-template name=
"language.attribute"/>
270 <xsl:when test=
"@renderas = 'sect1'">
271 <xsl:call-template name=
"sect1.titlepage"/>
273 <xsl:when test=
"@renderas = 'sect2'">
274 <xsl:call-template name=
"sect2.titlepage"/>
276 <xsl:when test=
"@renderas = 'sect3'">
277 <xsl:call-template name=
"sect3.titlepage"/>
279 <xsl:when test=
"@renderas = 'sect5'">
280 <xsl:call-template name=
"sect5.titlepage"/>
283 <xsl:call-template name=
"sect4.titlepage"/>
287 <xsl:variable name=
"toc.params">
288 <xsl:call-template name=
"find.path.params">
289 <xsl:with-param name=
"table" select=
"normalize-space($generate.toc)"/>
293 <xsl:if test=
"contains($toc.params, 'toc')
294 and $generate.section.toc.level >= 4">
295 <xsl:call-template name=
"section.toc">
296 <xsl:with-param name=
"toc.title.p" select=
"contains($toc.params, 'title')"/>
298 <xsl:call-template name=
"section.toc.separator"/>
300 <xsl:apply-templates/>
301 <xsl:call-template name=
"process.chunk.footnotes"/>
305 <xsl:template match=
"sect4/title
308 mode=
"titlepage.mode" priority=
"2">
309 <xsl:call-template name=
"section.title"/>
312 <xsl:template match=
"sect5">
313 <xsl:call-template name=
"id.warning"/>
316 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
317 <xsl:call-template name=
"dir">
318 <xsl:with-param name=
"inherit" select=
"1"/>
320 <xsl:call-template name=
"language.attribute"/>
323 <xsl:when test=
"@renderas = 'sect1'">
324 <xsl:call-template name=
"sect1.titlepage"/>
326 <xsl:when test=
"@renderas = 'sect2'">
327 <xsl:call-template name=
"sect2.titlepage"/>
329 <xsl:when test=
"@renderas = 'sect3'">
330 <xsl:call-template name=
"sect3.titlepage"/>
332 <xsl:when test=
"@renderas = 'sect4'">
333 <xsl:call-template name=
"sect4.titlepage"/>
336 <xsl:call-template name=
"sect5.titlepage"/>
340 <xsl:variable name=
"toc.params">
341 <xsl:call-template name=
"find.path.params">
342 <xsl:with-param name=
"table" select=
"normalize-space($generate.toc)"/>
346 <xsl:if test=
"contains($toc.params, 'toc')
347 and $generate.section.toc.level >= 5">
348 <xsl:call-template name=
"section.toc">
349 <xsl:with-param name=
"toc.title.p" select=
"contains($toc.params, 'title')"/>
351 <xsl:call-template name=
"section.toc.separator"/>
353 <xsl:apply-templates/>
354 <xsl:call-template name=
"process.chunk.footnotes"/>
358 <xsl:template match=
"sect5/title
361 mode=
"titlepage.mode" priority=
"2">
362 <xsl:call-template name=
"section.title"/>
365 <xsl:template match=
"simplesect">
366 <xsl:call-template name=
"id.warning"/>
369 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
370 <xsl:call-template name=
"dir">
371 <xsl:with-param name=
"inherit" select=
"1"/>
373 <xsl:call-template name=
"language.attribute"/>
374 <xsl:call-template name=
"simplesect.titlepage"/>
375 <xsl:apply-templates/>
379 <xsl:template match=
"simplesect/title|simplesect/info/title"
380 mode=
"titlepage.mode" priority=
"2">
381 <xsl:call-template name=
"section.title"/>
384 <xsl:template match=
"section/title"></xsl:template>
385 <xsl:template match=
"section/titleabbrev"></xsl:template>
386 <xsl:template match=
"section/subtitle"></xsl:template>
387 <xsl:template match=
"sectioninfo"></xsl:template>
388 <xsl:template match=
"section/info"></xsl:template>
390 <xsl:template match=
"sect1/title"></xsl:template>
391 <xsl:template match=
"sect1/titleabbrev"></xsl:template>
392 <xsl:template match=
"sect1/subtitle"></xsl:template>
393 <xsl:template match=
"sect1info"></xsl:template>
394 <xsl:template match=
"sect1/info"></xsl:template>
396 <xsl:template match=
"sect2/title"></xsl:template>
397 <xsl:template match=
"sect2/subtitle"></xsl:template>
398 <xsl:template match=
"sect2/titleabbrev"></xsl:template>
399 <xsl:template match=
"sect2info"></xsl:template>
400 <xsl:template match=
"sect2/info"></xsl:template>
402 <xsl:template match=
"sect3/title"></xsl:template>
403 <xsl:template match=
"sect3/subtitle"></xsl:template>
404 <xsl:template match=
"sect3/titleabbrev"></xsl:template>
405 <xsl:template match=
"sect3info"></xsl:template>
406 <xsl:template match=
"sect3/info"></xsl:template>
408 <xsl:template match=
"sect4/title"></xsl:template>
409 <xsl:template match=
"sect4/subtitle"></xsl:template>
410 <xsl:template match=
"sect4/titleabbrev"></xsl:template>
411 <xsl:template match=
"sect4info"></xsl:template>
412 <xsl:template match=
"sect4/info"></xsl:template>
414 <xsl:template match=
"sect5/title"></xsl:template>
415 <xsl:template match=
"sect5/subtitle"></xsl:template>
416 <xsl:template match=
"sect5/titleabbrev"></xsl:template>
417 <xsl:template match=
"sect5info"></xsl:template>
418 <xsl:template match=
"sect5/info"></xsl:template>
420 <xsl:template match=
"simplesect/title"></xsl:template>
421 <xsl:template match=
"simplesect/subtitle"></xsl:template>
422 <xsl:template match=
"simplesect/titleabbrev"></xsl:template>
423 <xsl:template match=
"simplesect/info"></xsl:template>
425 <!-- ==================================================================== -->
427 <xsl:template name=
"section.heading">
428 <xsl:param name=
"section" select=
"."/>
429 <xsl:param name=
"level" select=
"1"/>
430 <xsl:param name=
"allow-anchors" select=
"1"/>
431 <xsl:param name=
"title"/>
432 <xsl:param name=
"class" select=
"'title'"/>
434 <xsl:variable name=
"id">
436 <!-- if title is in an *info wrapper, get the grandparent -->
437 <xsl:when test=
"contains(local-name(..), 'info')">
438 <xsl:call-template name=
"object.id">
439 <xsl:with-param name=
"object" select=
"../.."/>
443 <xsl:call-template name=
"object.id">
444 <xsl:with-param name=
"object" select=
".."/>
450 <!-- HTML H level is one higher than section level -->
451 <xsl:variable name=
"hlevel">
453 <!-- highest valid HTML H level is H6; so anything nested deeper
454 than 5 levels down just becomes H6 -->
455 <xsl:when test=
"$level > 5">6</xsl:when>
457 <xsl:value-of select=
"$level + 1"/>
461 <xsl:element name=
"h{$hlevel}">
462 <xsl:attribute name=
"class"><xsl:value-of select=
"$class"/></xsl:attribute>
463 <xsl:if test=
"$css.decoration != '0'">
464 <xsl:if test=
"$hlevel<3">
465 <xsl:attribute name=
"style">clear: both
</xsl:attribute>
468 <xsl:if test=
"$allow-anchors != 0">
469 <xsl:call-template name=
"anchor">
470 <xsl:with-param name=
"node" select=
"$section"/>
471 <xsl:with-param name=
"conditional" select=
"0"/>
474 <xsl:copy-of select=
"$title"/>
478 <!-- ==================================================================== -->
480 <xsl:template match=
"bridgehead">
481 <xsl:variable name=
"container"
482 select=
"(ancestor::appendix
484 |ancestor::bibliography
501 |ancestor::simplesect)[last()]"/>
503 <xsl:variable name=
"clevel">
505 <xsl:when test=
"local-name($container) = 'appendix'
506 or local-name($container) = 'chapter'
507 or local-name($container) = 'article'
508 or local-name($container) = 'bibliography'
509 or local-name($container) = 'glossary'
510 or local-name($container) = 'index'
511 or local-name($container) = 'partintro'
512 or local-name($container) = 'preface'
513 or local-name($container) = 'setindex'">1</xsl:when>
514 <xsl:when test=
"local-name($container) = 'glossdiv'">
515 <xsl:value-of select=
"count(ancestor::glossdiv)+1"/>
517 <xsl:when test=
"local-name($container) = 'sect1'
518 or local-name($container) = 'sect2'
519 or local-name($container) = 'sect3'
520 or local-name($container) = 'sect4'
521 or local-name($container) = 'sect5'
522 or local-name($container) = 'refsect1'
523 or local-name($container) = 'refsect2'
524 or local-name($container) = 'refsect3'
525 or local-name($container) = 'section'
526 or local-name($container) = 'simplesect'">
527 <xsl:variable name=
"slevel">
528 <xsl:call-template name=
"section.level">
529 <xsl:with-param name=
"node" select=
"$container"/>
532 <xsl:value-of select=
"$slevel + 1"/>
534 <xsl:otherwise>1</xsl:otherwise>
538 <!-- HTML H level is one higher than section level -->
539 <xsl:variable name=
"hlevel">
541 <xsl:when test=
"@renderas = 'sect1'">2</xsl:when>
542 <xsl:when test=
"@renderas = 'sect2'">3</xsl:when>
543 <xsl:when test=
"@renderas = 'sect3'">4</xsl:when>
544 <xsl:when test=
"@renderas = 'sect4'">5</xsl:when>
545 <xsl:when test=
"@renderas = 'sect5'">6</xsl:when>
547 <xsl:value-of select=
"$clevel + 1"/>
552 <xsl:element name=
"h{$hlevel}">
553 <xsl:call-template name=
"anchor">
554 <xsl:with-param name=
"conditional" select=
"0"/>
556 <xsl:apply-templates/>
560 <xsl:template match=
"section/subtitle" mode=
"titlepage.mode" priority=
"2">
561 <xsl:call-template name=
"section.subtitle"/>
564 <xsl:template match=
"simplesect/subtitle" mode=
"titlepage.mode" priority=
"2">
565 <xsl:call-template name=
"section.subtitle"/>
568 <xsl:template match=
"sect1/subtitle" mode=
"titlepage.mode" priority=
"2">
569 <xsl:call-template name=
"section.subtitle"/>
572 <xsl:template match=
"sect2/subtitle" mode=
"titlepage.mode" priority=
"2">
573 <xsl:call-template name=
"section.subtitle"/>
576 <xsl:template match=
"sect3/subtitle" mode=
"titlepage.mode" priority=
"2">
577 <xsl:call-template name=
"section.subtitle"/>
580 <xsl:template match=
"sect4/subtitle" mode=
"titlepage.mode" priority=
"2">
581 <xsl:call-template name=
"section.subtitle"/>
584 <xsl:template match=
"sect5/subtitle" mode=
"titlepage.mode" priority=
"2">
585 <xsl:call-template name=
"section.subtitle"/>
588 <xsl:template name=
"section.subtitle">
589 <!-- the context node should be the subtitle of a section when called -->
590 <xsl:variable name=
"section" select=
"(ancestor::section
591 |ancestor::simplesect
596 |ancestor::sect5)[last()]"/>
598 <xsl:variable name=
"level">
599 <xsl:call-template name=
"section.level">
600 <xsl:with-param name=
"node" select=
"$section"/>
604 <xsl:call-template name=
"section.heading">
605 <xsl:with-param name=
"section" select=
".."/>
606 <xsl:with-param name=
"allow-anchors" select=
"0"/>
607 <!-- subtitle heading level one higher than section level -->
608 <xsl:with-param name=
"level" select=
"$level + 1"/>
609 <xsl:with-param name=
"class" select=
"'subtitle'"/>
610 <xsl:with-param name=
"title">
611 <xsl:apply-templates select=
"$section" mode=
"object.subtitle.markup">
612 <xsl:with-param name=
"allow-anchors" select=
"0"/>
613 </xsl:apply-templates>