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

Re: Add id to next element

Subject: Re: Add id to next element
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 19 May 2022 18:47:49 -0000
Re:  Add id to next element
On Thu, May 19, 2022 at 05:53:58PM -0000, Eliot Kimber eliot.kimber@xxxxxxxxxxxxxx scripsit:
> The typical way to do it is to have the processing of the section element get
> the value from the preceding target element:
>
>   <xsl:template match="section">
>     <xsl:variable name="id" as="xs:string?"
>       select="preceding-sibling::target[1]/@refid"
>     />
>     <xsl:copy>
>         <xsl:attribute name="id"
>           select="if ($id) then $id else generate-id(.)"
>         />
>         <xsl:apply-templates mode="#current"/>
>     </xsl:copy>
>  </xsl:template>

What's wrong with

<xsl:template match="section">
    <xsl:copy>
    	<xsl:apply-templates select="@*" mode="#current" />
	<xsl:attribute name="id"
	  select="(preceding-sibling::*[1][self::target]/@refid,generate-id(.)) => head()" />
	<xsl:apply-templates mode="#current" />
    </xsl:copy>
</xsl:template>

I am assuming XSLT 3, here, but that should be a fairly safe assumption
these days.

-- 
Graydon Saunders  | graydonish@xxxxxxxxx
^fs oferiode, pisses swa mfg.
-- Deor  ("That passed, so may this.")

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.