cancel
Showing results for 
Search instead for 
Did you mean: 

Replace Namespace in XSLT

Former Member
0 Kudos

Hi all,

We are facing one issue in xslt mapping.

We have a requirement where client wants us to use only XSLT mapping, no Graphical/Java mapping.

Now, the issue is we have Proxy(ABAP) to Proxy scenario, where we need to change/replace the namespace coming from source(ECC).

one namespace coming from ECC side, which we need to replace it by another SAP system namespace.

for ex: 

 

urn:mr:pi:interfaces:ecc:ID461:OrderIntegration

it should get replaced by below

urn:mr:pi:interfaces:tm:ID461:OrderIntegration

However messages in PI are getting failed as ECC namespace is not getting replaced by tm namespace.

Please let me know how to handle it in XSLT only. 🙂

appreciate early response for this.

Thanks,

Aman

Accepted Solutions (0)

Answers (3)

Answers (3)

ambrish_mishra
Active Contributor
0 Kudos

Aman,

Try the link below.

http://wiki.sdn.sap.com/wiki/display/XI/Changing+Namespaces+and+the+encoding+format+of+XML

There are multiple links on SCN for this.

Ambrish

Former Member
0 Kudos

Ambrish,

I already tried this, problem is main namespaces also getting effected. I am able to replace the particular namespace by the above code in my last reply, but I need to maintain main namespaces as well.

any other pointer?

Thanks,

Aman

Former Member
0 Kudos

if you only want to swap the namespace with an XSLT try this:

http://wiki.sdn.sap.com/wiki/display/XI/Changing+Namespaces+and+the+encoding+format+of+XML

Former Member
0 Kudos

Hi Barry,

Thanks for the link, I already tried this option but my requirement is to keep the Main Namespaces as is and to replace particular Namespaces(which are at field level)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="@*|*|text()" />
        </xsl:copy>
    </xsl:template>
    <xsl:template match="//*[namespace-uri()='urn:mr:pi:interfaces:ecc:ID461:OrderIntegration']">
        <xsl:element name="{local-name()}" namespace="urn:mr:pi:interfaces:tm:ID461:OrderIntegration" >
            <xsl:apply-templates select="@*|node()" />
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>

I tried this code, I am able to replace the field level Namespaces but the problem is main Namespaces are not coming in the output.

please help on this.

TIA.

Thanks,

Aman

Former Member
0 Kudos

Hi Aman

maybe you need to change the node where you set the level for transformation in the XSLT?

Former Member
0 Kudos

Hi Barry,

my Input structure is  

<?xml version="1.0" encoding="utf-8"?>

<nm:TransportationRequestSUITERequest xmlns:nm="http://sap.com/xi/SAPGlobal20/Global" xmlns:prx="some ns">

                <MessageHeader/>

                <TransportationRequest>

                                <Item>

                                                <ne:TMAddnOrderFields xmlns:ne="urn:mr:pi:interfaces:ecc:ID461:OrderIntegration">

                                                                <n0:SHIP_TYPE xmlns:n0="urn:mr:pi:interfaces:ecc:ID461:OrderIntegration">LOLO</n0:SHIP_TYPE>

                                                </ne:TMAddnOrderFields>

                                </Item>

                </TransportationRequest>

</nm:TransportationRequestSUITERequest>

I just need to replace the namespace of TMAddnOrderFields and its fields. I am able to do that but main namespaces getting effected.

please let me know what to be edited in this below snippet. 🙂

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="@*|*|text()" />
        </xsl:copy>
    </xsl:template>
    <xsl:template match="//*[namespace-uri()='urn:mr:pi:interfaces:ecc:ID461:OrderIntegration']">
        <xsl:element name="{local-name()}" namespace="urn:mr:pi:interfaces:tm:ID461:OrderIntegration" >
            <xsl:apply-templates select="@*|node()" />
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>

Thanks,

Aman

manigram
Active Participant
0 Kudos
Former Member
0 Kudos

Hi Mani,

link is not working.

Thanks,

Aman