[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XSL stylesheet issue (newbie)

Subject: Re: XSL stylesheet issue (newbie)
From: "Dave Pawson dave.pawson@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 17 Oct 2024 18:01:30 -0000
Re:  XSL stylesheet issue (newbie)
Look up the generate-id function if you want a unique id value.
Perhaps prefix it with a constant if needed?

HTH

On Thu, 17 Oct 2024 at 18:21, Frank Dissinger frank.dissinger@xxxxxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> Hello everyone,
>
> The stylesheet below is supposed to add a unique 'id' attribute named
> 'tocref001', 'tocref002' etc. to all <h2>, <h3> and <p class="rn_heading">
> elements which are descendants of an element with an 'id' attribute named
> 'rn_release_notes'. The script runs without any errors, but does not add
> any IDs.
>
> I admit that I have little to no knowledge of XSLT. ChatGPT was my friend.
> But I have created a small HTML file and an XSL stylesheet with slightly
> simpler XPath expressions which works fine. But it does not work with a
> more complex HTML file. I have attached such a file to this message. A
> colleague who is a software developer tried to debug the stylesheet with
> Visual Studio, but without success.
>
> The purpose of this script, when finished, is to create a Table of
> Contents for an HTML file. The current state of it is only to add hyperlink
> targets to the relevant headings.
>
> Any help is greatly appreciated.
>
> -------------------------------------------------------
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
>
>   <!-- Output settings for HTML5 -->
>   <xsl:output method="html"
>               encoding="UTF-8"
>               indent="yes"/>
>
>   <!-- Identity template to copy all elements and attributes -->
>   <xsl:template match="node()|@*">
>     <xsl:copy>
>       <xsl:apply-templates select="node()|@*"/>
>     </xsl:copy>
>   </xsl:template>
>
> <!-- Adding id=toc001 attributes 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:variable name="id">
>        <xsl:number level="any" count="*[@id='rn_release_notes']//h2 |
> *[@id='rn_release_notes']//h3 |
> *[@id='rn_release_notes']//p[@class='rn_heading']" format="000"/>
>     </xsl:variable>
>
>    <xsl:copy>
>         <xsl:attribute name="id">tocref<xsl:value-of
> select="$id"/></xsl:attribute>
>         <xsl:apply-templates select="@*[name() != 'id']"/>
>         <xsl:apply-templates select="node()"/>
>     </xsl:copy>
>
> </xsl:template>
>
> </xsl:stylesheet>
> 
>


-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.