[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] XSL stylesheet issue - part 2 (newbie)
Many, many thanks, Martin. Now the TOC is created (almost) as expected. I understand that the logical error was to test for IDs which are not available in the input file because they were generated by the transformation. There is still one issue. The "level" variable seems to remain empty. It is supposed to be a number which indicates the nesting level of the heading and should become part of the value of the "class" attribute of the TOC headings. -----UrsprC<ngliche Nachricht----- Von: Martin Honnen martin.honnen@xxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Gesendet: Dienstag, 22. Oktober 2024 08:42 An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Betreff: Re: XSL stylesheet issue - part 2 (newbie) 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 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xpath-default-namespace="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" version="3.0"> <!-- Output settings for XHTML --> <xsl:output method="xhtml" encoding="UTF-8" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" indent="yes"/> <xsl:mode on-no-match="shallow-copy"/> <xsl:mode name="step2" on-no-match="shallow-copy"/> <xsl:variable name="intermediary-result1"> <xsl:apply-templates/> </xsl:variable> <xsl:template match="/"> <xsl:apply-templates select="$intermediary-result1" mode="step2"/> </xsl:template> <!-- Adding a unique ID attribute using generate-id() to headings to create hyperlink targets for the TOC --> <xsl:template match="*[@id='rn_release_notes']//h2 | *[@id='rn_release_notes']//h3 | *[@id='rn_release_notes']//p[@class='rn_heading']"> <xsl:copy> <!-- Generating a unique ID for each element --> <xsl:attribute name="id"> <xsl:text>tocref-</xsl:text> <xsl:value-of select="generate-id()"/> </xsl:attribute> <!-- Copy the remaining attributes except "id", and apply templates to children --> <xsl:apply-templates select="@*[name() != 'id']"/> <xsl:apply-templates select="node()"/> </xsl:copy> </xsl:template> <!-- Template to generate the TOC --> <xsl:template mode="step2" match="div[@id='rn_toc']"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:apply-templates select="h1"/> <!-- Insert the TOC after the <h1> element --> <xsl:for-each select="//*[@id[starts-with(., 'tocref')]]"> <xsl:variable name="level"> <xsl:choose> <xsl:when test="self::h2">1</xsl:when> <xsl:when test="self::h3">2</xsl:when> <xsl:when test="self::p[@class='rn_heading']">3</xsl:when> </xsl:choose> </xsl:variable> <p class="toclev{level}"> <a href="#{./@id}"> <xsl:value-of select="."/> </a> </p> </xsl:for-each> </xsl:copy> </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.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|