Skip to Content
0
Nov 07, 2012 at 07:37 PM

Transform tables to hiarchic / nested xml

40 Views

Hi all,

I was searching here and via Google about the issue and found some clues already. However, I would like to ask about any best practice here as I would suppose this must be a quite common task.

I have a source XML from an RFC that looks like this

<LT_DELIVERY_HEAD>  <item>           <VBELN>D1</VBELN>           <KUNNR>C1</KUNNR>           <ROUTE/>  </item>  <item>           <VBELN>D2</VBELN>           <KUNNR>C2</KUNNR>           <ROUTE/>  </item></LT_DELIVERY_HEAD><LT_HU_HEAD>  <item>           <EXIDV>E1</EXIDV>           <OBJKEY>D1</OBJKEY>  </item>  <item>           <EXIDV>E2</EXIDV>           <OBJKEY>D1</OBJKEY>  </item>  <item>           <EXIDV>E3</EXIDV>           <OBJKEY>D2</OBJKEY>  </item></LT_HU_HEAD>

Expected outpout would be

<Shipment>          <Delivery>                    <DeliveryID>D1</DeliveryID>                    <ShipToID>C1</ShipToID>                    <HandlingUnit>                              <HandlingUnitID>E1</HandlingUnitID>                              <HandlingUnitID>E2</HandlingUnitID>                    </HandlingUnit>          </Delivery>          <Delivery>                    <DeliveryID>D2</DeliveryID>                    <ShipToID>C2</ShipToID>                    <HandlingUnit>                              <HandlingUnitID>E3</HandlingUnitID>                    </HandlingUnit>          </Delivery></Shipment>

I would like to know how to best (most easily) achieve this. Message Mapping with UDF? XSLT? Java Mapping? Or any other tricks?

Key here would be that HandlingUnitIDs E1 and E2 should reside under Delivery D1 and HandlingUnitID E3 under Delivery D2.

Thanks in advance for any input on this.

Cheers

Jens