This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Copying node but changing attributes
- To: xsl-list at mulberrytech dot com
- Subject: Re: Copying node but changing attributes
- From: David Carlisle <davidc at nag dot co dot uk>
- Date: Fri, 29 Sep 2000 16:35:46 GMT
- References: <200009290950578.SM00229@mail.econovo.com>
- Reply-To: xsl-list at mulberrytech dot com
well, you've done 99% of the work, the only thing to
do is fill in <!-- DO SOMETHING WITH ATTR -->
(and take out xsl:copy)
but hard to say as you haven't said how you want to change the
attribute.
For example
<xsl:template match="node">
<xsl:copy>
<xsl:copy-of"@*[not(name()='x' or name()='y')]">
<xsl:attribute name="xxx">
<xsl:value-of select="@y"/>
</xsl:attribute>
<xsl:attribute name="yyy">
I was here
</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
copies any attribute not called x or y, makes a new attribute xxx with
the data from the old y attribute, makes a new attribute yyy
and doesn't use the old x attribute at all.
or perhaps
<xsl:template match="node">
<xsl:copy>
<xsl:for-each select="@*">
<xsl:attribute name="new-{name()}">
<xsl:text>modified from </xsl:text>
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
which changes
<node a="1" b="2">
to
<node new-a="modified from 1" new-b="modified from 2">
or at least I hope it does, haven't checked:-)
David
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list