![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: copying a node into a variable, but changing one attribute value [Thread Next] Re: copying a node into a variable, but changing one attribute valueTo: NULL Date: 8/15/2008 3:13:00 PM On Aug 15, 4:26=A0am, Martin Honnen <mahotr...@yahoo.de> wrote:
> John.Frazz...@gmail.com 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=3D"3">
> > =A0 <As>
> > =A0 =A0 =A0<a value=3D"4" />
> > =A0 =A0</As>
> > =A0 <N value=3D"1">
> > =A0 =A0 <S>
> > =A0 =A0 =A0 =A0<sA name=3D"foo" />
> > =A0 =A0 </S>
> > =A0 =A0<T value=3D"X." />
> > =A0</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
> =A0 =A0xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"
> =A0 =A0version=3D"1.0">
>
> =A0 =A0<xsl:template match=3D"@* | node()">
> =A0 =A0 =A0<xsl:copy>
> =A0 =A0 =A0 =A0<xsl:apply-templates select=3D"@* | node()"/>
> =A0 =A0 =A0</xsl:copy>
> =A0 =A0</xsl:template>
>
> =A0 =A0<xsl:template match=3D"T/@value">
> =A0 =A0 =A0<xsl:attribute name=3D"{name()}">
> =A0 =A0 =A0 =A0<xsl:value-of select=3D"substring-before(., '.')"/>
> =A0 =A0 =A0</xsl:attribute>
> =A0 =A0</xsl:template>
>
> =A0 =A0<xsl:template match=3D"/">
> =A0 =A0 =A0<xsl:variable name=3D"foo">
> =A0 =A0 =A0 =A0<xsl:apply-templates select=3D"P"/>
> =A0 =A0 =A0</xsl:variable>
> =A0 =A0 =A0<xsl:copy-of select=3D"$foo"/>
> =A0 =A0</xsl:template>
>
> </xsl:stylesheet>
>
> --
>
> =A0 =A0 =A0 =A0 Martin Honnen --- MVP XML
> =A0 =A0 =A0 =A0http://JavaScript.FAQTs.com/- Hide quoted text -
>
> - Show quoted text -
Thanks Martin, I appreciate the help.
--John
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||
|
