[xsl] Problem in replacing XML namespace using XSLT

Subject: [xsl] Problem in replacing XML namespace using XSLT
From: Krishna Gopal Binyala <kgbinyala@xxxxxxxxx>
Date: Thu, 17 Dec 2009 15:26:05 +0530
Hello,

I need to just replace the XML namespace using XSLT. My input XML
looks like as follows. I just want to replace "oldNameSpace" with
"newNameSpace" and rest of XML want as it is..

[CODE]<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/";
	xmlns:impl="oldNameSpace" xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
	<soapenv:Body>
		<impl:requestData
			xmlns:impl="oldNameSpace">
			<xmlString ChangeDate="2008-12-18T14:47:11.773+01:00"
				IdentificationNumber="WDDKJ5GBXAF000229"
				OrderNumber="08 295 70821"
				ProductionNumber="1700158">
				<ServiceTool ExecutionTime="2008-12-18T14:47:11.773+01:00"
					UserID="kris" Version="1.1.1" />
			</xmlString>
		</impl:requestData>
	</soapenv:Body>
</soapenv:Envelope>[/CODE]

I tried with following XSL

[CODE]<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
	xmlns:source="oldNameSpace" xmlns:desti="newNameSPace" xmlns="newNameSPace"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; version="2.0">
	<xsl:output method="xml" encoding="iso-8859-1" indent="yes" />


	<xsl:template match="source:*">
		<xsl:element name="{name()}" namespace="newNameSPace">
			<xsl:apply-templates select="@*|node()" />
		</xsl:element>
	</xsl:template>

	<xsl:template match="@*|node()">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()" />
		</xsl:copy>
	</xsl:template>
</xsl:stylesheet>[/CODE]

but it is not giving the desired results...it is giving the following results.

[CODE]
<?xml version="1.0" encoding="iso-8859-1"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/";
xmlns:impl="oldNameSpace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
	<soapenv:Body>
		<impl:requestData xmlns:impl="newNameSPace">
			<xmlString xmlns:impl="oldNameSpace"
ChangeDate="2008-12-18T14:47:11.773+01:00"
IdentificationNumber="WDDKJ5GBXAF000229" OrderNumber="08 295 70821"
ProductionNumber="1700158">
				<ServiceTool ExecutionTime="2008-12-18T14:47:11.773+01:00"
UserID="kris" Version="1.1.1"/>
			</xmlString>
		</impl:requestData>
	</soapenv:Body>
</soapenv:Envelope>

[/CODE]

problem with the above is that -- "<xmlString
xmlns:impl="oldNameSpace"  is still showing the "oldNameSpace" only..
where as there was no namespace for that element in the input

Anyone can help in this ....
Thanks a lot.

---Krishna

Current Thread