Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT table to complex xml structure

volkan_bekci2
Explorer
0 Kudos
185

Hi Gurus,

I need help about STRANS functionality of ABAP.

I have a internal table and i show this table in ALV list. I want to send my alv list to legacy systems.

Normally i can create a xml document with concat fields in abap. But i want to use STRANS.

How can I transform itab to deep structure xml. Thanks a lot. I dont want to use string concat or xml classes.. I just want to use XSLT.

Thanks a lot

Volkan

Source xml of ITAB

<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">

<asx:values>

<ITAB>

<item>

<VBELN>0060000004</VBELN>

<KUNNR>0000000051</KUNNR>

<POSNR>000001</POSNR>

<MATNR>H1</MATNR>

</item>

<item>

<VBELN>0060000004</VBELN>

<KUNNR>0000000051</KUNNR>

<POSNR>000002</POSNR>

<MATNR>H2</MATNR>

</item>

<item>

<VBELN>0060000005</VBELN>

<KUNNR>0000000051</KUNNR>

<POSNR>000001</POSNR>

<MATNR>H1</MATNR>

</item>

</ITAB>

</asx:values>

</asx:abap>

Destination XML Must be like this

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

<ROOT>

<ORDER>

<VBELN>0060000004</VBELN>

<KUNNR>0000000051</KUNNR>

<ORDERLINES>

<ORDERLINE>

<POSNR>000001</POSNR>

<MATNR>H1</MATNR>

</ORDERLINE>

<ORDERLINE>

<POSNR>000002</POSNR>

<MATNR>H2</MATNR>

</ORDERLINE>

</ORDERLINES>

</ORDER>

<ORDER>

<VBELN>0060000005</VBELN>

<KUNNR>0000000051</KUNNR>

<ORDERLINES>

<ORDERLINE>

<POSNR>000001</POSNR>

<MATNR>H1</MATNR>

</ORDERLINE>

</ORDERLINES>

</ORDER>

</ROOT>

1 REPLY 1

former_member197445
Contributor
0 Kudos
80

Try this:

<?xml version='1.0' ?>

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

   <xsl:key name="ByDoc" use="VBELN" match="item"/>

   <xsl:key name="ItemsByDoc" use="concat(concat(VBELN, '|'), POSNR)" match="item"/>

          <xsl:template match="/">

                    <xsl:variable name="var_msg" select="asx:abap/asx:values/ITAB"/>

                    <xsl:for-each select="$var_msg">

                    <ROOT>

                    <xsl:for-each select="$var_msg/item[count(. | key('ByDoc', VBELN)[1]) = 1]">

                    <xsl:sort select="VBELN" data-type="number"></xsl:sort>

                              <ORDER>

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

                              <KUNNR><xsl:value-of select="string(KUNNR)"/></KUNNR>

                              <ORDERLINES>

                                  <xsl:for-each select="key('ByDoc', VBELN)[count(. | key('ItemsByDoc', concat(concat(VBELN, '|'), POSNR))[1]) = 1]">

                                        <xsl:sort select="POSNR" data-type="number"></xsl:sort>

                                        <ORDERLINE>

                                                  <POSNR><xsl:value-of select="string(POSNR)"/></POSNR>

                                                  <MATNR><xsl:value-of select="string(MATNR)"/></MATNR>

                                        </ORDERLINE>

                                        </xsl:for-each>

                              </ORDERLINES>

                              </ORDER>

                    </xsl:for-each>

                    </ROOT>

                    </xsl:for-each>

          </xsl:template>

</xsl:stylesheet>