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

Re: Reassinging attribute values

Subject: Re: Reassinging attribute values
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 11 Jan 2006 13:32:53 GMT
Re:  Reassinging attribute values
> So basically I am looking for a way to change an attribute value in
> the tree while I am processing the document. Is there any way to do
> this? 

XSLT never changes its input tree, the model is that the input is
read-only and you generate a new document.

The trick for arranging that generated ids and references to the
generated id use the same generated value is to generate the value at
the same place.

So suppose your source has 
<foo id="old"/>
...
<reference refid="old"/>

first have a template that makes new ids from old, assuming it is called
at the place that is referenced (<foo> here).

<xsl:template name="idmunger">
  <xsl:value-of select="generate-id()"/>
  <xsl:value-of select="count(ancestor::*)"/>
  <xsl:value-of select="substring(@id,1,2)"/>
</xsl:template>

(or whatever function you need) then call it twice:


<xsl:template match="foo">
 <newfoo>
  <xsl:attribute name="id">
    <xsl:call-template name="idmunger"/>
  </xsl:attribute>
  <xsl;apply-templates/>
 </newfoo>
</xsl:template>

and

<xsl:template match="reference">
<newreference>
 <xsl:for-each select="key('id',@idref)[1]">
  <xsl:attribute name="idref">
    <xsl:call-template name="idmunger"/>
  </xsl:attribute>
 </xsl:for-each>
</newreference>
</xsl:template>

together with

<xsl:key name="id" match="*" use="@id"/>


so this generates

<newfoo id="asjafha5ol"/> .... <newrefererence refid="asjafha5ol"/> with
the same generated value in both places as it is generated on the same
(foo) node in each case.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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.