cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT mapping to replace namespace prefix

Former Member
0 Kudos

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>

Accepted Solutions (1)

Accepted Solutions (1)

iaki_vila
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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

Answers (1)

Answers (1)

nitindeshpande
Active Contributor
0 Kudos

Hello Pankaj,

You need to write a XSLT mapping for this. We already have a Standard Adapter module to do this.

Please go through the below blog -

Regards,

Nitin