04-18-2023 12:17 PM
We are trying to implement XSL transformation using this reference article. https://blogs.sap.com/2018/09/10/xslt-transformations-xml-2-abap-a-working-example/
The only issue we have so far is that when we put the XML into a namespace, we start getting ABAP dump that mentions "root tag <abap> must be in the XML namespace "http://www.sap.com/abapxml"."
Any pointers would be helpful.
XML
<?xml version="1.0" encoding="UTF-8"?>
<ns0:File xmlns:ns0="www.sap.com">
<Head>
<Name>K. Richards</Name>
</Head>
<Items>
<ITM QTY="23" EAN="123123123123" CAT="BL"/>
<ITM QTY="100" EAN="123123123123" CAT=""/>
<ITM QTY="240" EAN="123123123123" CAT=""/>
<ITM QTY="989" EAN="123123123123" CAT=""/>
<ITM QTY="1000" EAN="123123123123" CAT=""/>
<ITM QTY="5" EAN="123123123123" CAT="BL"/>
<ITM QTY="50" SOH="4000299949" EAN="123123123123" SOI="000010" CAT=""/>
<ITM QTY="140" EAN="123123123123" CAT=""/>
<ITM QTY="420" EAN="123123123123" CAT="QI"/>
<ITM QTY="30" EAN="123123123123" CAT=""/>
<ITM QTY="20" EAN="123123123123" CAT="QI"/>
<ITM QTY="475" SOH="4000299949" EAN="123123123123" SOI="000040" CAT=""/>
<ITM QTY="300" EAN="123123123123" CAT=""/>
<ITM QTY="994" EAN="123123123123" CAT=""/>
<ITM QTY="24" EAN="123123123123" CAT="BL"/>
<ITM QTY="3" EAN="123123123123" CAT="BL"/>
<ITM QTY="441" EAN="123123123123" CAT=""/>
<ITM QTY="240" EAN="123123123123" CAT="QI"/>
<ITM QTY="5" EAN="123123123123" CAT=""/>
<ITM QTY="102" EAN="123123123123" CAT="BL"/>
<ITM QTY="2" EAN="123123123123" CAT=""/>
<ITM QTY="360" EAN="123123123123" CAT="QI"/>
<ITM QTY="403" EAN="123123123123" CAT=""/>
<ITM QTY="425" SOH="123123123123" EAN="6941023243415" SOI="000030" CAT=""/>
<ITM QTY="100" EAN="123123123123" CAT=""/>
<ITM QTY="220" EAN="123123123123" CAT=""/>
<ITM QTY="1000" EAN="123123123123" CAT=""/>
<ITM QTY="25" SOH="4000299949" EAN="123123123123" SOI="000020" CAT="BL"/>
<ITM QTY="425" SOH="4000299949" EAN="123123123123" SOI="000020" CAT=""/>
<ITM QTY="340" EAN="123123123123" CAT=""/>
<ITM QTY="1" EAN="123123123123" CAT="BL"/>
</Items>
</ns0:File>
XSLT
<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="ns0:File">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<FILE> <!--FILE Needs to match name of RESULT variable in CALL TRANSFORMATION call-->
<xsl:for-each select="/File">
<!-- <DUMMY1> = Dummy, not in ABAP structure-->
<DUMMY1>
<HEAD>
<NAME>
<xsl:value-of select="Head/Name"/>
</NAME>
</HEAD>
<ITEMS>
<xsl:for-each select="Items/ITM">
<DUMMY2>
<!-- <DUMMY2> = Dummy, not in ABAP structure-->
<QTY>
<!-- @ = Attribute of element rather than element-->
<xsl:value-of select="@QTY"/>
</QTY>
<SOH>
<xsl:value-of select="@SOH"/>
</SOH>
<EAN>
<xsl:value-of select="@EAN"/>
</EAN>
<SOI>
<xsl:value-of select="@SOI"/>
</SOI>
<CAT>
<xsl:value-of select="@CAT"/>
</CAT>
</DUMMY2>
</xsl:for-each>
</ITEMS>
</DUMMY1>
</xsl:for-each>
</FILE>
</asx:values>
</asx:abap>
</xsl:template>
</xsl:transform>
05-03-2023 2:45 AM
We got solution for this, it was a minor miss - the XML namespace was missing in the transformation. Once that is added, you simple use the name space to access the node in <xsl:template match>
This is the correct XSLT
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0" xmlns:ns0="www.sap.com">
<xsl:strip-space elements="*"/>
<xsl:template match="ns0:File">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<FILE> <!--FILE Needs to match name of RESULT variable in CALL TRANSFORMATION call-->
<xsl:for-each select="//ns0:File">
<!-- <DUMMY1> = Dummy, not in ABAP structure-->
<DUMMY1>
<HEAD>
<NAME>
<xsl:value-of select="Head/Name"/>
</NAME>
</HEAD>
<ITEMS>
<xsl:for-each select="Items/ITM">
<DUMMY2>
<!-- <DUMMY2> = Dummy, not in ABAP structure-->
<QTY>
<!-- @ = Attribute of element rather than element-->
<xsl:value-of select="@QTY"/>
</QTY>
<SOH>
<xsl:value-of select="@SOH"/>
</SOH>
<EAN>
<xsl:value-of select="@EAN"/>
</EAN>
<SOI>
<xsl:value-of select="@SOI"/>
</SOI>
<CAT>
<xsl:value-of select="@CAT"/>
</CAT>
</DUMMY2>
</xsl:for-each>
</ITEMS>
</DUMMY1>
</xsl:for-each>
</FILE>
</asx:values>
</asx:abap>
</xsl:template>
</xsl:transform>
05-03-2023 2:45 AM
We got solution for this, it was a minor miss - the XML namespace was missing in the transformation. Once that is added, you simple use the name space to access the node in <xsl:template match>
This is the correct XSLT
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0" xmlns:ns0="www.sap.com">
<xsl:strip-space elements="*"/>
<xsl:template match="ns0:File">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<FILE> <!--FILE Needs to match name of RESULT variable in CALL TRANSFORMATION call-->
<xsl:for-each select="//ns0:File">
<!-- <DUMMY1> = Dummy, not in ABAP structure-->
<DUMMY1>
<HEAD>
<NAME>
<xsl:value-of select="Head/Name"/>
</NAME>
</HEAD>
<ITEMS>
<xsl:for-each select="Items/ITM">
<DUMMY2>
<!-- <DUMMY2> = Dummy, not in ABAP structure-->
<QTY>
<!-- @ = Attribute of element rather than element-->
<xsl:value-of select="@QTY"/>
</QTY>
<SOH>
<xsl:value-of select="@SOH"/>
</SOH>
<EAN>
<xsl:value-of select="@EAN"/>
</EAN>
<SOI>
<xsl:value-of select="@SOI"/>
</SOI>
<CAT>
<xsl:value-of select="@CAT"/>
</CAT>
</DUMMY2>
</xsl:for-each>
</ITEMS>
</DUMMY1>
</xsl:for-each>
</FILE>
</asx:values>
</asx:abap>
</xsl:template>
</xsl:transform>