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

XSLT Transformation Functions

Former Member
0 Likes
1,380

Hello,

I have a trasnformation and something in this transformation is not logical. why do I have to write after the expression for-each, <item>????


        <ROOT>

          <LIST>

            <xsl:for-each select="/pre:XmlInterchange/pre:Payload/pre:Organisations/pre:Organisation/pre:OrganisationDetails/pre:Addresses/pre:Address">

              <item>

                <NAME>
                  <xsl:value-of select="string(../../pre:Name)"/>
                </NAME>

if I delete the expression <item> I get a short dump, the funny thing is that I can write whatever I want for the expression <item> and it works

So following I don't understand, why do I have to write it?

11 REPLIES 11
Read only

Former Member
0 Likes
1,250

Hi,

I have done a little XLST, but never used 'for-each'. So I am just speculating...

Maybe the <item> element is mandatory for the parser in order to bound each item of the for-each?

I think someone more experienced with the topic would tell us!

Read only

0 Likes
1,250

what I not understand is that <item> is not a command, I can wrote in this < > somethinf else and it works

Read only

former_member207438
Participant
0 Likes
1,250

Only elements which have the namespace xls for example <xls:for-each> are part of the XSLT. In your example <item> is an element (not part of the XSLT) that will be copied to the result as is. That's why there is no problem with your XSLT. If I understood your question correctly.

The best website for XSLT is [http://w3schools.com]

Read only

former_member207438
Participant
0 Likes
1,250

Actually. Can you post your entire XSLT? Might help to answer your question.

Read only

0 Likes
1,250

this is my xslt which works very well, but I understand not why I have to write the element <item> on the top and on the buttom.



<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:pre="http://www.edi.com.au/EnterpriseService/" version="1.0">

  <xsl:template match="*">
    <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
      <asx:values>

        <ROOT>

          <LIST>

            <xsl:for-each select="/pre:XmlInterchange/pre:Payload/pre:Organisations/pre:Organisation/pre:OrganisationDetails/pre:Addresses/pre:Address">
              <item>

                <NAME>
                  <xsl:value-of select="string(../../pre:Name)"/>
                </NAME>

                <COUNTRY>
                  <xsl:value-of select="string(../../pre:Location/@Country)"/>
                </COUNTRY>

                <CITY>
                  <xsl:value-of select="string(../../pre:Location/@City)"/>
                </CITY>

                <LOCATION>
                  <xsl:value-of select="string(../../pre:Location)"/>
                </LOCATION>

                <ADDRESSLINE1>
                  <xsl:value-of select="string(pre:AddressLine1)"/>
                </ADDRESSLINE1>

                <ADDRESSLINE2>
                  <xsl:value-of select="string(pre:AddressLine2)"/>
                </ADDRESSLINE2>

                <ADDRESSCODE>
                  <xsl:value-of select="string(pre:AddressCode)"/>
                </ADDRESSCODE>

                <CITYORSUBURB>
                  <xsl:value-of select="string(pre:CityOrSuburb)"/>
                </CITYORSUBURB>

                <STATEORPROVINCE>
                  <xsl:value-of select="string(pre:StateOrProvince)"/>
                </STATEORPROVINCE>

                <POSTCODE>
                  <xsl:value-of select="string(pre:PostCode)"/>
                </POSTCODE>

                <LANGUAGE>
                  <xsl:value-of select="string(pre:Language)"/>
                </LANGUAGE>

              </item>
            </xsl:for-each>

          </LIST>

        </ROOT>

      </asx:values>
    </asx:abap>
  </xsl:template>

</xsl:transform>

Read only

0 Likes
1,250

Hi,

Logically(for me) the <item></item> element is very much required. Let me explain..

From your XSLT code the source/result XML should look like below rite...

<ROOT> 
     <LIST> 
        <ITEM>                    " First Item
            <NAME>
            Jose
            </NAME> 
            <COUNTRY>
             India
             </COUNTRY> 
            .
            .
            <LANGUAGE>
             English
             </LANGUAGE> 
        </ITEM> 
        <ITEM>                    " Second Item 
            <NAME>
            ABAP OO Beginner
            </NAME> 
            .
            .
            <LANGUAGE>
             English
             </LANGUAGE> 
         </ITEM> 
     </LIST> 
</ROOT>

Here if you have only one item, element <item> is not required. But for the other cases(multiple items), the XML document is not proper without <item>....

~Jose

Read only

0 Likes
1,250

but instead of <item> I can write whatever I want, this is what I not really understand, as item is not a expression

Read only

0 Likes
1,250

Hi,

With the very limited knowledge on ABAP <-> XML conversions using XSLT, I assume

this conversion is for converting SAP data to XML format... If it is so, the name of element does not

matter at all becoz <item> is just going to be the element name in the result XML document

1) If it is <item> , the result XML document will be like in the above message.

2) Or if it is <somethingelse> the result XML document will be

<ROOT> 
     <LIST> 
        <somethingelse>                    " First Item
            <NAME>
            Jose
            </NAME> 
            <COUNTRY>
             India
             </COUNTRY> 
            .
            .
            <LANGUAGE>
             English
             </LANGUAGE> 
        </somethingelse> 
        <somethingelse>                    " Second Item 
            <NAME>
            ABAP OO Beginner
            </NAME> 
            .
            .
            <LANGUAGE>
             English
             </LANGUAGE> 
         </somethingelse>
     </LIST> 
</ROOT>

~Jose.

Edited by: Jose on May 15, 2009 2:46 PM

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,250

Hello

Again many important pieces of information are missing in order to answer your question. However, I assume your scenario looks like this:

- You have an XML file with data

- You want to make an XSLT transformation XML -> ABAP (using CALL TRANSFORMATION)


DATA:
  ld_xml      TYPE string,
  lt_data      TYPE <table type>.

"... Upload XML file into string

  CALL TRANSFORMATION ID 'Z_MY_XSLT'
    SOURCE ld_xml
    RESULT itab = lt_data.

I think to remember that this transformation expects each record of the ABAP itab to be defined as <ITEM> structure (complex sequence) in the XML.

You may also replace the <xsl:transform> statement with <xsl:stylesheet> and check if you still need <item> or if you can use any other name.

Regards

Uwe

Read only

Former Member
0 Likes
1,250

Hi,

The element <item> (or whatever the name) seems just to declare the item that are to be repeted with the for-each. Like some kind of a container...

Read only

former_member207438
Participant
0 Likes
1,250

Please provide the following, if you'd like further discussion on this.

1) A sample XML that you are transforming

2) Your CALL TRANSFORMATION with the declaration of variables used in it

If no further discussion needed, then, in my opinion, Uwe Schieferstein answered your question.