cancel
Showing results for 
Search instead for 
Did you mean: 

Convert XML to a different format in SAP Cloud Integration

03-11-2022 6:20 AM
2493 views 3 comments Go to solution
0 Likes
SAP Managed Tags
Subscribe

Hi Experts,

Fairly new to Cloud Integration and would appreciate your help in converting the below source XML structure to the expected target structure.

In my understanding, this can be only achieved using groovy scripting. Any way to achieve using message mapping?

The value from 'Field 1' , 'Field2' , 'Field3' in source should be added in to a field '1' in the target. Also depending up on the number of 'Item' in source, target should have that many incremental numbers '1' ,'2','3' etc.

Request your kind help on the same.

Source XML:

<Root>

<Item>

<Field1>A</Field1>

<Field2>B</Field2>

<Field3>C</Field3>

</Item>

<Item>

<Field1>D</Field1>

<Field2>E</Field2>

<Field3>F</Field3>

</Item>

</Root>

Expected Target:

<Root>

<Item>

<1>ABC</1>

</Item>

<Item>

<2>DEF</2>

</Item>

</Root>

Thanks & Regards,

Priyanka

0 Likes

Accepted Solutions (1)

Accepted Solutions (1)

Hi Priyanka,

Please use the below XSLT code to generate your required output:

--------------------------------------------------------------------------------------------------------------------------------

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

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

<xsl:template match="/">

<Root>

<xsl:for-each select="/Root/Item">

<Item>

<xsl:for-each select=".">

<Item1>

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

</Item1>

</xsl:for-each>

</Item>

</xsl:for-each>

</Root>

</xsl:template>

</xsl:stylesheet>

--------------------------------------------------------------------------------------------------------------------------------

You can then do the mapping accordingly as per your requirement ( using Concat Function, etc.)

Kindly accept the answer if it works for you.

- Thanks,

Akshay Bakliwal

Answers (2)

Answers (2)

MortenWittrock
SAP Mentor
SAP Mentor

Hi Priyanka

First off, you can't have XML elements named 1, 2 etc. The element names must start with a letter or an underscore. So you can name them, say, Item1, Item2 etc.

I don't think this can be done in Message Mapping either, but it can definitely be done in both scripting and XSLT. I wrote a blog post a couple of years ago which discusses the pros and cons of the three mapping options: Cloud Integration mapping: Your options explained and compared

Regards,

Morten

daviddasilva
Active Contributor
0 Likes

Hi Priyanka,

If you know the source structure of your XML and the target structure of your XML, then you could use a Message mapping step to do this. It will take some standard functions to achieve it but it can be done fairly easily. The key here is to ensure you have the correct source and target schemas (.xsd files).

Then, when mapping source to target, set the correct context level and then use the function concat to join the values within the fields you want.

Kind regards,

David