2014 Jul 21 5:39 PM
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
2014 Jul 22 12:11 AM
Hello Goncalo,
I think, there are two problems:
1) The xmlns declaration within your xml is a problem for the SAP XSLT Processor.
2) I have written a similar XSLT-report, which performs directly with your data. Perhaps this is not necessary if 1) is solved:
<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="AuditFile">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<xsl:apply-templates select="MasterFiles"/>
</asx:values>
</asx:abap>
</xsl:template>
<xsl:template match="MasterFiles">
<ICUSTOMER>
<xsl:apply-templates select="./Customer"/>
</ICUSTOMER>
</xsl:template>
<xsl:template match="Customer">
<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>
...
</xsl:template>
</xsl:transform>
Kind regards,
Hendrik
2014 Jul 22 12:11 AM
Hello Goncalo,
I think, there are two problems:
1) The xmlns declaration within your xml is a problem for the SAP XSLT Processor.
2) I have written a similar XSLT-report, which performs directly with your data. Perhaps this is not necessary if 1) is solved:
<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="AuditFile">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<xsl:apply-templates select="MasterFiles"/>
</asx:values>
</asx:abap>
</xsl:template>
<xsl:template match="MasterFiles">
<ICUSTOMER>
<xsl:apply-templates select="./Customer"/>
</ICUSTOMER>
</xsl:template>
<xsl:template match="Customer">
<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>
...
</xsl:template>
</xsl:transform>
Kind regards,
Hendrik
2014 Jul 22 10:16 AM
Hi Hendrik,
thanks for your help.
I tried using your version of the XSLT report, but I got this error:
The element {http://www.sap.com/abapxml was exepected for the XML-ABAP transformation
You also mentioned the problem might be in the xlmns declaration in the xml. Could you explain what is wrong or what might be the problem? I might be able to correct the XML directly...
Thank you,
Gonçalo
2014 Jul 22 10:31 AM
Hello Gonçalo,
the XSLT error at your side is the missing xmlns declaration for the asx element.
I could get your example running by removing all xmlns declaration within your source xml-file. Add the missing asx namespace and try the xml-file without xmlns declarations within the xml-tags
Kind regards,
Hendrik
2014 Jul 22 11:44 AM
Hi Hendrik,
Sorry to keep bothering you, but I still haven't been able to solve the problem.
XML / XSLT isn't really my thing...
I did as you suggested and removed all xmlns declarations from the XML source file but didn't quite follow with the 'missing asx namespace'? I've been using your XSLT to run the transformation.
If I try to call the transformation having removed all the xmlns declarations from XML source file I get the following error:
Unexpected text for XML-ABAP Transformation
Thanks again,
Gonçalo
2014 Jul 22 12:26 PM
Hi Gonçalo,
no problem. I also does not pretend to know evertything of XSLT and XML 😉
I have checked my local example, which has been the base of my answers. Could it be, that you have taken the "..." of my answer within your xslt-Transformation? Can this transformation be activated?
Kind regards,
Hendrik
2014 Jul 22 5:22 PM
Hi Hendrik,
I have solved the issue. I used the XML source file without the xmlns declarations as you said and at the same time went back to using my original XSLT and somehow it worked!
So, problem solved. Thank you for all your help!
Best regards,
Gonçalo
2014 Oct 24 6:42 PM
Hi Hendrik & Gonçalo,
I also had the same problem and I got it fixed by introducing <item> tag in the output for each line of internal table.
Thanks,
Kirubakaran T.