xml - Copy node and alter its content -
i'm kinda stuck on transformation i'd make on xml file.
basically i'm trying copy xml change tags begins
xml code :
<test alt="foo" title="bar"/>
what i'd after passing xsl :
<test alt="foo"/>
or
<change alt="foo" title=""/>
thing is, got tag lot of attributes, dont want make template match , change every attributes manually.
actually i'm doing :
<xsl:template match="test"> <change><xsl:apply-templates select="@*|node()"/></change> </xsl:template> <xsl:template match="test/@title"> <xsl:attribute name="title"> <xsl:value-of select=""/> </xsl:attribute> </xsl:template>
but doesnt change content of title in output.
for such tasks should start identity transformation template
<xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template>
and add templates nodes need special treatment, instance
<xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="test/@title"/>
would copy unchanged delete title
attributes of test
elements.
or
<xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="test"> <change><xsl:apply-templates select="@*|node()"/></change> </xsl:template> <xsl:template match="test/@title"> <xsl:attribute name="title"/> </xsl:template>
should implement second requirement. if still have problems post minimal complete samples allowing reproduce problem.
Comments
Post a Comment