cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP-XSLT Mapping Issue (Namespace)

Former Member
0 Kudos

Hi All,

I have been working on ABAP-XSLT mapping and facing an issue. First 2 lines of my input file look like this,

<?xml version="1.0" ?>

     <Invoice xmlns="http://schema.test.com/TEST/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schema.infor.com/TEST/2 http://schema.test.com/2.6.3/TEST/Developer/Invoice.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" releaseID="9.2" versionID="2.6.3">

When I test mapping without all the namespace definitions, the mapping works. But when I test with all namespaces as shown above, then mapping program cannot locate the field values in source XML.

I am using <xsl:template match="/"> to match root node (Invoice)

What could be wrong? I don't want to remove the namespaces from source file. What can be done?

- Netrey

Accepted Solutions (1)

Accepted Solutions (1)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Yes, you dont need to make changes in the source file. You can ignore the namespaces that you don't need using the XML Anonymizer bean. In addition to Greg's link if you need any screenshot for how to apply this bean you can see this link

http://www.saptechnical.com/Tutorials/XI/XMLPayload/Index.htm

Remember this bean module is not for adding the namespace. This is only used for removing the namespace or namespace prefix or changing the namespace prefix.

Former Member
0 Kudos

Hi Greg and Baskar,

Thanks for your inputs. Those are really helpful. However, I have a little problem here. I have JDBC adapter at sender side which reads table entry in VARBINARY format. Then Java mapping program converts this VARBINARY and then only I get the data in XML format. Now, if I use XML Anonymizer Bean in sender JDBC adapter, it's of no use. So, do I have to change this XML data in Java mapping only to remove namespace definitions or still there is some other way to do it, without manually modifying source XML ?

Thanks,

Netrey

former_member184681
Active Contributor
0 Kudos

Dear Netrey,

You're right, any adapter module is of no use in this case. Furtunately there is an alternative: you can use an additional XSLT mapping (after Java mapping and before the "main" graphical mapping) that will remove the namespaces from the XML payload. Here is the XSLT code that should do this for you:

<xsl:stylesheet version="1.0"
               
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 
<!-- attributes, commments, processing instructions, text: copy as is -->
 
<xsl:template match="@*|comment()|processing-instruction()|text()">
   
<xsl:copy-of select="."/>
 
</xsl:template>

 
<!-- elements: create a new element with the same name, but no namespace -->
 
<xsl:template match="*">
   
<xsl:element name="{local-name()}">
     
<xsl:apply-templates select="@*|node()"/>
   
</xsl:element>
 
</xsl:template>

</xsl:stylesheet>

More XSLT variants for removing namespaces are included in this thread: . You could also remove the namespaces while parsing the input in the Java mapping, but this might require some more complex coding.

Regards,

Greg

Former Member
0 Kudos

Dear Greg,

Fantastic! It indeed solved my problem. Thanks a lot. So, now I have mapping sequence like this,

Java Mapping (Converts VARBINARY to XML) -> XSL Mapping (Removes Namespaces) -> ABAP-XSL Mapping (Main mapping which creates Target XML).

Thanks again.

Best Regards,

Netrey

Answers (1)

Answers (1)

former_member184681
Active Contributor
0 Kudos

Hi Netrey,

>>> What could be wrong?

It's just that you cannot ignore the namespaces when working with XML. Namespace is an integral part of the tag name and you cannot simply omit it (otherwise the solution won't work as expected, just like in your case). <abc:xyz> is not the same tag as <def:xyz>, just like <xyz> is not the same as <jkl>.

>>> I don't want to remove the namespaces from source file.

Luckily there is also another solution. You can use the XML Anonymizer Bean in the sender channel to make PI remove the unwanted namespaces from the payload read from the file, before the mapping. Thanks to that, you will not have to modify the source files, nor the mapping itself. Read more about the bean here:

http://help.sap.com/saphelp_nw04/helpdata/en/45/d169186a29570ae10000000a114a6b/content.htm

Regards,

Greg