Subject: Re: [xsl] Reassinging attribute values From: David Carlisle <davidc@xxxxxxxxx> Date: Wed, 11 Jan 2006 13:32:53 GMT |
> 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Reassinging attribute val, Michael Kay | Thread | [xsl] Namespace problem : Supress a, jaya vardhani |
RE: [xsl] Reassinging attribute val, Michael Kay | Date | [xsl] Namespace problem : Supress a, jaya vardhani |
Month |