Reputation: 79
does anyone know how I can rename a tag using XSLT?
In my example I copy the tag "NUMBER" from "CONTACT/NUMBER" at the Tag "ADD" to "GRP". But now I also want the copied Tag "NUMBER" at "GRP" to be called "CONTACT_NUMBER" instead of "NUMBER".
<xsl:template match="GRP">
<xsl:copy>
<!--copy the data from ADD - CN to the GRP so it can be used in the mapping to set the delivery address from end customer-->
<xsl:for-each select ="./ADD">
<xsl:if test="./QUALIFIER='CN'">
<xsl:copy-of select="PARTY_NAME_1"/>
<xsl:copy-of select="STREET_1"/>
<xsl:copy-of select="CITY"/>
<xsl:copy-of select="POSTAL_CODE"/>
<xsl:copy-of select="COUNTRY_CODE"/>
<xsl:copy-of select="CONTACT/NUMBER"/>
</xsl:if>
</xsl:for-each>
<!--copy all other nodes-->
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
Result:
PARTY_NAME_1
STREET_1
... CONTACT_NUMBER (instead of "NUMBER")
Thanks, Julian
Upvotes: 0
Views: 54
Reputation: 29052
Change
<xsl:copy-of select="CONTACT/NUMBER"/>
to
<CONTACT_NUMBER>
<xsl:value-of select="CONTACT/NUMBER"/>
</CONTACT_NUMBER>
That should do the job.
Upvotes: 1