[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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.
|
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
|