Application Development and Automation 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: 
Read only

Creating an XML From a Deep Structure using XSL Transformation

Former Member
0 Likes
695

Hi ABAPers,

I have a requirement to use XSL Transformations on an ABAP deep type structure.

Currently i have an API that fills in this deep structure and by using CALL TRANSFORMATION ID.... i will get the BIG XML having having 100s of nodes . But actualy form the deep structure i need only some NODES (say 50)... So i tried writing an XSLT

in the transaction STRANS.. but on using this TRANSFORMATION which i wrote i am getting an error messgae like INVALID XML...

Am i going in right track or is there a good solution...

My sample transformation is as below...

***********************************************************************************************************************

<xsl:transform version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:strip-space elements="*"/>

<xsl:template match="/">

<xsl:value-of select="DATA/NODE_ELEMENTS/UUID_KEY/UUID"/>

<xsl:value-of select="DATA/NODE_ELEMENTS/SEMANTICAL_NAME"/>

<xsl:value-of select="DATA/NODE_ELEMENTS/STRUCT_CAT"/>

<xsl:value-of select="DATA/NODE_ELEMENTS/USAGE_CAT"/>

<xsl:value-of select="DATA/NODE_ELEMENTS/RESTRICTED_IND"/>

<xsl:value-of select="VALUES/DATA/NODE_ID"/>.

</xsl:template>

</xsl:transform>

***********************************************************************************************************************

Please help me in solving this issue....

Thanks,

Linda.

1 REPLY 1
Read only

Former Member
0 Likes
353

Hi Linda,

I am replying based on your sample code.

Try the below following suggestions.

here 'GRPHDR' is the node where I am selecting the data.

IGRPHDR is the name of the reference.

First calling the transformation in you program.



 TYPES: BEGIN OF tl_hdr,
           msgid(20)    TYPE c,
             END OF tl_hdr.
 DATA : t_hdr           TYPE STANDARD TABLE OF tl_hdr.

  GET REFERENCE OF t_hdr INTO l_result_xml-value.
    l_result_xml-name = 'IGRPHDR'.
    APPEND l_result_xml TO t_result_xml.

   TRY.

        CALL TRANSFORMATION yfi_xml_read
        SOURCE XML it_xml_data
        RESULT (t_result_xml).

      CATCH cx_root INTO l_rif_ex.

        l_var_text = l_rif_ex->get_text( ).
        l_bapiret-type = 'E'.
        l_bapiret-message = l_var_text.
        APPEND l_bapiret TO errormsgs.
        EXIT.
    ENDTRY.
 

in XSL transformation

First write a block of statement to specify from which node you are taking the data.

No matter it is a node or sub-node.


<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output encoding="iso-8859-1" indent="yes" method="xml" version="1.0"/>
  <xsl:strip-space elements="*"/>


<xsl:template match="/">
      <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
      <asx:values>
        <IGRPHDR>  " reference name of internal table
          <xsl:apply-templates select="//GrpHdr"/>
        </IGRPHDR>
  </asx:values>
    </asx:abap>
</xsl:template>

Next select the data from the nodes under the nodes specified in the transformation.

here msgid is the field i am selecting for value.



<xsl:template match="GrpHdr">
    <item>
      <MSGID>  " field in the internal table t_hdr where data has to go
        <xsl:value-of select="MsgId"/>
      </MSGID>
    </item>
  </xsl:template>
   

reply back if further clarification is needed.

Thanks and regards,

Kannan N