On 22/10/2024 08:41, Martin Honnen martin.honnen@xxxxxx wrote:
<!-- Template to generate the TOC -->
B <xsl:template mode="step2" match="div[@id='rn_toc']">
B B B <xsl:copy>
B B B B B <xsl:apply-templates select="@*"/>
B B B B B <xsl:apply-templates select="h1"/>
Note that for a clean approach I should have changed all the
apply-templates in templates for the mode named step2 to use e.g.
B B B B <xsl:apply-templates select="@*" mode="#current"/>
B B B B B <xsl:apply-templates select="h1" mode="#current"/>
but for the simple case of two modes doing shallow copying by default it
doesn't matter.
B B B B B <!-- Insert the TOC after the <h1> element -->
B B B B B <xsl:for-each select="//*[@id[starts-with(., 'tocref')]]">
B B B B B B B <xsl:variable name="level">
B B B B B B B B B <xsl:choose>
B B B B B B B B B B B <xsl:when test="self::h2">1</xsl:when>
B B B B B B B B B B B <xsl:when test="self::h3">2</xsl:when>
B B B B B B B B B B B <xsl:when
test="self::p[@class='rn_heading']">3</xsl:when>
B B B B B B B B B </xsl:choose>
B B B B B B B </xsl:variable>
B B B B B B B <p class="toclev{level}">
B B B B B B B B B <a href="#{./@id}">
B B B B B B B B B B B <xsl:value-of select="."/>
B B B B B B B B B </a>
B B B B B B B </p>
B B B B B </xsl:for-each>
B B B </xsl:copy>
B </xsl:template>
|