Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: copying a node into a variable, but changing one attribute value

From: John.Frazzini@-----.---
To: 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


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent