I have this xml:
<pos:getPositionRouter xmlns:pos="positionNS">
<positionID>
<code>1</code>
</positionID>
<parameter>?</parameter>
</pos:getPositionRouter>
and I want to rename the element pos:getPositionRouterin x:getPositionusing xslt:
<x:getPosition xmlns:x="newPositionNS">
<positionID>
<code>1</code>
</positionID>
<parameter>?</parameter>
</x:getPosition>
This is the sylesheet I came across:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />
<xsl:param name="old_namespace" />
<xsl:param name="old_element_localname" />
<xsl:param name="new_namespace" />
<xsl:param name="new_element_localname" />
<xsl:template match="@*|node()">
<xsl:choose>
<xsl:when test="(local-name() = $old_element_localname) and (namespace-uri() = $old_namespace)">
<xsl:element name="{$new_element_localname}" namespace="{$new_namespace}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
I have to use xalan as an xslt processor, and the output, unfortunately, is this:
<getPosition xmlns="newPositionNS">
<positionID xmlns:pos="positionNS">
<code>1</code>
</positionID>
<parameter xmlns:pos="positionNS">?</parameter>
</getPosition>
By default, the element namespace getPositionbecomes the new namespace, but the child elements must remain without the namespace ( xmlns="").
Can anyone understand why?
Thank!
Simon source
share