Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - copying a node into a variable, but changing one attribute value >Thread Next - Re: copying a node into a variable, but changing one attribute value Re: copying a node into a variable, but changing one attribute valueTo: NULL Date: 8/15/2008 1:27:00 PM
John.Frazzini@g... wrote:
> Please excuse the noob kind of question. I've been trying to select a
> node into a variable, but I want to change the value of one of the
> attributes somewhere within the node. For example, if I have the
> following node:
>
> <P id="3">
> <As>
> <a value="4" />
> </As>
> <N value="1">
> <S>
> <sA name="foo" />
> </S>
> <T value="X." />
> </N>
> </P>
>
> I'm trying to copy P as-is except I want to change the value attribute
> of T to a substring (e.g., substring-before(.,'.')).
Start with the identity transformation template, then add a template for
T/@value. The following sample then also creates a variable of the
transformed P element as you seemed to want to do that too:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="T/@value">
<xsl:attribute name="{name()}">
<xsl:value-of select="substring-before(., '.')"/>
</xsl:attribute>
</xsl:template>
<xsl:template match="/">
<xsl:variable name="foo">
<xsl:apply-templates select="P"/>
</xsl:variable>
<xsl:copy-of select="$foo"/>
</xsl:template>
</xsl:stylesheet>
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
