Skip to Content
0
Former Member
Apr 28, 2009 at 11:09 AM

XSLT Transformation

51 Views

Hi All

I need to read .XML File using XSLT Transformation ,

The Input file which I have in this format. Header-1 Detail -2 Trailer - 1

<CUSTOMER>

<INPUT_HEADER>

<ID>..</ID>

</INPUT_HEADER>

<INPUT_DETAIL>

<COMPANY_CODE>...</COMPANY_CODE>

<CUST_ID>...</CUST_ID>

</INPUT_DETAIL>

<INPUT_DETAIL>

<COMPANY_CODE>...</COMPANY_CODE>

<CUST_ID>...</CUST_ID>

</INPUT_DETAIL>

<INPUT_TRAILER>

<TOTAL>..</TOTAL>

</INPUT_TRAILER>

</CUSTOMER>

The code which I have written below is in this format. when I execute this code . the detail lines are duplicated.

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

<xsl:output cdata-section-elements="*" indent="yes" omit-xml-declaration="yes"/>

<xsl:template match="/">

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

<asx:values>

<CUSTOMER>

<xsl:apply-templates select="//INPUT_HEADER"/>

<xsl:apply-templates select="//INPUT_DETAIL"/>

<xsl:apply-templates select="//INPUT_TRAILER"/>

</CUSTOMER>

</asx:values>

</asx:abap>

</xsl:template>

<xsl:template match="//INPUT_HEADER">

<xsl:element name="HEADER">

<xsl:element name="ID">

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

</xsl:element>

</xsl:element>

</xsl:template>

<xsl:template match="//INPUT_DETAIL">

<xsl:for-each select="//INPUT_DETAIL">

<xsl:element name="DETAIL">

<xsl:element name="BUKRS">

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

</xsl:element>

<xsl:element name="KUNNR">

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

</xsl:element>

</xsl:element>

</xsl:for-each>

</xsl:template>

<xsl:template match="//INPUT_TRAILER">

<xsl:element name="TRAILER">

<xsl:element name="TOTAL">

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

</xsl:element>

</xsl:element>

</xsl:template>

It would be helpful if any one suggest me how to avoid the duplicate items in <DETAIL> Element .

Thanks