UTF-8 encoding in XSLT transformation

Hello,
I have a problem with a transformation of an ABAP structure into XML. I use the XSLT transformation for this.
My XSLT starts like this:
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:strip-space elements="*"/>
  <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
    <asx:values>
I tried many settings I could find posted on the internet, but I did not find one that would allow encoding to UTF-8.
It always encodes to iso-8859-1 which my interface partner cannot read.
Does anyone know a way to force encoding to UTF-8?
Adding a command like <xsl:output encoding="utf-8"/> did not help.
Thanks a lot!
       J. Euler

Hello!
I think I just solved the problem taking a different approach.
In a note here on SDN, a guy from SAP wrote, that the SAP XSLT processor is not able to code anything but the system's default to a string, BUT that it is able to code it to an xstring.
All I did now is add the tag  
<xsl:output encoding="utf-8" indent="yes" method="xml"/>
to my xslt program and change the coding in the program accordingly.
The program code is now:
  DATA: tempxstring TYPE xstring,
        temp_length TYPE i,
        conv      TYPE REF TO cl_abap_conv_in_ce.
  CLEAR tempxstring.
  TRY.
      CALL TRANSFORMATION
          zxxje_tst_xslt
        SOURCE omsregdatawebservice = wa_data
        RESULT XML tempxstring.
    CATCH cx_sy_conversion_base64.
    CATCH cx_sy_conv_illegal_date_time.
  ENDTRY.
  IF tempxstring IS NOT INITIAL.
    CLEAR: conv, temp_length, string_xml_result.
    conv = cl_abap_conv_in_ce=>create( input = tempxstring ).
    conv->read( IMPORTING data = string_xml_result len = temp_length ).
  ENDIF.
Thanks anyways for all your help!
regards,
      Johannes Euler

Similar Messages

  • JAXP XSLT transformation UTF-8 issue

    Hi all,
    I have XML file generated from Java app. File is valid and is in UTF-8.
    I have XSLT template created with Altova StyleVision. Template is to produce RTF output file from above XML.
    I Java app there are two variant for XSLT transformation - with and without Saxon. I have simplified the code and it is almost the same in two variants.
    File outputFile = new File("path");
    *if (saxonToBeUsed) {*
    ClassLoader saxonClassLoader = SaxonLoader.getInstance(saxonPath);
    TransformerFactory transFact = TransformerFactory.newInstance("net.sf.saxon.TransformerFactoryImpl", saxonClassLoader); //$NON-NLS-1$
    Transformer trans = transFact.newTransformer(xsltSource);
    trans.setOutputProperty("encoding", "UTF-8"); //$NON-NLS-1$
    StreamResult res = new StreamResult(outputFile);
    trans.transform(xmlSource, res);
    *} else {*
    TransformerFactory transFact = TransformerFactory.newInstance();
    Transformer trans = transFact.newTransformer(xsltSource);
    trans.setOutputProperty("encoding", "UTF-8"); //$NON-NLS-1$
    StreamResult res = new StreamResult(outputFile);
    *// Same result -> StreamResult res = new StreamResult(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"));*
    *// Same result -> StreamResult res = new StreamResult(new PrintWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")));*
    trans.transform(xmlSource, res);
    XML file contains Arabic or Chinese text. RTF is generated.
    When RTF and XML are opened with text editor or web browser Arabic/Chinese whatever text is readable.
    The issue is that when RTF is opened with MSWord/WordPad/Open Office Writer :
    - Saxon generation -> RTF file can be opened and Arabic/Chinese text is normal i.e readable. English language is readable too.
    - JAXP generation -> RTF file can be opened but Arabic/Chinese is scrabmbled, messed up. English language is readable.
    All three files (XML,XSLT,RTF) are in UTF-8
    I have installed Chinese and Arabic true type fonts. When I create manual MSWord doc i can write some of their symbols.
    Please suggest some solution.
    Thanks

    Hi jtahlborn,
    I found the difference between two RTFs. This is one table cell containing random Arabic text
    XSLT 1.0 generated:
    {\*\bkmkstart محمود_شمام_لرويترز:_القذافي_قتل_في_هجوم_للمجلس_الانتقالي}{\fs16 محمود شمام لرويترز: القذافي قتل في هجوم للمجلس الانتقالي}
    XLST2.0 generated:
    {\*\bkmkstart محمود_شمام_لرويترز:_القذافي_قتل_في_هجوم_للمجلس_الانتقالي} {\fs16\u1605?\u1581?\u1605?\u1608?\u1583?\u32?\u1588?\u1605?\u1575?\u1605?\u32?\u1604?\u1585?\u1608?\u1610?\u1578?\u1585?\u1586?\u58?\u32?\u1575?\u1604?\u1602?\u1584?\u1575?\u1601?\u1610?\u32?\u1602?\u1578?\u1604?\u32?\u1601?\u1610?\u32?\u1607?\u1580?\u1608?\u1605?\u32?\u1604?\u1604?\u1605?\u1580?\u1604?\u1587?\u32?\u1575?\u1604?\u1575?\u1606?\u1578?\u1602?\u1575?\u1604?\u1610?}
    But I don't know how to fix it. Both files are generated with Saxon, same Java code, only XSLTs are different.
    Any ideas ?

  • XSLT Transformation

    Hi,
    I am trying to upload one xml file and filling an internal table with the content and a XSLT transformation. After uploading the file and make the first transformation i obtein one string with all the fields without tags and separated by #. so when i try to call transformation for filling the internal table i obtein the exception cx_xslt_exception with the message 'No valid source context supplied'.
    I would like to know if i am having poroblems with unicode characters. Is there any example made in sap that i can test or does anybody have had any similar problem?.
    My string
    <?xml version="1.0" encoding="utf-16"?>#######S####L####08##2######
    Thanks in advance
    regards

    Hi Verma,
    You're not transforming anything from your input to the output shown. You're actually constructing a new Output. I don't see anything being transformed from input to output.
    Anyway, if you need a XSLT to be used to get the above Output in map, following XSLT shall help you:
    <?xml version="1.0" encoding="UTF-16"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0" version="1.0" xmlns:s0="http://xmlns.service/1" xmlns:ns1="http://xmlns.types/1.0" xmlns:ns0="http://xmlns.OutService/2">
    <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
    <xsl:template match="/">
    <xsl:apply-templates select="/s0:Request" />
    </xsl:template>
    <xsl:template match="/s0:Request">
    <Output xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://xmlns.OutService/2">
    <outContext xmlns:ns0="http://xmlns.OutService/2" xsi:type="ns0:ReferenceContext" xmlns="http://xmlns.types/1.0" />
    </Output>
    </xsl:template>
    </xsl:stylesheet>
    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

  • XSLT transformation: tamplate match="*" problem

    Hi everybody,
    I have some stupid problem with XSLT transformations. I use XALAN-J 2.7 to transform xml files. My xslt transformation can be downloaded from http://tesla.rcub.bg.ac.yu/~sing/xsd2rdf.xslt
    Problem is when I have in xslt file template defined with (match="*") it does not work. Transformation does not throw any exceptions; it just does not match nodes very well.
    Next XML schema can be used as test. So, if you transform this file(schema below) using e.g. XML Spy it will work fine, but if you transform it using JAVA it does not match all nodes. Any suggestions are welcome. Is it problem with XPath standard and XALAN implementation or what???
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema targetNamespace="http://www.openapplications.org/oagis/CoreComponents/1.90/Types" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cct="http://www.openapplications.org/oagis/CoreComponents/1.90/Types" elementFormDefault="qualified" attributeFormDefault="unqualified">
         <xs:simpleType name="Simple">
              <xs:restriction base="xs:integer"/>
         </xs:simpleType>
         <xs:complexType name="AmountType">
              <xs:simpleContent>
                   <xs:extension base="cct:Simple">
                        <xs:attribute name="currencyID" type="xs:integer" use="required"/>
                        <xs:attribute name="codeListVersionID" type="xs:float" use="optional"/>
                   </xs:extension>
              </xs:simpleContent>
         </xs:complexType>
    </xs:schema>
    Thanks,
    Igor.

    Found a solution for my problem. Now it works!
      DATA: wa_transformation TYPE y0dpl_structures.
      DATA: obj_import TYPE abap_trans_srcbind_tab,
            wa_import TYPE abap_trans_srcbind.
      DATA: obj_data TYPE REF TO data.
      DATA: wa_return TYPE bapiret2.
      FIELD-SYMBOLS: <data> TYPE ANY TABLE.
    * Get transformation data
      SELECT SINGLE *
      INTO wa_transformation
      FROM y0dpl_structures
      WHERE filetype = i_file_type.
      IF sy-subrc IS INITIAL.
    * Create table with internal structure
        CREATE DATA e_data TYPE STANDARD TABLE OF (wa_transformation-structure_name).
        ASSIGN i_data->* TO <data>.
        wa_import-name = 'IMPORT'.
        GET REFERENCE OF <data> INTO wa_import-value.
        APPEND wa_import TO obj_import.
    * Call transformation
        CALL TRANSFORMATION (wa_transformation-transformation)
        SOURCE (obj_import)
        RESULT export_data = e_data.
      ELSE.
        MOVE:  'Y0_DPL' TO wa_return-id,
               'E'      TO wa_return-type,
               '108'    TO wa_return-number.
        APPEND wa_return TO e_return.
        CLEAR: wa_return.
      ENDIF.

  • XSLT-transformation inserts linefeeds

    Hi,
    I am using XSLT-transformation on WAS 7.0. Part of the result of my XSLT-transformations is javascript-sourcecode.
    The statement
    <xsl:output omit-xml-declaration="yes" indent="no" method="html" encoding="utf-8" />
    should generate browser-readable html-code.
    So take the line
    xxxxx<br/>yyyyy
    After the transformation I am expecting the result
    xxxxx<br>yyyyy
    wheras the XSLT-transformation engine returns
    xxxxx<br>
    <br>
    yyyyy<br>
    (LINEBREAKS ARE INSERTED FOR EACH LINE!!!)
    As my result is javascript-source, this behaviour is a huge problem, as - due to the linefeeds - my generated javascipt-code is not executable anymore.
    Does anybody know a solution, how I can tell the XSLT-processor to generate code WITHOUT linefeeds?
    Thanks,
    Andreas

    A <i>value-of tag</i> would be much useful .
    <xsl:value-of
      select? = expression
      separator? =
      [disable-output-escaping]? = "yes" | "no">
    </xsl:value-of>
    e.g
    <xsl:template match="description">
      <xsl:value-of select="." disable-output-escaping="yes" />
    </xsl:template>

  • Automatic insert of xmlns:xsl during XSLT transformation

    I am using the xmlparserv2.jar of dated "12/10/00" to perform a XSLT transformation. I need to insert a xml:space="preserve" attribute to a generated tag. However, there is an addition attribute added : xmlns:xml="http://www.w3/org/XML/1998/namespace". How can I suppress the generation of this attribute ?
    Here is my XML :
    <?xml version = '1.0' standalone = 'no'?>
    <COLDdoc>
    <Page template="bkgnd1" num="1">
    <Line num="1"> CN011A021C 1A021</Line>
    <Line num="2"> 1954.90 7713.36</Line>
    </Page>
    </COLDdoc>
    My XSL is :
    <?xml version = '1.0' standalone = 'yes'?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="no" doctype-system="svg-20000303-stylable.dtd"/>
    <xsl:template match="Line">
    <text>
    <xsl:attribute name="x">0</xsl:attribute>
    <xsl:attribute name="y">
    <xsl:value-of select="@num*10"/>
    </xsl:attribute>
    <xsl:attribute name="xml:space">preserve</xsl:attribute>
    <xsl:value-of select="."/>
    </text>
    </xsl:template>
    </xsl:stylesheet>
    The result XSLT Transformation :
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <!DOCTYPE text SYSTEM "svg-20000303-stylable.dtd">
    <text x="0" y="10" xmlns:xml="http://www.w3/org/XML/1998/namespace" xml:space="preserve"> CN011A021C 1A021</text>
    <text x="0" y="20" xmlns:xml="http://www.w3/org/XML/1998/namespace" xml:space="preserve"> "> 1954.90 7713.36</text>
    Regards.
    Jeffrey
    null

    Hi Greg,
    please try it with the following (just slightly) modified transformation (works fine for me):
    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                   xmlns:asx="http://www.sap.com/abapxml"
                   xmlns:sap="http://www.sap.com/sapxsl"
                   version="1.0">
      <xsl:strip-space elements="*"/>
      <xsl:template match="/PEXR2002/IDOC">
        <asx:abap version="1.0">
          <asx:values>
            <HEADER_DATA>
              <SNDPRN>
                <xsl:value-of select="EDI_DC40/SNDPRN"/>
              </SNDPRN>
              <BGMREF>
                <xsl:value-of select="E1IDKU1/BGMREF"/>
              </BGMREF>
              <MOABETR>
                <xsl:value-of select="E1IDKU5/MOABETR"/>
              </MOABETR>
              <CREDAT>
                <xsl:value-of select="EDI_DC40/CREDAT"/>
              </CREDAT>
              <DATUM>
                <xsl:value-of select="E1EDK03/DATUM"/>
              </DATUM>
            </HEADER_DATA>
          </asx:values>
        </asx:abap>
      </xsl:template>
    </xsl:transform>
    I recommend to test all transformations that you define on a sample source and check the output. If you apply your original transformation you would see that it basically doesn't select anything and therefore you just get an XML document with the field names but no values.
    Cheers, harald

  • XSLT transformation for Single XML Output

    I want to save a book to a single XML document. Is it correct that I can do this by adding an xslt to merge the standard framemaker entity type output ? Can I easily reconfigure the standard Save As XML to acheive this? or do I need to add a new menu item and call the XSLT dialogue...
    any advice appreciated.
    Thanks!

    Tracey,
       A related discussion appeared in the FrameSGML Yahoo group recently. Much of what follows is what I wrote there.
       Your XML application (defined in structapps.fm or another application definition file) can specify an XSLT post-process. No need to change Save as XML or define a new menu item. Depending on what you want, the XSLT transform can be as simple as the following:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml"/>
        <xsl:template match="/ | node() | @*">
            <xsl:copy>
                <xsl:apply-templates select="@* | node()"/>
            </xsl:copy>
        </xsl:template>
    </xsl:transform>
    This is an identity transform that simply copies the interpreted input to the output. I've used the word "interpreted" here because XSLT does not distinguish among some variations of how content is entered. In particular, it does not distinguish between content in referenced general entities (which is what you want) or between attribute values that happen to be the same as the attribute default value and attributes that are not explicitly specified and hence use the default value.
    There are a few things to watch out for involving use of general entities.
    First, if you are using entity attributes for graphics, you'll need to modify the above slightly. It's probably easier to replace the entity attributes with file attributes, but if you want to keep the entities, the above needs to be extended to declare the entities.
    Second, if you are using and want to preserve entity references for special characters or variables, you'll need to account for them as well. See $FMHOME\Structure\xml\PreserveEntity\readme.pdf.
        --Lynne

  • Problem getting xslt transform to work

    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 ?

    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.

  • Tags not printed when outputting XML after XSLT transformation

    Hi!
    I want my to perform an XSLT transformation on requests to my web service.
    This is the style of a typical request:
    <app:aRequest xmlns:app="http://myNamespace">
      <app:firstTag>value1</app:firstTag>
      <app:secondTag>value2</app:secondTag>
      <app:thirdTag>value3</app:thirdTag>
    </app:aRequest>I want to transform it into something like this:
    <app:aRequest xmlns:app="http://myNamespace">
      <app:firstTag>A hard coded, completely different value!</app:firstTag>
      <app:secondTag>value2</app:secondTag>
      <app:thirdTag>value3</app:thirdTag>
    </app:aRequest>To do that, I use the following XSLT:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:app="http://myNamespace">
    <xsl:template match="/">
    <app:aRequest>
      <app:firstTag>A hard coded, completely different value!</app:firstTag>
      <app:secondTag><xsl:value-of select="app:aRequest/app:secondTag" /></app:secondTag>
      <app:thirdTag><xsl:value-of select="app:aRequest/app:thirdTag" /></app:thirdTag>
    </app:aRequest>
    </xsl:template>
    </xsl:stylesheet>And I use the following code to execute the transformation:
    public Object unmarshal(Source source) throws XmlMappingException, IOException {
      TransformerFactory factory = TransformerFactory.newInstance();
        // Does this factory support SAX features?
        if(factory.getFeature(SAXSource.FEATURE)) {
          SAXTransformerFactory saxTransformerFactory = (SAXTransformerFactory)factory;
        // Read xslt file.
        InputStream inputStream = getClass().getResourceAsStream("/META-INF/xsltTransformation.xsl");
        if(inputStream == null) {
          throw new RuntimeException("No XSLT transformation file present at " + location);
        Templates xsltOutputTemplate = saxTransformerFactory.newTemplates(new StreamSource(inputStream));
        Transformer transformer = xsltTemplate.newTransformer();
        // Perform transformation.
        StringWriter stringWriter = new StringWriter();
        StreamResult result = new StreamResult(stringWriter);
        transformer.transform(source, result);
        // Print result.
        String xmlString = stringWriter.toString();
        System.out.println(xmlString);
        // Proceed with unmarshalling.
        StringReader stringReader = new StringReader(xmlString);
        StreamSource transformedSource = new StreamSource(stringReader);
        return oxMapper.getUnmarshaller().unmarshal(transformedSource);
    }However, the System.out.println(xmlString); produces the following result:
    <?xml version="1.0" encoding="UTF-8"?>
      value1
      value2
      value3The tags are not printed and the hard coded value is not present.
    What am I doing wrong? Please help!

    Following up on what the good Dr said,
    Are you sure that you are using the stylesheet that you think you are?
    I tried your stylesheet and input and got more or less what you wanted and not what you actually got.
    Note that I did not use your code.

  • Error in ABAP XSLT transformation

    Hi,
    Im trying to upload some data from XML to abap. But Im getting an error while transforming xml data to internal table.
    Here are the details.
    XML:
    <?xml version="1.0" encoding="ISO-8859-1" ?>
      <!--  Edited by XMLSpy® -->
    <?xml-stylesheet type="text/xsl" href="ABAP1.xsl"?>
    <conceptRevDecisionXml>
    <projectInfo>
    <projectId>P000755</projectId>
    <stage>CON</stage>
    <country>Ethiopia</country>
    <region>AFRICA</region>
    <teamleader>Priya Agarwal</teamleader>
    <teamleaderfirstname>Priya</teamleaderfirstname>
    <teamleaderlastname>Agarwal</teamleaderlastname>
    <actionType>X</actionType>
    </projectInfo>
    </conceptRevDecisionXml>
    XSLT: Transformation
    <xsl:transform version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:sapxsl="http://www.sap.com/sapxsl"
    >
    <xsl:strip-space elements="*"></xsl:strip-space>
    <xsl:template match="/">
        <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
          <asx:values>
            <PROJID>
              <xsl:apply-templates select="//conceptRevDecisionXml"></xsl:apply-templates>
            </PROJID>
          </asx:values>
        </asx:abap>
    </xsl:template>
    <xsl:template match="conceptRevDecisionXml">
          <xsl:for-each select="projectInfo">
           <xsl:value-of select="projectId"></xsl:value-of>
           <xsl:value-of select="stage"></xsl:value-of>
           <xsl:value-of select="country "></xsl:value-of>
           <xsl:value-of select="region"></xsl:value-of>
           <xsl:value-of select="teamleader"></xsl:value-of>
           <xsl:value-of select="teamleaderfirstname"></xsl:value-of>
           <xsl:value-of select="teamleaderlastname"></xsl:value-of>
            <xsl:value-of select="actionType"></xsl:value-of>
            </xsl:for-each>
        </xsl:template>
    </xsl:transform>
    Once I run the program...Im getting an error saying...ABAP XML Formatting error in XML node..
    Im new to ABAP-XML parsing..Pls help me where Im going wrong..
    Thanks in advance.
    Regards,
    Priya

    Hi Priya,
    you can try with the below,
    1) Create a local ITAB with the structure of the XML,
    TYPES: BEGIN OF t_data,
            projectid           TYPE char30,
            stage               TYPE char30,
            country             TYPE char30,
            region              TYPE char30,
            teamleader          TYPE char30,
            teamleaderfirstname TYPE char30,
            teamleaderlastname  TYPE char30,
            actiontype          TYPE char30,
           END OF t_data.
    2) Create an XSLT prog in "STRANS" with the below code,
    <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>
    <L_DATA>
    <xsl:apply-templates select="//projectInfo"/>
    </L_DATA>
    </asx:values>
    </asx:abap>
    </xsl:template>
    <xsl:template match="projectInfo">
    <conceptRevDecisionXml>
    <PROJECTID>
    <xsl:value-of select="projectId"/>
    </PROJECTID>
    <STAGE>
    <xsl:value-of select="stage"/>
    </STAGE>
    <COUNTRY>
    <xsl:value-of select="country"/>
    </COUNTRY>
    <REGION>
    <xsl:value-of select="region"/>
    </REGION>
    <TEAMLEADER>
    <xsl:value-of select="teamleader"/>
    </TEAMLEADER>
    <TEAMLEADERFIRSTNAME>
    <xsl:value-of select="teamleaderfirstname"/>
    </TEAMLEADERFIRSTNAME>
    <TEAMLEADERLASTNAME>
    <xsl:value-of select="teamleaderlastname"/>
    </TEAMLEADERLASTNAME>
    <ACTIONTYPE>
    <xsl:value-of select="actionType"/>
    </ACTIONTYPE>
    </conceptRevDecisionXml>
    </xsl:template>
    </xsl:transform>
    3) Call the transformation as shown below,
    CALL TRANSFORMATION zxslt_project ---> "Name of the XSLT prog created above
    SOURCE XML l_xml_str                           ---> Source XML string
    RESULT l_data = l_data.                          ---> ITAB as in step 1 above
    Regards,
    Chen

  • XML stream utf-8 encoding

    Hi folks,
    I'm trying to establish a CSTRING XML stream with utf-8 encoding. I've only managed to do this in XSTRING so far.
    If i use this coding, i get a binary output.
      DATA: gt_result TYPE TABLE OF string,
             l_result type string.
      constants: encoding type string value 'UTF-8'.
      data:  g_ixml type ref to if_ixml.
      data:  g_stream_factory type ref to IF_IXML_STREAM_FACTORY.
      data:  g_encoding type ref to if_ixml_encoding.
      g_ixml = cl_ixml=>create( ).
      g_stream_factory = g_ixml->CREATE_STREAM_FACTORY( ).
      g_encoding = g_ixml->create_encoding( character_set = 'utf-8'
                                            byte_order = 0 ).
      data:  resstream type ref to if_ixml_ostream.
      resstream = g_stream_factory->create_ostream_cstring( l_result ).
      call method resstream->set_encoding
        EXPORTING
          encoding = g_encoding.
    * XML Transformieren
      CALL TRANSFORMATION id_indent
        SOURCE     itab = it_Itab
        RESULT XML resstream.
    * Temporär, XML File erzeugen
      refresh gt_result.
      APPEND l_result TO gt_result.
      CALL METHOD cl_gui_frontend_services=>gui_download
        EXPORTING
          filename         = 'c:test.xml'
        CHANGING
          data_tab         = gt_result
        EXCEPTIONS
          file_write_error = 1.
    Without this expression :
    g_encoding = g_ixml->create_encoding(
                 character_set = 'utf-8' byte_order = 0 ).
    I get a cstring stream, but in utf-16.
    My question now is, how do I manage to get a utf-8 encoded stream in cstring?
    Thanks for your help.
    Cheers
    Daniel

    This is the solution:
    METHOD TRANSFORM_XML.
      TYPE-POOLS TRUXS.
    *********************** XML ***********************************
      DATA: GT_RESULT TYPE TABLE OF STRING,
             L_RESULT TYPE ETXML_LINE_STR.
      CONSTANTS:  ENCODING     TYPE STRING VALUE 'UTF-8'.
      DATA:  G_IXML TYPE REF TO IF_IXML.
      DATA:  G_STREAM_FACTORY TYPE REF TO IF_IXML_STREAM_FACTORY.
      DATA:  G_ENCODING TYPE REF TO IF_IXML_ENCODING.
      G_IXML = CL_IXML=>CREATE( ).
      G_STREAM_FACTORY = G_IXML->CREATE_STREAM_FACTORY( ).
      G_ENCODING = G_IXML->CREATE_ENCODING( CHARACTER_SET = ENCODING
                                            BYTE_ORDER = 0 ).
      DATA:  RESSTREAM TYPE REF TO IF_IXML_OSTREAM.
      RESSTREAM = G_STREAM_FACTORY->CREATE_OSTREAM_XSTRING( L_RESULT ).
      CALL METHOD RESSTREAM->SET_ENCODING
        EXPORTING
          ENCODING = G_ENCODING.
    * XML Transformieren
      CALL TRANSFORMATION ID_INDENT
        SOURCE     ITAB = IT_ITAB
        RESULT XML RESSTREAM.
    * XString to String
      CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'
        EXPORTING
          IM_XSTRING  = L_RESULT
          IM_ENCODING = 'UTF-8'
        IMPORTING
          EX_STRING   = E_XML.
    * Temporär, XML File erzeugen
      refresh gt_result.
      APPEND e_xml TO gt_result.
      CALL METHOD cl_gui_frontend_services=>gui_download
        EXPORTING
          filename         = 'c:test.xml'
        CHANGING
          data_tab         = gt_result
        EXCEPTIONS
          file_write_error = 1.
    ENDMETHOD.
    How can I give the 10 points to myself?
    Cheers
    Daniel

  • Execute a query using ABAP  (XSLT transformation issue)

    Hello,
    I made the steps from this blog (part I, II and III).
    /people/durairaj.athavanraja/blog/2005/12/05/execute-bw-query-using-abap-part-iii
    When trying to run the XSLT transformation, I got the message that : XML invalid source file.
    I am not sure what are the steps for running a transformation, or running it for this case ,maybe something it's not ok. I just run it, did not provide any information.
    Any suggestions ? Did anyone use the function module described in this blog ?
    Thank you very much in advance.

    try giving
    CALL TRANSFORMATION (`ID`)
    SOURCE meta = meta_data[]
    output = <ltable>[]
    RESULT XML xml_out
    OPTIONS xml_header = 'NO'.
    and check - sometimes the codepages configured in the BW system tend to cause an issue... I am not sure if the syntax is right though - but you are basically trying to bypass any encoding that is happening in the query transformation....
    http://www.sapetabap.com/ovidentia/index.php?tg=fileman&sAction=getFile&inl=1&id=4&gr=Y&path=ABAP%2FABAPENANGLAIS&file=ABAP-XML+Mapping.pdf&idf=41
    Edited by: Arun Varadarajan on May 18, 2009 11:28 PM

  • XSLT transformation in binding editor

    Hi,
    In the new version of the workflow builder we are so lucky, that not only can we use programmed bindings but also XSLT transformation.
    I have tried to create a XSLT that transforms the wf XML container to the Step XML container, but it does not change the containervalue as i hoped. Does anyone have experience with XSLT in the binding editor?
    What format/schema should I end up the in the stepcontainer?
    Hopy you can help?
    Kind regards
    Mikkel

    By the way, this is the XSLT transformation that works fine if we remove that ":ns4" from the attribute name:
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:source="/com/grifols/gds/webapp/inventoryCount/units/queries/common/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    version="2.0">
    <xsl:output method="xml" encoding="iso-8859-1" indent="yes"/>
    <xsl:template match="source:*">
    <xsl:element name="{local-name()}" namespace="http://www.something.else">
    <xsl:apply-templates select="@*|node()"/>
    </xsl:element>
    </xsl:template>
    <xsl:template match="@*|node()">
    <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    </xsl:template>
    </xsl:stylesheet>

  • XSLT transformation in OSB Proxy Service

    Hello, I am trying to modify the answer from a WebService using an XSLT transformation in an OSB Proxy Service, but I am unable to do so. Here it is the content of the answer's body it receives:
    <ns0:getRecountUnitMovementsResponse xmlns:ns0="http://www.grifols.com/gds/interfaces/types/">
    <ns1:result xsi:type="ns4:VO_PR_UnitsMovementsSDO" xmlns:ns1="http://www.grifols.com/gds/interfaces/types/" xmlns:ns4="/com/grifols/gds/webapp/inventoryCount/units/queries/common/" xmlns:ns0="http://xmlns.oracle.com/adf/svc/types/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:typ="http://www.grifols.com/gds/interfaces/types/">
    <ns4:GrpId>4</ns4:GrpId>
    <ns4:MovementType>960</ns4:MovementType>
    <ns4:DcCode>165</ns4:DcCode>
    <ns4:RecDcCode>165</ns4:RecDcCode>
    <ns4:UnitItemNumber>11-0001</ns4:UnitItemNumber>
    <ns4:RecUnitItemNumber xsi:nil="true"/>
    <ns4:Bol xsi:nil="true"/>
    <ns4:CustomerId xsi:nil="true"/>
    <ns4:DocumentDate>2011-01-01T09:00:00.0+01:00</ns4:DocumentDate>
    <ns4:PostingDate>2011-01-01T09:00:00.0+01:00</ns4:PostingDate>
    <ns4:MovStatusCode>SE</ns4:MovStatusCode>
    <ns4:Quantity>10</ns4:Quantity>
    </ns1:result>
    <ns1:result xsi:type="ns4:VO_PR_UnitsMovementsSDO" xmlns:ns1="http://www.grifols.com/gds/interfaces/types/" xmlns:ns4="/com/grifols/gds/webapp/inventoryCount/units/queries/common/" xmlns:ns0="http://xmlns.oracle.com/adf/svc/types/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:typ="http://www.grifols.com/gds/interfaces/types/">
    <ns4:GrpId>1</ns4:GrpId>
    <ns4:MovementType>913</ns4:MovementType>
    <ns4:DcCode>165</ns4:DcCode>
    <ns4:RecDcCode>165</ns4:RecDcCode>
    <ns4:UnitItemNumber>11-0001</ns4:UnitItemNumber>
    <ns4:RecUnitItemNumber xsi:nil="true"/>
    <ns4:Bol xsi:nil="true"/>
    <ns4:CustomerId xsi:nil="true"/>
    <ns4:DocumentDate>2011-01-01T09:00:00.0+01:00</ns4:DocumentDate>
    <ns4:PostingDate>2011-01-01T09:00:00.0+01:00</ns4:PostingDate>
    <ns4:MovStatusCode>SE</ns4:MovStatusCode>
    <ns4:Quantity>15</ns4:Quantity>
    </ns1:result>
    <ns1:result xsi:type="ns4:VO_PR_UnitsMovementsSDO" xmlns:ns1="http://www.grifols.com/gds/interfaces/types/" xmlns:ns4="/com/grifols/gds/webapp/inventoryCount/units/queries/common/" xmlns:ns0="http://xmlns.oracle.com/adf/svc/types/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:typ="http://www.grifols.com/gds/interfaces/types/">
    <ns4:GrpId>2</ns4:GrpId>
    <ns4:MovementType>913</ns4:MovementType>
    <ns4:DcCode>165</ns4:DcCode>
    <ns4:RecDcCode>165</ns4:RecDcCode>
    <ns4:UnitItemNumber>21-00001</ns4:UnitItemNumber>
    <ns4:RecUnitItemNumber xsi:nil="true"/>
    <ns4:Bol xsi:nil="true"/>
    <ns4:CustomerId xsi:nil="true"/>
    <ns4:DocumentDate>2011-01-01T09:00:00.0+01:00</ns4:DocumentDate>
    <ns4:PostingDate>2011-01-01T09:00:00.0+01:00</ns4:PostingDate>
    <ns4:MovStatusCode>SE</ns4:MovStatusCode>
    <ns4:Quantity>25</ns4:Quantity>
    </ns1:result>
    <ns1:result xsi:type="ns4:VO_PR_UnitsMovementsSDO" xmlns:ns1="http://www.grifols.com/gds/interfaces/types/" xmlns:ns4="/com/grifols/gds/webapp/inventoryCount/units/queries/common/" xmlns:ns0="http://xmlns.oracle.com/adf/svc/types/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:typ="http://www.grifols.com/gds/interfaces/types/">
    <ns4:GrpId>3</ns4:GrpId>
    <ns4:MovementType>959</ns4:MovementType>
    <ns4:DcCode>165</ns4:DcCode>
    <ns4:RecDcCode>165</ns4:RecDcCode>
    <ns4:UnitItemNumber>11-0001</ns4:UnitItemNumber>
    <ns4:RecUnitItemNumber xsi:nil="true"/>
    <ns4:Bol xsi:nil="true"/>
    <ns4:CustomerId xsi:nil="true"/>
    <ns4:DocumentDate>2011-01-01T09:00:00.0+01:00</ns4:DocumentDate>
    <ns4:PostingDate>2011-01-01T09:00:00.0+01:00</ns4:PostingDate>
    <ns4:MovStatusCode>SE</ns4:MovStatusCode>
    <ns4:Quantity>50</ns4:Quantity>
    </ns1:result>
    </ns0:getRecountUnitMovementsResponse>
    And what I am trying to do is replace all the "/com/grifols/gds/webapp/inventoryCount/units/queries/common/" for "http://www.something.else". I have succeeded replacing it if the attribute name is "xmlns" instead of "xmlns:ns4". However, that ":ns4" changes everything and I can't get it to work. Does anyone know how to do so?
    Thank you in advance. Don't hesitate to ask me for more information you may need.
    Jordi

    By the way, this is the XSLT transformation that works fine if we remove that ":ns4" from the attribute name:
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:source="/com/grifols/gds/webapp/inventoryCount/units/queries/common/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    version="2.0">
    <xsl:output method="xml" encoding="iso-8859-1" indent="yes"/>
    <xsl:template match="source:*">
    <xsl:element name="{local-name()}" namespace="http://www.something.else">
    <xsl:apply-templates select="@*|node()"/>
    </xsl:element>
    </xsl:template>
    <xsl:template match="@*|node()">
    <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    </xsl:template>
    </xsl:stylesheet>

  • PL/SQL XSLT transformation problem

    I am trying to perform an XSLT transformation inside a PL/SQL procedure using dbms_xslprocessor.processxsl() but I am getting the following error 'LPX-00411: unknown function name encountered'
    The transformation XSL contains a java extension to preform some encoding of data and with the template containing the reference to the extension removed the transformation works fine. Does this mean that DBMS_XMLPARSER does not support java extensions in XSL or is it possible I'm just calling the function incorrectly?
    I have been testing up to now using oraxsl on the command line which seemed to work fine.
    Thanks,
    Alan

    Alan,
    Are you using the right namespace for the class you want to use?

Maybe you are looking for