Re: [xsl] XSL stylesheet issue - part 2 (newbie)

Subject: Re: [xsl] XSL stylesheet issue - part 2 (newbie)
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 22 Oct 2024 06:41:33 -0000
Frank, as Wendell pointed out, you seem to want two different processing
steps, if you want to do that in one XSLT stylesheet (instead of
chaining two) use modes


<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet B xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; B xpath-default-namespace="http://www.w3.org/1999/xhtml"; B xmlns="http://www.w3.org/1999/xhtml"; B version="3.0">

B  <!-- Output settings for XHTML -->
B  <xsl:output
B B B  method="xhtml"
B B B  encoding="UTF-8"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
B B B  indent="yes"/>

B <xsl:mode on-no-match="shallow-copy"/>

B <xsl:mode name="step2" on-no-match="shallow-copy"/>

B  <xsl:variable name="intermediary-result1">
B B B  <xsl:apply-templates/>
B  </xsl:variable>

B  <xsl:template match="/">
B B B  <xsl:apply-templates select="$intermediary-result1" mode="step2"/>
B  </xsl:template>

B  <!-- Adding a unique ID attribute using generate-id() to headings to
create hyperlink targets for the TOC -->
B  <xsl:template
B B B  match="*[@id='rn_release_notes']//h2 |
*[@id='rn_release_notes']//h3 |
*[@id='rn_release_notes']//p[@class='rn_heading']">
B B B  <xsl:copy>
B B B B B  <!-- Generating a unique ID for each element -->
B B B B B  <xsl:attribute name="id">
B B B B B B B  <xsl:text>tocref-</xsl:text>
B B B B B B B  <xsl:value-of select="generate-id()"/>
B B B B B  </xsl:attribute>
B B B B B  <!-- Copy the remaining attributes except "id", and apply
templates to children -->
B B B B B  <xsl:apply-templates select="@*[name() != 'id']"/>
B B B B B  <xsl:apply-templates select="node()"/>
B B B  </xsl:copy>
B  </xsl:template>

B  <!-- 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"/>

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>

</xsl:stylesheet>

On 22/10/2024 07:53, Frank Dissinger frank.dissinger@xxxxxxxxxxxx wrote:
Hi Wendell

Thank you for your reply. I have attached the input HTML file to this
message.

Current Thread