xml - Xslt copy element into renamed element -
i'm struggling xslt produce i'm after.
i have following xml
<data> <things> <name>a</name> </things> <other> <type>b</type> </other> </data>
and want output xml be
<data> <stuff> <name>a</name> <type>b</type> </stuff> </data>
i have following xslt far doesn't produce i'm after
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" > <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="node()|@*" name="identity"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="data/things"> <xsl:element name="stuff"> <xsl:apply-templates select="@*|node()"/> </xsl:element> </xsl:template> <xsl:template match="data/other"> <xsl:element name="stuff"> <xsl:apply-templates select="@*|node()"/> </xsl:element> </xsl:template> </xsl:stylesheet>
this simple appreciated
this simple
well, be:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/> <!-- identity transform --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="/data"> <xsl:copy> <stuff> <xsl:apply-templates select="*/*"/> </stuff> </xsl:copy> </xsl:template> </xsl:stylesheet>
or, if want explicit, make second template:
<xsl:template match="/data"> <xsl:copy> <stuff> <xsl:apply-templates select="things/name | other/type"/> </stuff> </xsl:copy> </xsl:template>
Comments
Post a Comment