I have the following XML document
<a:rootElement xmlns:a="http://a/1" xmlns:b="http://b/1" xmlns:c="http://c/1">
<child1 type="b:type"/>
<child2 type="c:type"/>
</a:rootElement>
Now I want to change the URIs of the namespaces so I get the following result
<a:rootElement xmlns:a="http://a/2" xmlns:b="http://b/2" xmlns:c="http://c/2">
<child1 type="b:type"/>
<child2 type="c:type"/>
</a:rootElement>
Nothing else should change. I tried it with the following stylesheet.
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:a="http://a/2"
xmlns:b="http://b/2"
xmlns:c="http://c/2" >
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="/*">
<xsl:element name="{name()}" namespace="{namespace-uri()}">
<xsl:copy-of select="document('')/*/namespace::*[name()='a']"/>
<xsl:copy-of select="document('')/*/namespace::*[name()='b']"/>
<xsl:copy-of select="document('')/*/namespace::*[name()='c']"/>
<xsl:copy-of select="node()|@*"/>
</xsl:element>
</xsl:template>
I get the following wrong output.
<a_0:rootElement xmlns:a_0="http://a/1" xmlns:a="http://a/2" xmlns:b="http://b/2" xmlns:c="http://c/2">
<child1 type="b:type" xmlns:a="http://a/1" xmlns:b="http://b/1" xmlns:c="http://c/1"/>
<child2 type="c:type" xmlns:a="http://a/1" xmlns:b="http://b/1" xmlns:c="http://c/1"/>
</a_0:rootElement>
I tried a few other ways too but also without the desired output. Is it even possible to change the namespaces in this way with XSLT?
Thanks for any advice