2014 Jan 20 11:47 AM
Hi all,
I'm receiving a XML from a Server and transform it via xslt-Transformation into an integer, because it is only one number.
Now I want to transform the data from a XML into a table. I checked some tutorials and there are many topics to solve this, but there, the structure is most for example: <id>1549347</id> <vorname>Albert</vorname> and so on.
But my file has the following structure:
<member><name>id</name><value><string>1549347</string></value></member>
<member><name>vorname</name><value><string>Albert</string></value></member>
<member><name>nachname</name><value><string>Hofman</string></value></member>
<member><name>email</name><value><string>albert.hofman@kunde.at</string></value></member>
<member><name>status</name><value><string>aktiv</string></value></member>
<member><name>istatus</name><value><int>1</int></value></member>
(This structure for each customer)
I tried, but I don't know how to solve this. How do I get this into a structure?
I don't need the value from <name>, I only need the value itself (into a table layout).
Do you have any idea?
Thanks in advance,
regards,
Florian
2014 Jan 20 1:44 PM
Hi,
what I know is xslt[transformation language] is used in sap xi/pi to convert the message structure.
I didn't get for which requirement you are using the xslt.
provide us more details...
br,
avinash
2014 Jan 20 1:47 PM
2014 Jan 20 2:21 PM
You can first use this type of transformation to convert xml to better format, and then use another transformation to populate structures.
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0">
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<member>
<xsl:apply-templates select="member" />
</member>
</xsl:template>
<xsl:template match="member">
<xsl:element name="{name}">
<xsl:value-of select="string" />
</xsl:element>
</xsl:template>
</xsl:transform>
//
2014 Jan 20 2:36 PM
Continuing previous reply, this xml:
<members>
<member><name>id</name><value><string>1549347</string></value></member>
<member><name>vorname</name><value><string>Albert</string></value></member>
<member><name>nachname</name><value><string>Hofman</string></value></member>
<member><name>email</name><value><string>albert.hofman@kunde.at</string></value></member>
<member><name>status</name><value><string>aktiv</string></value></member>
<member><name>istatus</name><value>1</value></member>
</members>
Gets converted to this:
<member>
<id>1549347</id>
<vorname>Albert</vorname>
<nachname>Hofman</nachname>
<email>albert.hofman@kunde.at</email>
<status>aktiv</status>
<istatus></istatus>
</member>
Using XSLT transformation code:
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0">
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<member>
<xsl:apply-templates select="member" />
</member>
</xsl:template>
<xsl:template match="member">
<xsl:element name="{name}">
<xsl:value-of select="value/string" />
</xsl:element>
</xsl:template>
</xsl:transform>
//
2014 Jan 21 8:34 AM
Hi,
we are using SAP-CRM and an external E-Mail broadcasting tool based on web.
You can only communicate via RPC. So I'm preparing a XML and send it to the Server and get back a XML in the above structure (in abap). I want to change this structure and get the values into an abap table.
@Manish Kumar: Do I have to call this Transformation from an abap report, or can I call a transformation in a transformation. When I implement your solution, I get an raise exception at line 04. "Falsches Element element bei XML-ABAP Transformation." --> False element "element" in XML abap transformation.
2014 Jan 21 9:16 AM
Hi Florian,
I had run the logic from a report program which demonstrates how during a transformation, key-value node pair can be converted a single node whose name is key and value is value.
You are able to convert <amount>1234</data> to an ABAP structure or variable using existing internet tutorials, using say transformation2.
Before calling this transformation, you can call another transformation, say transformation1 that will change <name>amount</name><value>1234</value> to <amount>1234</amount>.
It is possible to do it using single transformation, but i do not have sufficient expertise in this area.
2015 Oct 22 5:30 AM
Hi Manish,
I have a problem that data is not populated to my internal table. Could you please check and help me ?
-----------------------------------------------------------------------------
My ABAP code is below:
-----------------------------------------------------------------------------
GET REFERENCE OF gt_goodsmovement INTO gs_result_xml-value.
gs_result_xml-name = 'IDOC_POSDW'.
APPEND gs_result_xml TO gt_result_xml.
CALL TRANSFORMATION zxslt_goodsmovement
SOURCE XML gt_itab
RESULT (gt_result_xml).
-----------------------------------------------------------------------------
My transformation is below:
-----------------------------------------------------------------------------
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sap="http://www.sap.com/sapxsl"
>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<IDOC_POSDW>
<xsl:apply-templates select="//POSDW"/>
</IDOC_POSDW>
</asx:values>
</asx:abap>
</xsl:template>
<xsl:template match="/POSDW">
<item>
<POSDW>
<xsl:for-each select="TRANSACTION">
<TRANSACTION>
<RETAILSTOREID>
<xsl:value-of select="TRANSACTION/RETAILSTOREID"/>
</RETAILSTOREID>
<BUSINESSDAYDATE>
<xsl:value-of select="TRANSACTION/BUSINESSDAYDATE"/>
</BUSINESSDAYDATE>
<TRANSACTIONTYPECODE>
<xsl:value-of select="TRANSACTION/TRANSACTIONTYPECODE"/>
</TRANSACTIONTYPECODE>
<WORKSTATIONID>
<xsl:value-of select="TRANSACTION/WORKSTATIONID"/>
</WORKSTATIONID>
<TRANSACTIONSEQUENCENUMBER>
<xsl:value-of select="TRANSACTION/TRANSACTIONSEQUENCENUMBER"/>
</TRANSACTIONSEQUENCENUMBER>
<xsl:for-each select="GOODSMOVEMENT">
<GOODSMOVEMENT>
<GOODSMOVEMENTSEQUENCENUMBER>
<xsl:value-of select="TRANSACTION/GOODSMOVEMENT/GOODSMOVEMENTSEQUENCENUMBER"/>
</GOODSMOVEMENTSEQUENCENUMBER>
<GOODSMOVEMENTTYPECODE>
<xsl:value-of select="TRANSACTION/GOODSMOVEMENT/GOODSMOVEMENTTYPECODE"/>
</GOODSMOVEMENTTYPECODE>
<GOODSMOVEMENTREASONCODE>
<xsl:value-of select="TRANSACTION/GOODSMOVEMENT/GOODSMOVEMENTREASONCODE"/>
</GOODSMOVEMENTREASONCODE>
<ITEMIDQUALIFIER>
<xsl:value-of select="TRANSACTION/GOODSMOVEMENT/ITEMIDQUALIFIER"/>
</ITEMIDQUALIFIER>
<ITEMID>
<xsl:value-of select="TRANSACTION/GOODSMOVEMENT/ITEMID"/>
</ITEMID>
<UNITCOUNT>
<xsl:value-of select="TRANSACTION/GOODSMOVEMENT/UNITCOUNT"/>
</UNITCOUNT>
</GOODSMOVEMENT>
</xsl:for-each>
</TRANSACTION>
</xsl:for-each>
</POSDW>
</item>
</xsl:template>
</xsl:transform>
-----------------------------------------------------------------------------
Thanks and Regards,
May