Skip to Content

Special characteristics of XSLT in ABAP/SAP?

Feb 15, 2017 at 08:25 AM


avatar image

Hey everyone,

after my last approach of working with SAP Simple Transformations ( I'm now working with an incoming XML and a XSLT Transformation. It should use the input XML and transform it into a SAP structure.

My XML (shortened example):

        <serverTimePretty>Feb 12, 2017 23:55:14</serverTimePretty>

My XSLT (also shortened, but the problem is shown):

<xsl:transform version="1.0" xmlns:xsl="" xmlns:sap="">
<xsl:strip-space elements="*"/>
<xsl:template match="/">
  <asx:abap xmlns:asx="" version="1.0">
        <xsl:for-each select="result/row">
            <SERVERDATE> <xsl:value-of select="serverDate"/> </SERVERDATE>
            <USERID>  <xsl:value-of select="userId"/>      </USERID>
            <VISITORTYPE><xsl:value-of select="visitorType"/> </VISITORTYPE>
            <SEARCHES>    <xsl:value-of select="searches"/> </SEARCHES>
            <ACTIONS> <xsl:value-of select="actions"/>  </ACTIONS>
            <xsl:for-each select="actionDetails">
              <xsl:variable name="row" select="row" />
                <TYPE> <xsl:value-of select="$row/type"/> </TYPE>
                <URL> <xsl:value-of select="$row/url"/> </URL>
                <GOALNAME><xsl:value-of select="$row/goalName"/></GOALNAME>
                <ITEMS> <xsl:value-of select="$row/items"/> </ITEMS>
                <xsl:for-each select="itemDetails/row">
                    <ITEMSKU> <xsl:value-of select="itemSKU"/></ITEMSKU>
                    <ITEMNAME><xsl:value-of select="itemName"/></ITEMNAME>
            <RESULT>  <xsl:value-of select="result"/> </RESULT>
            <MESSAGE> <xsl:value-of select="message"/> </MESSAGE>

Problem: Once it reaches the first xsl:value-of inside of the inner for-each (at TYPE), it crashes and the debugger throws an CX_XSLT_FORMAT_ERROR. Without debugging it just says "Unexpected text for XML-ABAP transformation."

When I validate my files with an online XSLT Validator (, it does work fine.

Now my assumption/question: Are there some SAP-specific rules for XSLT or XPath I need to follow? I would say so, because it works outside of SAP. I tried to find any solution for this, but without success.

Thanks in advance and kind regards

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Timo Stegmeier Feb 17, 2017 at 07:21 AM

Got it:

   <xsl:for-each select="actionDetails/row">
           <TYPE>              <xsl:value-of select="type"/>               </TYPE>

For creating data for an internal table, I needed a parent node <ACTIONDETAILS> to add a collection of child elements <ACTIONDETAIL>.

I still can't explain though why it validated in both an online validator and the XSLT tester in SAP.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Please close the question.

PS: from the XML point of view, it's not an error to not have <ACTIONDETAILS>. But you must have it because of ABAP, containing the name of the internal table (by the way you didn't show the description of your target ABAP variable): <ITABNAME><xsl:for-each ...><item>...</item></xsl-for-each></ITABNAME> (name "item" may vary depending on the rule explained in asXML - Mapping of Internal Tables).