on 05-03-2016 6:09 AM
Hello Experts,
I have a requirement of replacing the namespace prefix using xslt mapping. There are 2 prefixes ns0 and ns1 which need to be replaced to v1 and v11. The challenge I am facing is that the v1 prefix is not appearing in EmployeeUpdate. Request correction in the xslt mapping to achieve the target structure.
Thanks is Advance.
Input Structure:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:EmployeeUpdate xmlns:ns0="urn:interface/Employee/Data/Update/v1">
<ns1:EmployeeList xmlns:ns1="urn:Employee/Data/Update/v1.0">
<ns1:Employee>
<ns1:EmpCode>EC</ns1:EmpCode>
<ns1:EmpName>EN</ns1:EmpName>
<ns1:Dept>DEP</ns1:Dept>
</ns1:Employee>
</ns1:EmployeeList>
</ns0:EmployeeUpdate>
OUTPUT required:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="urn:interface/Employee/Data/Update/v1" xmlns:v11="urn:Employee/Data/Update/v1.0">
<soapenv:Header/>
<soapenv:Body>
<v1:EmployeeUpdate>
<v11:EmployeeList>
<v11:Employee>
<v11:EmpCode>EC</v11:EmpCode>
<v11:EmpName>EN</v11:EmpName>
<v11:Dept>DEP</v11:Dept>
</v11:Employee>
</v11:EmployeeList>
</v1:EmployeeUpdate>
</soapenv:Body>
</soapenv:Envelope>
XSLT Mapping:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="urn:interface/Employee/Data/Update/v1"" xmlns:v11="urn:Employee/Data/Update/v1.0">
<soapenv:Header/>
<soapenv:Body>
<xsl:apply-templates select="node()|@* | *"/>
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
<xsl:template match="*">
<xsl:element name="v11:{local-name()}">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Hi Pankaj,
With this XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://sample.com/s" xmlns:ns0="urn:interface/Employee/Data/Update/v1" xmlns:ns1="urn:Employee/Data/Update/v1.0" xmlns:v1="urn:interface/Employee/Data/Update/v1" xmlns:v11="urn:Employee/Data/Update/v1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="ns0 ns1">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="urn:interface/Employee/Data/Update/v1" xmlns:v11="urn:Employee/Data/Update/v1.0">
<soapenv:Header/>
<soapenv:Body>
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
<xsl:template match="ns0:*">
<xsl:element name="v1:{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="ns1:*">
<xsl:element name="v11:{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
I get this XML:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns="http://sample.com/s" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<v1:EmployeeUpdate xmlns:v1="urn:interface/Employee/Data/Update/v1">
<v11:EmployeeList xmlns:v11="urn:Employee/Data/Update/v1.0">
<v11:Employee>
<v11:EmpCode>EC</v11:EmpCode>
<v11:EmpName>EN</v11:EmpName>
<v11:Dept>DEP</v11:Dept>
</v11:Employee>
</v11:EmployeeList>
</v1:EmployeeUpdate>
</soapenv:Body>
</soapenv:Envelope>
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Inaki Vila,
This xslt mapping helps, but still has couple of issues:
1. The soap envelop does not have the namespace.
xmlns:v1="urn:interface/Employee/Data/Update/v1" xmlns:v11="urn:Employee/Data/Update/v1.0"
2. The Namespace are occurring at the node level(this is not required):
<v1:EmployeeUpdate xmlns:v1="urn:interface/Employee/Data/Update/v1">
<v11:EmployeeList xmlns:v11="urn:Employee/Data/Update/v1.0">
Request inputs on this.
Thanks,
Pankaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.