<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<tns:send xmlns:tns="http://www.test.com/Service/v3">
<NS2:Message release="006" version="010" xmlns:NS2="http://www.ncpdp.org/schema/SCRIPT">
<NS2:Body>
<NS2:New>
<NS2:Pharmacy>
<NS2:Identification>
<NS2:ID>
<NS2:IDValue>01017</NS2:IDValue>
<NS2:IDQualifier>94</NS2:IDQualifier>
<NS2:IDRegion>SCA</NS2:IDRegion>
<NS2:IDState>CA</NS2:IDState>
</NS2:ID>
</NS2:Identification>
</NS2:Pharmacy>
</NS2:New>
</NS2:Body>
</NS2:Message>
</tns:send>
</soapenv:Body>
</soapenv:Envelope>
I have this xml which is on schema version 3.0 http://www.test.com/Service/v3 . I need to downgrade it to version 1 http://www.test.com/Service/v1. To do that i am using a XSL to transform it.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:booga="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://www.test.com/Service/v3"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:src="http://www.ncpdp.org/schema/SCRIPT"
>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="tns:*">
<!-- Output a new element in the new namespace -->
<xsl:element name="tns:{local-name()}" namespace="http://www.test.com/Service/v1">
<!-- Copy all child attributes and nodes
<xsl:apply-templates select="node()|@*"/> -->
<xsl:apply-templates />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
but i get a result like this
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<tns:send xmlns:tns="http://www.test.com/Service/v3">
<NS2:Message release="006" version="010" xmlns:NS2="http://www.ncpdp.org/schema/SCRIPT" xmlns:tns="http://www.test.com/Service/v3">
<NS2:Body>
<NS2:New>
<NS2:Pharmacy>
<NS2:Identification>
<NS2:ID>
<NS2:IDValue>01017</NS2:IDValue>
<NS2:IDQualifier>94</NS2:IDQualifier>
<NS2:IDRegion>SCA</NS2:IDRegion>
<NS2:IDState>CA</NS2:IDState>
</NS2:ID>
</NS2:Identification>
</NS2:Pharmacy>
</NS2:New>
</NS2:Body>
</NS2:Message>
</tns:send>
</soapenv:Body>
</soapenv:Envelope>
In my output XML i get this
<NS2:Message release="006" version="010" xmlns:NS2="http://www.ncpdp.org/schema/SCRIPT" xmlns:tns="http://eps.pdxinc.com/webservice/Rxservice/v3">
Why was this added to the NS2:Message?
xmlns:tns="http://eps.pdxinc.com/webservice/Rxservice/v3
It was not there in the input xml.
There is something which I am missing. I would really appreciate if someone could point out the issue.
What I am looking to create in the output is the following:
<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<tns:send xmlns:tns="http://www.test.com/Service/v1">
<NS2:Message release="006" version="010" xmlns:NS2="http://www.ncpdp.org/schema/SCRIPT" >
<NS2:Body>
<NS2:New>
<NS2:Pharmacy>
<NS2:Identification>
<NS2:ID>
<NS2:IDValue>01017</NS2:IDValue>
<NS2:IDQualifier>94</NS2:IDQualifier>
<NS2:IDRegion>SCA</NS2:IDRegion>
<NS2:IDState>CA</NS2:IDState>
</NS2:ID>
</NS2:Identification>
</NS2:Pharmacy>
</NS2:New>
</NS2:Body>
</NS2:Message>
</tns:send>
</soapenv:Body>
</soapenv:Envelope>
The XSL document I am applying is adding an extra namespace xmlns:tns="http://www.test.com/Service/v3 in the NS2:Message.
Orginally the tag was :
<NS2:Message release="006" version="010" xmlns:NS2="http://www.ncpdp.org/schema/SCRIPT">
After i applied XSL it changed to :
<NS2:Message release="006" version="010" xmlns:NS2="http://www.ncpdp.org/schema/SCRIPT" xmlns:tns="http://www.test.com/Service/v3>
I don’t know where this namespace is getting added.
All I wanted was to transform xmlns:tns="http://www.test.com/Service/v3 to xmlns:tns="http://www.test.com/Service/v3 in tns:send tag.
Try this…
XML Input
XSLT 1.0 (or 2.0 if you change the version)
(Edit: Changed “tns” prefix to “djh” to illustrate how the prefix doesn’t matter.)
XML Output