2016 Jan 04 8:33 PM
Hello everyone.
I need help with a transformation from ABAP to an XML file using XSLT.
I can't make loops correctly.
Here's my ABAP code:
TYPES: BEGIN OF ty_asigsol,
serie(4),
docnm(8),
emisi(21),
numau(15),
feres(10),
rgini(6),
rgfin(6),
END OF ty_asigsol,
BEGIN OF ty_detalle,
arktx(40),
ean11(18),
END OF ty_detalle,
tt_detalles TYPE STANDARD TABLE OF ty_detalle WITH DEFAULT KEY,
* DATA: lt_detalles TYPE TABLE OF ty_detalle.
BEGIN OF ty_factdocgt,
version(1),
asigsol TYPE ty_asigsol,
detalles TYPE tt_detalles,
END OF ty_factdocgt.
DATA: lt_factdocgt TYPE TABLE OF ty_factdocgt.
FIELD-SYMBOLS: <fs_fact> TYPE ty_factdocgt.
**** Here is where I fill the table ****
**** I need a XML file per row of the table, right now for testing purposes I only read the first row:
READ TABLE lt_factdocgt ASSIGNING <fs_fact> INDEX 1.
CALL TRANSFORMATION zxml_gt_factura
SOURCE factdocgt = <fs_fact>
RESULT XML xml_result1 .
And here's my XSLT program:
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" exclude-result-prefixes="asx asx:abap asx:values" version="1.0">
<xsl:output indent="yes" method="xml" version="1.0"/>
<xsl:strip-space elements="*"/>
<xsl:template match="FACTDOCGT">
<FactDocGT xmlns="http://www.fact.com.mx/schema/gt" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.fact.com.mx/schema/gt http://www.mysuitemex.com/fact/schema/fx_201">
<Version>
<xsl:value-of select="VERSION"/>
</Version>
<AsignacionSolicitada>
<Serie>
<xsl:value-of select="ASIGSOL/SERIE"/>
</Serie>
<NumeroDocumento>
<xsl:value-of select="ASIGSOL/DOCNM"/>
</NumeroDocumento>
<FechaEmision>
<xsl:value-of select="ASIGSOL/EMISI"/>
</FechaEmision>
<NumeroAutorizacion>
<xsl:value-of select="ASIGSOL/NUMAU"/>
</NumeroAutorizacion>
<FechaResolucion>
<xsl:value-of select="ASIGSOL/FERES"/>
</FechaResolucion>
<RangoInicialAutorizado>
<xsl:value-of select="ASIGSOL/RGINI"/>
</RangoInicialAutorizado>
<RangoFinalAutorizado>
<xsl:value-of select="ASIGSOL/RGFIN"/>
</RangoFinalAutorizado>
</AsignacionSolicitada>
<Detalles>
<xsl:for-each select="DETALLES">
<Detalle>
<Descripcion>
<xsl:value-of select="ARKTX" />
</Descripcion>
</Detalle>
</xsl:for-each>
</Detalles>
</FactDocGT>
</xsl:template>
</xsl:transform>
I use the following to loop of detalles table and print his arktx variable, but I cant get it done.
<xsl:for-each select="DETALLES">
<Detalle>
<Descripcion>
<xsl:value-of select="ARKTX" />
</Descripcion>
</Detalle>
</xsl:for-each>
My output is the following:
<?xml version="1.0" encoding="UTF-8"?>
<FactDocGT xsi:schemaLocation="http://www.fact.com.mx/schema/gt http://www.mysuitemex.com/fact/schema/fx_201" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.fact.com.mx/schema/gt">
<Version>2</Version>
<AsignacionSolicitada>
<Serie>30</Serie>
<NumeroDocumento>0000024</NumeroDocumento>
<FechaEmision>2015-12-15T15:08:15</FechaEmision>
<NumeroAutorizacion>2014-5-535-1847</NumeroAutorizacion>
<FechaResolucion>25/11/2014</FechaResolucion>
<RangoInicialAutorizado>2001</RangoInicialAutorizado>
<RangoFinalAutorizado>3000</RangoFinalAutorizado>
</AsignacionSolicitada>
<Detalles>
<Detalle>
<Descripcion/>
</Detalle>
</Detalles>
</FactDocGT>
What I am doing wrong?
Please help!
2016 Jan 05 4:04 PM
Hi,
If you are referring to the missing value of the description in the ouput XML then please see below:
In the Debugging mode you can see that there is a new Tag called <item> after the <DETALLES> Tag in the incoming XML:
Enclosed here for your reference:
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<FACTDOCGT>
<VERSION>2</VERSION>
<ASIGSOL>
<SERIE>30</SERIE>
<DOCNM>24</DOCNM>
<EMISI>2015-12-15T15:08:15</EMISI>
<NUMAU>2014-5-535-1847</NUMAU>
<FERES>25/11/2014</FERES>
<RGINI>2001</RGINI>
<RGFIN>3000</RGFIN>
</ASIGSOL>
<DETALLES>
<item>
<ARKTX>test123</ARKTX>
<EAN11>12354</EAN11>
</item>
</DETALLES>
</FACTDOCGT>
</asx:values>
</asx:abap>
Now you can see that the description is not printed as it is under the TAG : <item>.
So, just Change the XSLT as below for description:
<xsl:value-of select="item/ARKTX" />
Then you will get the value in the description.
Regards,
Pallavi
2016 Jan 05 4:04 PM
Hi,
If you are referring to the missing value of the description in the ouput XML then please see below:
In the Debugging mode you can see that there is a new Tag called <item> after the <DETALLES> Tag in the incoming XML:
Enclosed here for your reference:
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<FACTDOCGT>
<VERSION>2</VERSION>
<ASIGSOL>
<SERIE>30</SERIE>
<DOCNM>24</DOCNM>
<EMISI>2015-12-15T15:08:15</EMISI>
<NUMAU>2014-5-535-1847</NUMAU>
<FERES>25/11/2014</FERES>
<RGINI>2001</RGINI>
<RGFIN>3000</RGFIN>
</ASIGSOL>
<DETALLES>
<item>
<ARKTX>test123</ARKTX>
<EAN11>12354</EAN11>
</item>
</DETALLES>
</FACTDOCGT>
</asx:values>
</asx:abap>
Now you can see that the description is not printed as it is under the TAG : <item>.
So, just Change the XSLT as below for description:
<xsl:value-of select="item/ARKTX" />
Then you will get the value in the description.
Regards,
Pallavi
2016 Jan 12 8:09 PM