tools/boostbook/xsl/sections.xsl
<!-- Copyright (c) 2022 Evan Lenz <evan@lenzconsulting.com> Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <!-- This addresses a bug in the DocBook stylesheets that causes <h7> or <h8> to appear in the output; it forces such headings to be <h6> (the highest valid heading element in HTML). The rule below is copied verbatim from DocBook's html/sections.xsl with the exception of the called-out part below. --> <xsl:template match="bridgehead"> <xsl:variable name="container" select="(ancestor::appendix |ancestor::article |ancestor::bibliography |ancestor::chapter |ancestor::glossary |ancestor::glossdiv |ancestor::index |ancestor::partintro |ancestor::preface |ancestor::refsect1 |ancestor::refsect2 |ancestor::refsect3 |ancestor::sect1 |ancestor::sect2 |ancestor::sect3 |ancestor::sect4 |ancestor::sect5 |ancestor::section |ancestor::setindex |ancestor::simplesect)[last()]"/> <xsl:variable name="clevel"> <xsl:choose> <xsl:when test="local-name($container) = 'appendix' or local-name($container) = 'chapter' or local-name($container) = 'article' or local-name($container) = 'bibliography' or local-name($container) = 'glossary' or local-name($container) = 'index' or local-name($container) = 'partintro' or local-name($container) = 'preface' or local-name($container) = 'setindex'">1</xsl:when> <xsl:when test="local-name($container) = 'glossdiv'"> <xsl:value-of select="count(ancestor::glossdiv)+1"/> </xsl:when> <xsl:when test="local-name($container) = 'sect1' or local-name($container) = 'sect2' or local-name($container) = 'sect3' or local-name($container) = 'sect4' or local-name($container) = 'sect5' or local-name($container) = 'refsect1' or local-name($container) = 'refsect2' or local-name($container) = 'refsect3' or local-name($container) = 'section' or local-name($container) = 'simplesect'"> <xsl:variable name="slevel"> <xsl:call-template name="section.level"> <xsl:with-param name="node" select="$container"/> </xsl:call-template> </xsl:variable> <xsl:value-of select="$slevel + 1"/> </xsl:when> <xsl:otherwise>1</xsl:otherwise> </xsl:choose> </xsl:variable> <!-- HTML H level is one higher than section level --> <xsl:variable name="hlevel"> <xsl:choose> <xsl:when test="@renderas = 'sect1'">2</xsl:when> <xsl:when test="@renderas = 'sect2'">3</xsl:when> <xsl:when test="@renderas = 'sect3'">4</xsl:when> <xsl:when test="@renderas = 'sect4'">5</xsl:when> <xsl:when test="@renderas = 'sect5'">6</xsl:when> <xsl:otherwise> <!-- ====================================================== --> <!-- == START: BoostBook-specific fix ===================== --> <!-- ====================================================== --> <xsl:choose> <xsl:when test="$clevel >= 6">6</xsl:when> <xsl:otherwise> <xsl:value-of select="$clevel + 1"/> </xsl:otherwise> </xsl:choose> <!-- <xsl:value-of select="$clevel + 1"/> --> <!-- ====================================================== --> <!-- == END: BoostBook-specific fix ======================= --> <!-- ====================================================== --> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:element name="h{$hlevel}"> <xsl:call-template name="id.attribute"> <xsl:with-param name="conditional" select="0"/> </xsl:call-template> <xsl:call-template name="anchor"> <xsl:with-param name="conditional" select="0"/> </xsl:call-template> <xsl:apply-templates/> </xsl:element> </xsl:template> </xsl:stylesheet>