Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8689

Writing XSLT to perform transformation from XML to ABAP

$
0
0

Hi,

 

I've been struggling quite a bit with XSLT. I read several old discussions regarding transformations using ST and XSLT but I haven't been able to solve my problem.

 

I have a requirement to build a program to convert XML to an internal table.

 

I've been able to do it for smaller XMLs, but whenever I try to apply the same logic to a bigger XML it simply just doesn't work. I'm almost certain it has something to do with the way I wrote the XSLT but I haven't been able to figure out what.

 

The XML I have to read from goes something like this:

 

 

<?xml version="1.0" encoding="WINDOWS-1252"?>

 

 

-<AuditFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:OECD:StandardAuditFile-Tax:PT_1.02_01">

 

     -<Header xmlns="urn:OECD:StandardAuditFile-Tax:PT_1.02_01">

 

          <AuditFileVersion>1.02_01</AuditFileVersion>

 

 

               <CompanyID>50002</CompanyID>

 

 

               <TaxRegistrationNumber>5000</TaxRegistrationNumber>

 

 

               <TaxAccountingBasis>F</TaxAccountingBasis>

 

 

               <CompanyName>Company</CompanyName>

 

 

               <BusinessName>Business</BusinessName>

 

 

               -<CompanyAddress>

 

 

                    <AddressDetail>Address</AddressDetail>

 

 

                    <City>city</City>

 

 

                    <PostalCode>333333</PostalCode>

 

 

                    <Country>PT</Country>

 

 

               </CompanyAddress>

 

 

               <FiscalYear>2013</FiscalYear>

 

 

               <StartDate>2013-07-01</StartDate>

 

 

               <EndDate>2013-07-31</EndDate>

 

 

               <CurrencyCode>EUR</CurrencyCode>

 

 

               <DateCreated>2013-08-02</DateCreated>

 

 

               <TaxEntity>Global</TaxEntity>

 

 

               <ProductCompanyTaxID>00</ProductCompanyTaxID>

 

 

               <SoftwareCertificateNumber>00</SoftwareCertificateNumber>

 

 

               <ProductID>product</ProductID>

 

 

               <ProductVersion>00</ProductVersion>

 

 

              <Email>email@com</Email>

 

 

               <Website>www.s.pt</Website>

 

 

     </Header>

 

 

     -<MasterFiles xmlns="urn:OECD:StandardAuditFile-Tax:PT_1.02_01">

 

 

          -<Customer>

 

 

               <CustomerID>1</CustomerID>

 

 

               <AccountID>ID</AccountID>

 

 

               <CustomerTaxID>999999990</CustomerTaxID>

 

 

               <CompanyName>Desconhecido</CompanyName>

 

               -<BillingAddress>

 

 

                    <AddressDetail>Desconhecido</AddressDetail>

 

 

                    <City>Desconhecido</City>

 

 

                    <PostalCode>0000-000</PostalCode>

 

 

                    <Country>PT</Country>

 


               </BillingAddress>

 

 

               <SelfBillingIndicator>0</SelfBillingIndicator>

 

 

          </Customer>

 

          -<Customer>

 

 

               <CustomerID>2</CustomerID>

 

 

               <AccountID>Desconhecido</AccountID>

 

 

               <CustomerTaxID>571</CustomerTaxID>

 

 

               <CompanyName>Company</CompanyName>

 

 

               -<BillingAddress>

 

 

                    <AddressDetail>detail</AddressDetail>

 

 

                    <City>city</City>

 

 

                    <PostalCode>0000-000</PostalCode>

 

 

                   <Country>PT</Country>

 

 

           </BillingAddress>

 

 

          <SelfBillingIndicator>0</SelfBillingIndicator>

 

 

     </Customer>

 

 

...and so on

 

 

 

And the XSLT I've written so far is something like this:

 

 

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

   <xsl:output encoding="iso-8859-1" indent="yes" method="xml" version="1.0"/>

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

 

   <xsl:template match="/">

     <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">

       <asx:values>

         <ICUSTOMER>

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

         </ICUSTOMER>

       </asx:values>

     </asx:abap>

   </xsl:template>

 

   <xsl:template match="Customer">

     <item>

       <CUSTOMER_ID>

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

       </CUSTOMER_ID>

       <ACCOUNT_ID>

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

       </ACCOUNT_ID>

       <CUSTOMERTAX_ID>

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

       </CUSTOMERTAX_ID>

       <COMPANYNAME>

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

       </COMPANYNAME>

 

       <ADDRESSDETAIL>

         <xsl:value-of select="BillingAddress/AddressDetail"/>

       </ADDRESSDETAIL>

       <CITY>

         <xsl:value-of select="BillingAddress/City"/>

       </CITY>

        <POSTALCODE>

         <xsl:value-of select="BillingAddress/PostalCode"/>

       </POSTALCODE>

        <COUNTRY>

         <xsl:value-of select="BillingAddress/Country"/>

       </COUNTRY>

 

       <SELFBILLINGINDICATOR>

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

       </SELFBILLINGINDICATOR>

     </item>

   </xsl:template>

</xsl:transform>

 

Like I said, I'm almost certain that the problem is with the XSLT, as it returns an empty table / ALV. I've used this method before and it worked...

 

Any thoughts?

 

Thank you


Viewing all articles
Browse latest Browse all 8689

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>