2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5 <!-- ********************************************************************
6 $Id: sections.xsl 8421 2009-05-04 07:49:49Z bobstayton $
7 ********************************************************************
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.
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:call-template name="common.html.attributes">
24 <xsl:with-param name="inherit" select="1"/>
26 <xsl:call-template name="section.titlepage"/>
28 <xsl:variable name="toc.params">
29 <xsl:call-template name="find.path.params">
30 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
34 <xsl:if test="contains($toc.params, 'toc')
35 and $depth <= $generate.section.toc.level">
36 <xsl:call-template name="section.toc">
37 <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
39 <xsl:call-template name="section.toc.separator"/>
41 <xsl:apply-templates/>
42 <xsl:call-template name="process.chunk.footnotes"/>
46 <xsl:template name="section.title">
47 <!-- the context node should be the title of a section when called -->
48 <xsl:variable name="section" select="(ancestor::section
54 |ancestor::sect5)[last()]"/>
56 <xsl:variable name="renderas">
58 <xsl:when test="$section/@renderas = 'sect1'">1</xsl:when>
59 <xsl:when test="$section/@renderas = 'sect2'">2</xsl:when>
60 <xsl:when test="$section/@renderas = 'sect3'">3</xsl:when>
61 <xsl:when test="$section/@renderas = 'sect4'">4</xsl:when>
62 <xsl:when test="$section/@renderas = 'sect5'">5</xsl:when>
63 <xsl:otherwise><xsl:value-of select="''"/></xsl:otherwise>
67 <xsl:variable name="level">
69 <xsl:when test="$renderas != ''">
70 <xsl:value-of select="$renderas"/>
73 <xsl:call-template name="section.level">
74 <xsl:with-param name="node" select="$section"/>
80 <xsl:call-template name="section.heading">
81 <xsl:with-param name="section" select="$section"/>
82 <xsl:with-param name="level" select="$level"/>
83 <xsl:with-param name="title">
84 <xsl:apply-templates select="$section" mode="object.title.markup">
85 <xsl:with-param name="allow-anchors" select="1"/>
86 </xsl:apply-templates>
91 <xsl:template match="section/title
94 mode="titlepage.mode" priority="2">
95 <xsl:call-template name="section.title"/>
98 <xsl:template match="sect1">
99 <xsl:call-template name="id.warning"/>
102 <xsl:call-template name="common.html.attributes">
103 <xsl:with-param name="inherit" select="1"/>
107 <xsl:when test="@renderas = 'sect2'">
108 <xsl:call-template name="sect2.titlepage"/>
110 <xsl:when test="@renderas = 'sect3'">
111 <xsl:call-template name="sect3.titlepage"/>
113 <xsl:when test="@renderas = 'sect4'">
114 <xsl:call-template name="sect4.titlepage"/>
116 <xsl:when test="@renderas = 'sect5'">
117 <xsl:call-template name="sect5.titlepage"/>
120 <xsl:call-template name="sect1.titlepage"/>
124 <xsl:variable name="toc.params">
125 <xsl:call-template name="find.path.params">
126 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
130 <xsl:if test="contains($toc.params, 'toc')
131 and $generate.section.toc.level >= 1">
132 <xsl:call-template name="section.toc">
133 <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
135 <xsl:call-template name="section.toc.separator"/>
137 <xsl:apply-templates/>
138 <xsl:call-template name="process.chunk.footnotes"/>
142 <xsl:template match="sect1/title
145 mode="titlepage.mode" priority="2">
146 <xsl:call-template name="section.title"/>
149 <xsl:template match="sect2">
150 <xsl:call-template name="id.warning"/>
153 <xsl:call-template name="common.html.attributes">
154 <xsl:with-param name="inherit" select="1"/>
158 <xsl:when test="@renderas = 'sect1'">
159 <xsl:call-template name="sect1.titlepage"/>
161 <xsl:when test="@renderas = 'sect3'">
162 <xsl:call-template name="sect3.titlepage"/>
164 <xsl:when test="@renderas = 'sect4'">
165 <xsl:call-template name="sect4.titlepage"/>
167 <xsl:when test="@renderas = 'sect5'">
168 <xsl:call-template name="sect5.titlepage"/>
171 <xsl:call-template name="sect2.titlepage"/>
175 <xsl:variable name="toc.params">
176 <xsl:call-template name="find.path.params">
177 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
181 <xsl:if test="contains($toc.params, 'toc')
182 and $generate.section.toc.level >= 2">
183 <xsl:call-template name="section.toc">
184 <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
186 <xsl:call-template name="section.toc.separator"/>
188 <xsl:apply-templates/>
189 <xsl:call-template name="process.chunk.footnotes"/>
193 <xsl:template match="sect2/title
196 mode="titlepage.mode" priority="2">
197 <xsl:call-template name="section.title"/>
200 <xsl:template match="sect3">
201 <xsl:call-template name="id.warning"/>
204 <xsl:call-template name="common.html.attributes">
205 <xsl:with-param name="inherit" select="1"/>
209 <xsl:when test="@renderas = 'sect1'">
210 <xsl:call-template name="sect1.titlepage"/>
212 <xsl:when test="@renderas = 'sect2'">
213 <xsl:call-template name="sect2.titlepage"/>
215 <xsl:when test="@renderas = 'sect4'">
216 <xsl:call-template name="sect4.titlepage"/>
218 <xsl:when test="@renderas = 'sect5'">
219 <xsl:call-template name="sect5.titlepage"/>
222 <xsl:call-template name="sect3.titlepage"/>
226 <xsl:variable name="toc.params">
227 <xsl:call-template name="find.path.params">
228 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
232 <xsl:if test="contains($toc.params, 'toc')
233 and $generate.section.toc.level >= 3">
234 <xsl:call-template name="section.toc">
235 <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
237 <xsl:call-template name="section.toc.separator"/>
239 <xsl:apply-templates/>
240 <xsl:call-template name="process.chunk.footnotes"/>
244 <xsl:template match="sect3/title
247 mode="titlepage.mode" priority="2">
248 <xsl:call-template name="section.title"/>
251 <xsl:template match="sect4">
252 <xsl:call-template name="id.warning"/>
255 <xsl:call-template name="common.html.attributes">
256 <xsl:with-param name="inherit" select="1"/>
260 <xsl:when test="@renderas = 'sect1'">
261 <xsl:call-template name="sect1.titlepage"/>
263 <xsl:when test="@renderas = 'sect2'">
264 <xsl:call-template name="sect2.titlepage"/>
266 <xsl:when test="@renderas = 'sect3'">
267 <xsl:call-template name="sect3.titlepage"/>
269 <xsl:when test="@renderas = 'sect5'">
270 <xsl:call-template name="sect5.titlepage"/>
273 <xsl:call-template name="sect4.titlepage"/>
277 <xsl:variable name="toc.params">
278 <xsl:call-template name="find.path.params">
279 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
283 <xsl:if test="contains($toc.params, 'toc')
284 and $generate.section.toc.level >= 4">
285 <xsl:call-template name="section.toc">
286 <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
288 <xsl:call-template name="section.toc.separator"/>
290 <xsl:apply-templates/>
291 <xsl:call-template name="process.chunk.footnotes"/>
295 <xsl:template match="sect4/title
298 mode="titlepage.mode" priority="2">
299 <xsl:call-template name="section.title"/>
302 <xsl:template match="sect5">
303 <xsl:call-template name="id.warning"/>
306 <xsl:call-template name="common.html.attributes">
307 <xsl:with-param name="inherit" select="1"/>
311 <xsl:when test="@renderas = 'sect1'">
312 <xsl:call-template name="sect1.titlepage"/>
314 <xsl:when test="@renderas = 'sect2'">
315 <xsl:call-template name="sect2.titlepage"/>
317 <xsl:when test="@renderas = 'sect3'">
318 <xsl:call-template name="sect3.titlepage"/>
320 <xsl:when test="@renderas = 'sect4'">
321 <xsl:call-template name="sect4.titlepage"/>
324 <xsl:call-template name="sect5.titlepage"/>
328 <xsl:variable name="toc.params">
329 <xsl:call-template name="find.path.params">
330 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
334 <xsl:if test="contains($toc.params, 'toc')
335 and $generate.section.toc.level >= 5">
336 <xsl:call-template name="section.toc">
337 <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
339 <xsl:call-template name="section.toc.separator"/>
341 <xsl:apply-templates/>
342 <xsl:call-template name="process.chunk.footnotes"/>
346 <xsl:template match="sect5/title
349 mode="titlepage.mode" priority="2">
350 <xsl:call-template name="section.title"/>
353 <xsl:template match="simplesect">
354 <xsl:call-template name="id.warning"/>
357 <xsl:call-template name="common.html.attributes">
358 <xsl:with-param name="inherit" select="1"/>
361 <xsl:call-template name="simplesect.titlepage"/>
362 <xsl:apply-templates/>
366 <xsl:template match="simplesect/title|simplesect/info/title"
367 mode="titlepage.mode" priority="2">
368 <xsl:call-template name="section.title"/>
371 <xsl:template match="section/title"></xsl:template>
372 <xsl:template match="section/titleabbrev"></xsl:template>
373 <xsl:template match="section/subtitle"></xsl:template>
374 <xsl:template match="sectioninfo"></xsl:template>
375 <xsl:template match="section/info"></xsl:template>
377 <xsl:template match="sect1/title"></xsl:template>
378 <xsl:template match="sect1/titleabbrev"></xsl:template>
379 <xsl:template match="sect1/subtitle"></xsl:template>
380 <xsl:template match="sect1info"></xsl:template>
381 <xsl:template match="sect1/info"></xsl:template>
383 <xsl:template match="sect2/title"></xsl:template>
384 <xsl:template match="sect2/subtitle"></xsl:template>
385 <xsl:template match="sect2/titleabbrev"></xsl:template>
386 <xsl:template match="sect2info"></xsl:template>
387 <xsl:template match="sect2/info"></xsl:template>
389 <xsl:template match="sect3/title"></xsl:template>
390 <xsl:template match="sect3/subtitle"></xsl:template>
391 <xsl:template match="sect3/titleabbrev"></xsl:template>
392 <xsl:template match="sect3info"></xsl:template>
393 <xsl:template match="sect3/info"></xsl:template>
395 <xsl:template match="sect4/title"></xsl:template>
396 <xsl:template match="sect4/subtitle"></xsl:template>
397 <xsl:template match="sect4/titleabbrev"></xsl:template>
398 <xsl:template match="sect4info"></xsl:template>
399 <xsl:template match="sect4/info"></xsl:template>
401 <xsl:template match="sect5/title"></xsl:template>
402 <xsl:template match="sect5/subtitle"></xsl:template>
403 <xsl:template match="sect5/titleabbrev"></xsl:template>
404 <xsl:template match="sect5info"></xsl:template>
405 <xsl:template match="sect5/info"></xsl:template>
407 <xsl:template match="simplesect/title"></xsl:template>
408 <xsl:template match="simplesect/subtitle"></xsl:template>
409 <xsl:template match="simplesect/titleabbrev"></xsl:template>
410 <xsl:template match="simplesect/info"></xsl:template>
412 <!-- ==================================================================== -->
414 <xsl:template name="section.heading">
415 <xsl:param name="section" select="."/>
416 <xsl:param name="level" select="1"/>
417 <xsl:param name="allow-anchors" select="1"/>
418 <xsl:param name="title"/>
419 <xsl:param name="class" select="'title'"/>
421 <xsl:variable name="id">
423 <!-- Make sure the subtitle doesn't get the same id as the title -->
424 <xsl:when test="self::subtitle">
425 <xsl:call-template name="object.id">
426 <xsl:with-param name="object" select="."/>
429 <!-- if title is in an *info wrapper, get the grandparent -->
430 <xsl:when test="contains(local-name(..), 'info')">
431 <xsl:call-template name="object.id">
432 <xsl:with-param name="object" select="../.."/>
436 <xsl:call-template name="object.id">
437 <xsl:with-param name="object" select=".."/>
443 <!-- HTML H level is one higher than section level -->
444 <xsl:variable name="hlevel">
446 <!-- highest valid HTML H level is H6; so anything nested deeper
447 than 5 levels down just becomes H6 -->
448 <xsl:when test="$level > 5">6</xsl:when>
450 <xsl:value-of select="$level + 1"/>
454 <xsl:element name="h{$hlevel}">
455 <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
456 <xsl:if test="$css.decoration != '0'">
457 <xsl:if test="$hlevel<3">
458 <xsl:attribute name="style">clear: both</xsl:attribute>
461 <xsl:if test="$allow-anchors != 0 and $generate.id.attributes = 0">
462 <xsl:call-template name="anchor">
463 <xsl:with-param name="node" select="$section"/>
464 <xsl:with-param name="conditional" select="0"/>
467 <xsl:if test="$generate.id.attributes != 0 and not(local-name(.) = 'appendix')">
468 <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
470 <xsl:copy-of select="$title"/>
474 <!-- ==================================================================== -->
476 <xsl:template match="bridgehead">
477 <xsl:variable name="container"
478 select="(ancestor::appendix
480 |ancestor::bibliography
497 |ancestor::simplesect)[last()]"/>
499 <xsl:variable name="clevel">
501 <xsl:when test="local-name($container) = 'appendix'
502 or local-name($container) = 'chapter'
503 or local-name($container) = 'article'
504 or local-name($container) = 'bibliography'
505 or local-name($container) = 'glossary'
506 or local-name($container) = 'index'
507 or local-name($container) = 'partintro'
508 or local-name($container) = 'preface'
509 or local-name($container) = 'setindex'">1</xsl:when>
510 <xsl:when test="local-name($container) = 'glossdiv'">
511 <xsl:value-of select="count(ancestor::glossdiv)+1"/>
513 <xsl:when test="local-name($container) = 'sect1'
514 or local-name($container) = 'sect2'
515 or local-name($container) = 'sect3'
516 or local-name($container) = 'sect4'
517 or local-name($container) = 'sect5'
518 or local-name($container) = 'refsect1'
519 or local-name($container) = 'refsect2'
520 or local-name($container) = 'refsect3'
521 or local-name($container) = 'section'
522 or local-name($container) = 'simplesect'">
523 <xsl:variable name="slevel">
524 <xsl:call-template name="section.level">
525 <xsl:with-param name="node" select="$container"/>
528 <xsl:value-of select="$slevel + 1"/>
530 <xsl:otherwise>1</xsl:otherwise>
534 <!-- HTML H level is one higher than section level -->
535 <xsl:variable name="hlevel">
537 <xsl:when test="@renderas = 'sect1'">2</xsl:when>
538 <xsl:when test="@renderas = 'sect2'">3</xsl:when>
539 <xsl:when test="@renderas = 'sect3'">4</xsl:when>
540 <xsl:when test="@renderas = 'sect4'">5</xsl:when>
541 <xsl:when test="@renderas = 'sect5'">6</xsl:when>
543 <xsl:value-of select="$clevel + 1"/>
548 <xsl:element name="h{$hlevel}">
549 <xsl:call-template name="anchor">
550 <xsl:with-param name="conditional" select="0"/>
552 <xsl:apply-templates/>
556 <xsl:template match="section/subtitle" mode="titlepage.mode" priority="2">
557 <xsl:call-template name="section.subtitle"/>
560 <xsl:template match="simplesect/subtitle" mode="titlepage.mode" priority="2">
561 <xsl:call-template name="section.subtitle"/>
564 <xsl:template match="sect1/subtitle" mode="titlepage.mode" priority="2">
565 <xsl:call-template name="section.subtitle"/>
568 <xsl:template match="sect2/subtitle" mode="titlepage.mode" priority="2">
569 <xsl:call-template name="section.subtitle"/>
572 <xsl:template match="sect3/subtitle" mode="titlepage.mode" priority="2">
573 <xsl:call-template name="section.subtitle"/>
576 <xsl:template match="sect4/subtitle" mode="titlepage.mode" priority="2">
577 <xsl:call-template name="section.subtitle"/>
580 <xsl:template match="sect5/subtitle" mode="titlepage.mode" priority="2">
581 <xsl:call-template name="section.subtitle"/>
584 <xsl:template name="section.subtitle">
585 <!-- the context node should be the subtitle of a section when called -->
586 <xsl:variable name="section" select="(ancestor::section
587 |ancestor::simplesect
592 |ancestor::sect5)[last()]"/>
594 <xsl:variable name="level">
595 <xsl:call-template name="section.level">
596 <xsl:with-param name="node" select="$section"/>
600 <xsl:call-template name="section.heading">
601 <xsl:with-param name="section" select=".."/>
602 <xsl:with-param name="allow-anchors" select="0"/>
603 <!-- subtitle heading level one higher than section level -->
604 <xsl:with-param name="level" select="$level + 1"/>
605 <xsl:with-param name="class" select="'subtitle'"/>
606 <xsl:with-param name="title">
607 <xsl:apply-templates select="$section" mode="object.subtitle.markup">
608 <xsl:with-param name="allow-anchors" select="0"/>
609 </xsl:apply-templates>