Replacing Namespace using xslt not producing expected result
I wish to replace the namespace v1 in the following xml from
http://choby.co.xx/DialogueServices/AM/V1 to http://choby.co.xx/XYZ/WM/V1
Input
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v1="http://choby.co.xx/DialogueServices/AM/V1">
<soapenv:Header/>
<soapenv:Body>
<v1:CancelAppointmentRequest>
<Loc>1</Loc>
</v1:CancelAppointmentRequest>
</soapenv:Body>
</soapenv:Envelope>
Expected:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v1="http://choby.co.xx/XYZ/WM/V1">
<soapenv:Header/>
<soapenv:Body>
<v1:CancelAppointmentRequest>
<Loc>1</Loc>
</v1:CancelAppointmentRequest>
</soapenv:Body>
</soapenv:Envelope>
xslt used:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="http://choby.co.xx/XYZ/WM/V1"
xmlns:ns1old="http://choby.co.xx/DialogueServices/AM/V1">
<xsl:output omit-xml-declaration="no" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="/*">
<xsl:element name="soapenv:{local-name()}"
namespace="http://www.w3.org/2003/05/soap-envelope">
<xsl:apply-templates select="node()|@*" />
</xsl:element>
</xsl:template>
<xsl:template match="ns1old:*">
<xsl:element name="ns1:{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Result:
<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"/>
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<ns1:CancelAppointmentRequest xmlns:ns1="http://choby.co.xx/XYZ/WM/V1">
<Loc>1</Loc>
</ns1:CancelAppointmentRequest>
</soapenv:Body>
</soapenv:Envelope>
The Header and Body namespace is different from Envelope
No comments:
Post a Comment