cancel
Showing results for 
Search instead for 
Did you mean: 

how to add ns0 to the root namesapce

0 Kudos

Hi

Target SAP system is expecting n0: at the namepsace as shown below.

But the file from customer is coming without n0: I have a file--pi-->proxy scenario.(No mapping)

I went through lot of blogs, and tried XMLAnonymizer Bean on file adapter module. It is adding ns0: for all the elements. I just need to root node as shown in the screenshot. If add bean on SOAP adapter it has no effect.

I have tried XSLT Mapping from but it is simply adding another namespace tag at the root.

I have no control on source and target and need to change only in SAP PI/PO System. Is there a way to make this work in SAP XI/PI ?

Thanks

Ravindra

Accepted Solutions (0)

Answers (3)

Answers (3)

0 Kudos

Hi Ravinda,

try this:

Create a own XSD from org. xml message with:

Free Online XSD/XML Schema Generator From XML - FreeFormatter.com

Import this as the new XSD and make with this a message mapping to your needed target format. In this case no XSLT or modul bean is needed.

Quick and dirty is also possible to make the message mapping with a xml message (source format - is an option to use an xml). I prefer solution one, but have also sceanrios which running well with the other solution.

Regards Thomas

udo_martens
Active Contributor
0 Kudos

Hi Ravindra,


I have tried XSLT Mapping from UDF to add xml namespace tag but it is simply adding another namespace tag at the root.

If you have the SAME namespace in in source and target, then you just write down the root as you want to have it and put between opening and closing tag the xsl expression xsl:copy-of select="./*". So you select all child nodes of the root.

If you have different source and target namespace you need to map each field.

Best would be if you post your source, your wished target and your xsl.

/Udo

0 Kudos

Udo

My soure and target namespace are same and I don't have any mapping.

Expected XML

- <n0:SLL_SPL_DATA_FILE xmlns:n0="http://sap.com/xi/GTS">

- <SLL_SPL_CONTROL>

<SLL_SPL_DATA_PROVIDER_ID>String 1</SLL_SPL_DATA_PROVIDER_ID>

<SLL_SPL_FILE_ID>String 2</SLL_SPL_FILE_ID>

<SLL_SPL_VRSIO>String 3</SLL_SPL_VRSIO>

<SLL_SPL_BASE_URL>http://sap.com/anyURI</SLL_SPL_BASE_URL>

</SLL_SPL_CONTROL>

</n0:SLL_SPL_DATA_FILE>

Incoming XML

<SLL_SPL_DATA_FILE xmlns="http://sap.com/xi/GTS">

<SLL_SPL_CONTROL>

<SLL_SPL_DATA_PROVIDER_ID>String 1</SLL_SPL_DATA_PROVIDER_ID>

<SLL_SPL_FILE_ID>String 2</SLL_SPL_FILE_ID>

<SLL_SPL_VRSIO>String 3</SLL_SPL_VRSIO>

<SLL_SPL_BASE_URL>http://sap.com/anyURI</SLL_SPL_BASE_URL>

</SLL_SPL_CONTROL>

<SLL_SPL_DATA_FILE>

I am using below 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" encoding="UTF-8"/>

<xsl:template match="/">

<ns0:SLL_SPL_DATA_FILE xmlns:ns0="http://sap.com/xi/GTS">

<xsl:copy-of select="." />

</ns0:SLL_SPL_DATA_FILE>

</xsl:template>

</xsl:stylesheet>

It is generating below output

<n0:SLL_SPL_DATA_FILE xmlns:n0="http://sap.com/xi/GTS">

-<SLL_SPL_DATA_FILE xmlns="http://sap.com/xi/GTS">

<SLL_SPL_CONTROL>

<SLL_SPL_DATA_PROVIDER_ID>String 1</SLL_SPL_DATA_PROVIDER_ID>

<SLL_SPL_FILE_ID>String 2</SLL_SPL_FILE_ID>

<SLL_SPL_VRSIO>String 3</SLL_SPL_VRSIO>

<SLL_SPL_BASE_URL>http://sap.com/anyURI</SLL_SPL_BASE_URL>

</SLL_SPL_CONTROL>

<SLL_SPL_DATA_FILE>

</n0:SLL_SPL_DATA_FILE>



Basically it is putting entire xml back into root and end tag.


I need to tune XSL. Any expert in xsl who can help me ?


Thanks

Ravindra






Snavi
Active Participant
0 Kudos

Hi Ravindra,

  1. replace <xsl:template match="/"> with <xsl:template match="@*|node()"> and <xsl:copy-of select="."/> with <xsl:copy-of select="@*|node()"/> in your xslt that you posted
  2. if you are doing mapping , then using graphical mapping map the elements one to one from source to target should also resolve your issue.
  3. xslt one to one mapping with namespace prefix to your root node.

<?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" version="1.0" encoding="UTF-8" indent="yes"/>

  <xsl:template match="/">

  <ns0:SLL_SPL_DATA_FILE xmlns:ns0="http://sap.com/xi/GTS">

  <SLL_SPL_CONTROL>

  <SLL_SPL_DATA_PROVIDER_ID><xsl:value-of select="//SLL_SPL_DATA_PROVIDER_ID"/></SLL_SPL_DATA_PROVIDER_ID>

  <SLL_SPL_FILE_ID><xsl:value-of select="//SLL_SPL_FILE_ID"/></SLL_SPL_FILE_ID>

  <SLL_SPL_VRSIO><xsl:value-of select="//SLL_SPL_VRSIO"/></SLL_SPL_VRSIO>

  <SLL_SPL_BASE_URL><xsl:value-of select="//SLL_SPL_BASE_URL"/></SLL_SPL_BASE_URL>

  </SLL_SPL_CONTROL>

  </ns0:SLL_SPL_DATA_FILE>

  </xsl:template>

</xsl:stylesheet>

udo_martens
Active Contributor
0 Kudos

Hi Ravindra,

the xsl is nearly ok. But the x-path expression is wrong. You copy the whole message under the root element with a <xsl:copy-of select="."/>

But you should copy ONLY the children of the root element.

Try <xsl:copy-of select="./*"/>

/Udo

Harish
Active Contributor
0 Kudos

Hi Ravindra,

Please check the below blog for XMLAnonymizer Bean configuration