on 02-12-2015 9:02 AM
Dears,
I have an outbound interface that required field mapping without any namespace prefixes at the beginning of each node. So I have implemented an XSLT program and use it as a mapping program in the operation mapping and it worked fine as it has removed all the prefixes. BUT my problem is, the first Document node header should contain the namespace after the <node> as a value.
this is the XSLT program code I've used to remove the prefixes:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*">
<xsl:element name="{local-name(.)}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
my XML msg looks like this:
After using the XSLT mapping program:
<?xml version="1.0" encoding="UTF-8" ?>
So, even the namespace value after Document is removed. I only want the name space (n0:) to be removed and keep the other namespace.
Can someone help me where can I modify the code to match want I need?!
Thank you,
Hi Eman,
May be this is not an elegant way, but you can delete all and add the other namespace:
Source:
<?xml version="1.0" encoding="utf-8"?>
<n0:Document xmlns:n0="urn:xxxxxxxxxxxxxxxxxx" xmlns:prx="urn:sap.com:proxy:DR1xxxxxxxxxxxxxxxxxxxxxxxxx">
<n0:subelement1>
<n0:subelement2>1234567</n0:subelement2>
</n0:subelement1>
</n0:Document>
XSL:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*">
<xsl:element name="{local-name(.)}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name(.)}"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>
<xsl:template match="/*">
<xsl:element name="ns:{local-name()}" namespace="urn:sap.com:proxy:DR1xxxxxxxxxxxxxxxxxxxxxxxxx">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Target:
<?xml version="1.0" encoding="UTF-8"?>
<ns:Document xmlns:ns="urn:sap.com:proxy:DR1xxxxxxxxxxxxxxxxxxxxxxxxx">
<subelement1>
<subelement2>1234567</subelement2>
</subelement1>
</ns:Document>
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Eman
I agree with Inaki. There is no other way to do this in XSLT.
These will be necessary code
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*">
<xsl:element name="{local-name(.)}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="/*">
<xsl:element name="ns:{local-name()}" namespace="urn:sap.com:proxy:DR1xxxxxxxxxxxxxxxxxxxxxxxxx">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
However you can do the same in java mapping as well.
Thanks,
Indrajit
Hi Eman
Xml Anonymizer bean worked perfectly for your scenario.
Module name : AF_Modules/XMLAnonymizerBean
Module Key : 1
Parameter name : anonymizer.acceptNamespaces
Value : urn:sap.com:proxy:DR1xxxxxxxxxxxxxxxxxxxxxxxxx prx
output xml will be like below
<?xml version='1.0' encoding='utf-8'?>
<Document xmlns:prx='urn:sap.com:proxy:DR1xxxxxxxxxxxxxxxxxxxxxxxxx'>
<subelement1>
<subelement2>1234567</subelement2>
</subelement1>
</Document>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Eman
Have you tried using the standard XMLAnonymizerBean module? No extra custom development needed if it fits your needs.
It allows you to specify the namespaces you want to keep (prx) in the following parameter, anything else not specified will be removed (ns0)
anonymizer.acceptNamespaces
There are a few SCN blogs for more details on the usage and example. Here are a few of them:
Rgds
Eng Swee
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
24 | |
11 | |
9 | |
7 | |
5 | |
5 | |
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.