‎2012 Feb 02 8:38 PM
I have the following ABAP Xslt transformation
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sap="http://www.sap.com/sapxsl" version="1.0"
>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<ALLIR_REIKNINGAR>
<xsl:apply-templates select="//Invoice"/>
</ALLIR_REIKNINGAR>
</asx:values>
</asx:abap>
</xsl:template>
<xsl:template match="Invoice">
<REIKNINGUR>
<REIKN_NUMER>
<xsl:value-of select="cbc:ID"/>
</REIKN_NUMER>
<REIKN_AFRIT>
<xsl:value-of select="cbc:CopyIndicator"/>
</REIKN_AFRIT>
<REIKN_UTGAFUDAGS>
<xsl:value-of select="cbc:IssueDate"/>
</REIKN_UTGAFUDAGS>
<REIKN_MYNT>
<xsl:value-of select="cbc:DocumentCurrencyCode"/>
</REIKN_MYNT>
<REIKN_TIMABIL_FRA>
<xsl:value-of select="cac:InvoicePeriod/cbc:StartDate"/>
</REIKN_TIMABIL_FRA>
<REIKN_TIMABIL_TIL>
<xsl:value-of select="cac:InvoicePeriod/cbc:EndDate"/>
</REIKN_TIMABIL_TIL>
</REIKNINGUR>
</xsl:template>
</xsl:transform>
And the following XML input file
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="vodafone_xslt_namespace.xslt"?>
<Invoice
xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2"
xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ccts="urn:un:unece:uncefact:documentation:2"
xmlns:stat="urn:oasis:names:specification:ubl:schema:xsd:DocumentStatusCode-1.0"
xmlns:clm5639="urn:un:unece:uncefact:codelist:specification:5639:1988"
xmlns:clm54217="urn:un:unece:uncefact:codelist:specification:54217:2001"
xmlns:clm66411="urn:un:unece:uncefact:codelist:specification:66411:2001"
xmlns:clmIANAMIMEMediaType="urn:un:unece:uncefact:codelist:specification:IANAMIMEMediaType:2003"
>
<cbc:UBLVersionID>2.0</cbc:UBLVersionID>
<cbc:CustomizationID>NES</cbc:CustomizationID>
<cbc:ProfileID schemeID="Profile"
schemeAgencyID="NES">urn:www.nesubl.eu:profiles:profile4:ver1.1</cbc:ProfileID>
<cbc:ID>PB1554421</cbc:ID>
<cbc:CopyIndicator>false</cbc:CopyIndicator>
<cbc:IssueDate>2011-12-31</cbc:IssueDate>
<cbc:InvoiceTypeCode listID="UN/ECE 1001 Restricted" listAgencyID="NES">380</cbc:InvoiceTypeCode>
<cbc:Note languageID="IS">Company name</cbc:Note>
<cbc:DocumentCurrencyCode listID="ISO 4217 Alpha">ISK</cbc:DocumentCurrencyCode>
<cbc:AccountingCost>2001523</cbc:AccountingCost>
<cac:InvoicePeriod>
<cbc:StartDate>2011-12-01</cbc:StartDate>
<cbc:EndDate>2011-12-31</cbc:EndDate>
</cac:InvoicePeriod>
</Invoice>
My problem is that this transformation does not work unless I completly strip out the namespace parts i.e. cbc:
How can I get the parser to read the tags with namespace part. And if the parser can not handle namespace in XML how can I go about reding the data into sap ?
‎2012 Feb 03 1:13 PM
You need to put namspaces inside <xsl:transform> tag, bellow is the correct XSLT for you:
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:inv="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2"
xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ccts="urn:un:unece:uncefact:documentation:2"
xmlns:stat="urn:oasis:names:specification:ubl:schema:xsd:DocumentStatusCode-1.0"
xmlns:clm5639="urn:un:unece:uncefact:codelist:specification:5639:1988"
xmlns:clm54217="urn:un:unece:uncefact:codelist:specification:54217:2001"
xmlns:clm66411="urn:un:unece:uncefact:codelist:specification:66411:2001"
xmlns:clmIANAMIMEMediaType="urn:un:unece:uncefact:codelist:specification:IANAMIMEMediaType:2003"
xmlns:sapxsl="http://www.sap.com/sapxsl"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<ALLIR_REIKNINGAR>
<xsl:apply-templates select="//inv:Invoice"/>
</ALLIR_REIKNINGAR>
</asx:values>
</asx:abap>
</xsl:template>
<xsl:template match="inv:Invoice">
<REIKNINGUR>
<REIKN_NUMER>
<xsl:value-of select="cbc:ID"/>
</REIKN_NUMER>
<REIKN_AFRIT>
<xsl:value-of select="cbc:CopyIndicator"/>
</REIKN_AFRIT>
<REIKN_UTGAFUDAGS>
<xsl:value-of select="cbc:IssueDate"/>
</REIKN_UTGAFUDAGS>
<REIKN_MYNT>
<xsl:value-of select="cbc:DocumentCurrencyCode"/>
</REIKN_MYNT>
<REIKN_TIMABIL_FRA>
<xsl:value-of select="cac:InvoicePeriod/cbc:StartDate"/>
</REIKN_TIMABIL_FRA>
<REIKN_TIMABIL_TIL>
<xsl:value-of select="cac:InvoicePeriod/cbc:EndDate"/>
</REIKN_TIMABIL_TIL>
</REIKNINGUR>
</xsl:template>
</xsl:transform>
‎2012 Feb 03 1:13 PM
You need to put namspaces inside <xsl:transform> tag, bellow is the correct XSLT for you:
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:inv="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2"
xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ccts="urn:un:unece:uncefact:documentation:2"
xmlns:stat="urn:oasis:names:specification:ubl:schema:xsd:DocumentStatusCode-1.0"
xmlns:clm5639="urn:un:unece:uncefact:codelist:specification:5639:1988"
xmlns:clm54217="urn:un:unece:uncefact:codelist:specification:54217:2001"
xmlns:clm66411="urn:un:unece:uncefact:codelist:specification:66411:2001"
xmlns:clmIANAMIMEMediaType="urn:un:unece:uncefact:codelist:specification:IANAMIMEMediaType:2003"
xmlns:sapxsl="http://www.sap.com/sapxsl"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<ALLIR_REIKNINGAR>
<xsl:apply-templates select="//inv:Invoice"/>
</ALLIR_REIKNINGAR>
</asx:values>
</asx:abap>
</xsl:template>
<xsl:template match="inv:Invoice">
<REIKNINGUR>
<REIKN_NUMER>
<xsl:value-of select="cbc:ID"/>
</REIKN_NUMER>
<REIKN_AFRIT>
<xsl:value-of select="cbc:CopyIndicator"/>
</REIKN_AFRIT>
<REIKN_UTGAFUDAGS>
<xsl:value-of select="cbc:IssueDate"/>
</REIKN_UTGAFUDAGS>
<REIKN_MYNT>
<xsl:value-of select="cbc:DocumentCurrencyCode"/>
</REIKN_MYNT>
<REIKN_TIMABIL_FRA>
<xsl:value-of select="cac:InvoicePeriod/cbc:StartDate"/>
</REIKN_TIMABIL_FRA>
<REIKN_TIMABIL_TIL>
<xsl:value-of select="cac:InvoicePeriod/cbc:EndDate"/>
</REIKN_TIMABIL_TIL>
</REIKNINGUR>
</xsl:template>
</xsl:transform>
‎2012 Feb 03 1:29 PM
Brilljant !
This solved the issue for me, actually I did test this solution but probably because of some other conflicting issue or not testing against the latest version. This did not seem to Work.
‎2012 Feb 03 3:46 PM
I think you are trying convert the xml to an internal table because of // in apply-templates, then you need to change last XSLT program and include <item> tag inside the <xsl:template match="inv:Invoice"> template, see updated XSLT bellow.
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:inv="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2"
xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ccts="urn:un:unece:uncefact:documentation:2"
xmlns:stat="urn:oasis:names:specification:ubl:schema:xsd:DocumentStatusCode-1.0"
xmlns:clm5639="urn:un:unece:uncefact:codelist:specification:5639:1988"
xmlns:clm54217="urn:un:unece:uncefact:codelist:specification:54217:2001"
xmlns:clm66411="urn:un:unece:uncefact:codelist:specification:66411:2001"
xmlns:clmIANAMIMEMediaType="urn:un:unece:uncefact:codelist:specification:IANAMIMEMediaType:2003"
xmlns:sapxsl="http://www.sap.com/sapxsl"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<ALLIR_REIKNINGAR>
<xsl:apply-templates select="//inv:Invoice"/>
</ALLIR_REIKNINGAR>
</asx:values>
</asx:abap>
</xsl:template>
<xsl:template match="inv:Invoice">
<item>
<REIKNINGUR>
<REIKN_NUMER>
<xsl:value-of select="cbc:ID"/>
</REIKN_NUMER>
<REIKN_AFRIT>
<xsl:value-of select="cbc:CopyIndicator"/>
</REIKN_AFRIT>
<REIKN_UTGAFUDAGS>
<xsl:value-of select="cbc:IssueDate"/>
</REIKN_UTGAFUDAGS>
<REIKN_MYNT>
<xsl:value-of select="cbc:DocumentCurrencyCode"/>
</REIKN_MYNT>
<REIKN_TIMABIL_FRA>
<xsl:value-of select="cac:InvoicePeriod/cbc:StartDate"/>
</REIKN_TIMABIL_FRA>
<REIKN_TIMABIL_TIL>
<xsl:value-of select="cac:InvoicePeriod/cbc:EndDate"/>
</REIKN_TIMABIL_TIL>
</REIKNINGUR>
</item>
</xsl:template>
</xsl:transform>
According to the XSLT program you need dclare an itab like this:
DATA: BEGIN OF ls_reikningur,
reikn_numer(10) TYPE c,
END OF ls_reikningur.
DATA: BEGIN OF ls_invoice,
reikningur LIKE ls_reikningur,
END OF ls_invoice.
DATA: lt_invoice LIKE TABLE OF ls_invoice.
And finally you need a call transformation in your abap code like this:
DATA: root_error TYPE REF TO cx_root.
DATA: lv_mess TYPE string.
TRY.
CALL TRANSFORMATION zinvoice
SOURCE XML lv_xml
RESULT allir_reikningar = lt_invoice.
CATCH cx_root INTO root_error.
lv_mess = root_error->if_message~get_text( ).
WRITE lv_mess.
ENDTRY.