Skip to Content
0
Former Member
Mar 02, 2008 at 02:35 PM

ABAP Program that generates XML and calls an XSLT transformation,

293 Views

Hello,

I am creating a program that creates some XML output, and I am using STRANS to create a transformation.

The file created looks like below before transformation.

<?xml version="1.0" encoding="utf-8" ?>

- http://www.sap.com/abapxml" version="1.0">

- <asx:values>

- <EMPLOYEE_DATA>

- <item>

<EMPLOYEE_ID>00000010</EMPLOYEE_ID>

<FIRSTNAME>Joe</FIRSTNAME>

<SURNAME>Bloggs</SURNAME>

<DOB>1940-11-10</DOB>

<SALARY>200000.0</SALARY>

</item>

<item>

<EMPLOYEE_ID>00000055</EMPLOYEE_ID>

<FIRSTNAME>Lydia</FIRSTNAME>

<SURNAME>Jones</SURNAME>

<DOB>1965-03-09</DOB>

<SALARY>90000.0</SALARY>

</item>

</EMPLOYEE_DATA>

</asx:values>

</asx:abap>

I want to make EMPLOYEE_ID an attribute like in the following

and what I want to output is:

<?xml version="1.0" encoding="utf-8" ?>

- http://www.sap.com/abapxml">

- <asx:values>

- <EMPLOYEE_DATA>

- <EMPLOYEE_DETAILS EMPLOYEE_ID="00000010">

<FIRSTNAME>Joe</FIRSTNAME>

<SURNAME>Bloggs</SURNAME>

<DOB>1940-11-10</DOB>

<SALARY>200000.0</SALARY>

</EMPLOYEE_DETAILS>

<EMPLOYEE_DETAILS EMPLOYEE_ID="00000055">

<FIRSTNAME>Lydia</FIRSTNAME>

<SURNAME>Jones</SURNAME>

<DOB>1965-03-09</DOB>

<SALARY>90000.0</SALARY>

</EMPLOYEE_DETAILS>

</EMPLOYEE_DATA>

</asx:values>

</asx:abap>

the XSLT I have cureently produces:

<?xml version="1.0" encoding="utf-8" ?>

- http://www.sap.com/abapxml">

- <asx:values>

- <EMPLOYEE_DATA>

- <EMPLOYEE_DETAILS EMPLOYEE_ID="00000010">

<EMPLOYEE_ID>00000010</EMPLOYEE_ID>

<FIRSTNAME>Joe</FIRSTNAME>

<SURNAME>Bloggs</SURNAME>

<DOB>1940-11-10</DOB>

<SALARY>200000.0</SALARY>

</EMPLOYEE_DETAILS>

- <EMPLOYEE_DETAILS EMPLOYEE_ID="00000038">

<EMPLOYEE_ID>00000038</EMPLOYEE_ID>

<FIRSTNAME>Fred</FIRSTNAME>

<SURNAME>Johnson</SURNAME>

<DOB>1960-12-11</DOB>

<SALARY>123450.0</SALARY>

</EMPLOYEE_DETAILS>

- <EMPLOYEE_DETAILS EMPLOYEE_ID="00000055">

<EMPLOYEE_ID>00000055</EMPLOYEE_ID>

<FIRSTNAME>Lydia</FIRSTNAME>

<SURNAME>Jones</SURNAME>

<DOB>1965-03-09</DOB>

<SALARY>90000.0</SALARY>

</EMPLOYEE_DETAILS>

</EMPLOYEE_DATA>

</asx:values>

</asx:abap>

But it is repeating the Employee_ID, I want it to start from Firstname, the XSLT I have is:

http://www.w3.org/1999/XSL/Transform" xmlns:sap=" http://www.sap.com/sapxsl" version="1.0">

<xsl:strip-space elements="*"/>

<xsl:template match="node()">

<xsl:copy>

<xsl:apply-templates select="node()"/>

</xsl:copy>

</xsl:template>

<xsl:template match="item">

<EMPLOYEE_DETAILS>

<xsl:attribute name="EMPLOYEE_ID">

<xsl:value-of select="EMPLOYEE_ID"/>

</xsl:attribute>

<xsl:apply-templates select="node()"/>

</EMPLOYEE_DETAILS>

</xsl:template>

</xsl:transform>

How do I get it to start from the next node?

Thanks