How to Rename xml elements and use the new names in the same XSL styleSheet?

Tags: xslt xslt-2.0
By : sofr

I have a xsl file for html output. the xsl handles an old format of xml whixh I want to renew now. Therefore I need to rename the old elements names to the new names I'm using the new names in the following xsl code. How can I do this? I tried

<xsl:template match="OldName">
<NewName><xsl:value-of select="."/></NewName>
<xsl:template match="/">
some code... </xsl:template>

and then I tried to access

<xsl:value-of select="NewName"/>

but got nothing while when using the OldName I got the value

By : sofr

If you're using XSLT2, you can use a two-phase transformation.

<xsl:value-of select="NewName"/> looks at the input, not the output. And in the input, there is no NewName. To make use of the NewName, you would have to parse it twice; once renewing the names, and once doing formatting.

By : Eric

This video can help you solving your question :)
By: admin