Create ABAP coding
At first we create the internal table TYPES and DATA definition, we want to fill with the XML data. I have declared the table "it_airplus" like the structure from XML file definition for a better overview, because it is a long XML Definition (see the XSD file in the sample ZIP container by airplus.com)
see the complete report: Read data from XML file via XSLT program
Create XSLT program
There are two options to create a XSLT program:
- Tcode: SE80 -> create/choose packet -> right click on it | Create -> Others -> XSL Transformation
- Tcode: XSLT_TOOL
For a quick overview you can watch at the SXSLTDEMO* programs.
In this example we already use the three XSLT options explained later.
As you can see we define a XSL and ASX (ABAP) tags to handle the ABAP and XML variables/tags. After "<asx:values>" we create the XML_OUTPUT tag, but in this case we also could speak about a container. In fact the XML_OUTPUT tag comprise the structure of the internal table "it_airplus" which where moved by the CALL TRANSFORMATION in the report.
See the whole XSLT program here: XSLT sample to encode, decode XML file
Here are the relevant XSLT elements in order of you could need it in your own program. For a good XSLT reference look at W3Schools.com - reference. In a XSLT program it is also possible to to write comments with the standard HTML commentfunction "<!- your comment here ->".
to catch the value from the element/attribute and move it to the ABAP variable
use this element to make loops over your XML Tags, maybe if you have more than one XML tag (street) in your XML-File
create a variable for access to the XML element. It is just a nice shortcut. Note that you can close this XSL element it self, look at the slash before the >
continuative the "for-each" element you can write it like this:
XML sample file
We take the sample file from Airplus. You can load the sample ZIP container by Airplus at: airplus.com -> products -> pay -> airplus electronic billing -> XML.