Updating XML prior to XSLT transformation

I am attempting to convert an XML document using XSLT but I need to transform it a bit beforehand. Does anyone have a suggestion as to how to do this?
Below is the logic that will transform the XML directly from the file, but I need to manipulate it first.
Thanks in advance.
Patti
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import java.io.*;
public class Transform {
     * Performs an XSLT transformation, sending the results
     * to System.out.
    public static void main(String[] args) throws Exception {
        if (args.length != 2) {
            System.err.println(
                "Usage: java Transform [xmlfile] [xsltfile]");
            System.exit(1);
        File xmlFile = new File(args[0]);
        File xsltFile = new File(args[1]);
        // JAXP reads data using the Source interface
        Source xmlSource = new StreamSource(xmlFile);
        Source xsltSource = new StreamSource(xsltFile);
        // the factory pattern supports different XSLT processors
        TransformerFactory transFact =
                TransformerFactory.newInstance();
        Transformer trans = transFact.newTransformer(xsltSource);
        trans.transform(xmlSource, new StreamResult(System.out));
}

The first scenerio is what I intended. Since I posted my question I realized that I can manipulate the string and then create a StringSource passing a StringReader like so:
StringReader src = new StringReader(xmlStr);
StringWriter target = new StringWriter();
currentTransformer.transform(new StreamSource(src),
                             new StreamResult(target));Thanks.

Similar Messages

  • How to update XML file using XSLT

    Hi there,
    I have a "small" issue with exporting data to an XML file using XSLT.
    A two steps process is needed to import data from a non-hierarchical XML file into ABAP, change the data, and then update the XML file with new values. The problem is not trivial, since the format of the XML file is a complex one: there are many interdependent elements on the same level, pointing to each other by using id and ref attributes. Based on these values the data can be read and written into an internal table. I use XSLT and XPath for that. So the inbound process is done and seems to work correctly. I have to mention that the file contains much more data than I need. I am working only with a small part of it.
    Now the changed data must be exported back into the XML file, meaning that the content of certain elements must be updated. How can this be done with XSLT? I can pass only the internal table to the transformation, so how do I access the XML file in order to update it? I have tried to use the <B>xsl:document()</B> function to access the content of the file store locally on my PC, but it fails each time by throwing and URI exception. I have tried the absolute path without any addition and the path with the file:/// addition. Same result. Please advise.
    Many thanks,
    Ferenc
    P.S. Please provide me with links only if they are relevant for this very matter. I will not give points for irrelevant postings...

    Now the changed data must be exported back into the XML file, meaning that the content of certain elements must be updated. How can this be done with XSLT?
    XSLT approach:  check these online tutorial
    http://www.xml.com/pub/a/2000/08/02/xslt/index.html
    http://www.xml.com/pub/a/2000/06/07/transforming/index.html
    ABAP approach:
    for example you have the xml (original) in a string called say xml_out .
    data: l_xml  type ref to cl_xml_document ,
            node type ref to if_ixml_node  .
    create object l_xml.
    call method l_xml->parse_string
      exporting
        stream = xml_out.
    node = l_xml->find_node(
        name   = 'IDENTITY'
       ROOT   = ROOT
    l_xml->set_attribute(
        name    = 'Name'
        value   = 'Charles'
        node    = node
    (the above example reads the element IDENTITY and sets attribute name/value to the same)
    like wise you can add new elements starting from IDENTITY using various methods available in class CL_XML_DOCUMENT
    so how do I access the XML file in order to update it?
    you have already read this XML into a ABAP variable right?
    Sorry couldnt understand your whole process, why do you need to read local XML file?
    Raja

  • BI Admin Tool and XSLT transformation for XML data source - How it works ?

    Hello,
    There is a possibility to import data from XML data source using BI Admin Tool.
    In the import window we can point XSLT file. What is the purpose of that XSLT field?
    Why I am asking ?
    I thought it is smth like XSLT processor, but simply it doesnt work.
    What I did:
    - I pointed XML data source file
    - I pointed XSLT transformation file
    - Click OK, and still get the message that the XML file structure is not supported
    After that I transformed that XML file with some desktop XSLT processor using the same XSLT file, and I tried to connect that file directly using BI Admin tool.Then it works. So it means that the transformation is ok.
    So basically one question comes to my mind in that situation:
    What is the purpose of XSLT field in BI Admin Tool when it comes to XML data source ?
    (it doesnt look like XSLT processor)
    Greetings
    /Michal

    Hi Mariano
    Why you need to use XSLT for transforming XML file into ABAP table
    Code is a part of some ABAP report. Looks like it is reading a file from file system and updating table after transformation
    If you have requirement like you need to read XML file and then insert the data into a SAP table
    You can use
    File to RFC
    File to Proxy scenario using SAP PI.
    Please provide more inputs on requirement to help
    Thanks
    Gaurav

  • XSLT transformation for XML to ABAP internal table

    Hi, can anyone please tell me how it should be the xslt tranformation to conver this xml
    <Embargos_ARBA_DOC>
         <ns:Embargos_ARBA_MT
              xmlns:ns="un:swissmedical:sap:proxy:embargos_arba:file">
              <Embargos_ARBA_MT>
                   <FECHA>20081101</FECHA>
                   <CUIT>50000002124</CUIT>
                   <MONTO>0000013794090</MONTO>
                   <RAZON_SOCIAL>RAUL ARMANDO CUNQUEIRO S.A.C.I.</RAZON_SOCIAL>
              </Embargos_ARBA_MT>
              <Embargos_ARBA_MT>
                   <FECHA>20081101</FECHA>
                   <CUIT>55000001456</CUIT>
                   <MONTO>0000001144410</MONTO>
                   <RAZON_SOCIAL>PARODI ESTEBAN ARMANDO</RAZON_SOCIAL>
              </Embargos_ARBA_MT>
         </ns:Embargos_ARBA_MT>
    </Embargos_ARBA_DOC>
    to this abap Table....
      DATA: BEGIN OF i_embargos_arba_doc occurs 0,
              fecha TYPE d,
              cuit TYPE char11,
              monto TYPE char13,
              razon_social(120),
            END OF i_embargos_arba_mt.
    so i can transform it with this sentence
          CALL TRANSFORMATION ('embargos_transformation')
            SOURCE XML source
            RESULT Embargos_ARBA_DOC = embargos.
    pls i need help because i am unable to create this xslt transformation...
    I will give the highest rewards points to the one who can help me.
    thanks!
    mariano

    Hi Mariano
    Why you need to use XSLT for transforming XML file into ABAP table
    Code is a part of some ABAP report. Looks like it is reading a file from file system and updating table after transformation
    If you have requirement like you need to read XML file and then insert the data into a SAP table
    You can use
    File to RFC
    File to Proxy scenario using SAP PI.
    Please provide more inputs on requirement to help
    Thanks
    Gaurav

  • ABAP XSLT transformation - XML to deep structure/nested standard table

    Hi all,
    I was struggling with this topic recently and couldn't find a single working example or description of a possible solution. So now that I've sorted it out, I did a quick example to elustrate how it works. Here is the code with XML embeded in it and the XSLT follows:
    <HR>
    <PRE>
    *& Report  Z_XML2ABAP
    *& Author: Jayanta Roy
    *& Date: 03/02/2010
    REPORT  z_xml2abap.
    DATA input_xml TYPE string.
    TYPES: BEGIN OF t_address,
            house_no TYPE string,
            street_name TYPE string,
            city_name TYPE string,
            phone_no TYPE string,
          END OF t_address.
    TYPES: t_addresses TYPE STANDARD TABLE OF t_address with NON-UNIQUE KEY house_no.
    TYPES: BEGIN OF t_person,
            firstname TYPE string,
            surname TYPE string,
            addresses TYPE t_addresses,
          END OF t_person.
    input_xml = '&lt;Friends&gt;' &&
      '&lt;People&gt;' &&
        '&lt;FirstName&gt;Homer&lt;/FirstName&gt;' &&
        '&lt;Surname&gt;Simpson&lt;/Surname&gt;' &&
          '&lt;Address&gt;' &&
            '&lt;HouseNo&gt;123&lt;/HouseNo&gt;' &&
            '&lt;Street&gt;Evergreen Terrace&lt;/Street&gt;' &&
            '&lt;City&gt;Springfield&lt;/City&gt;' &&
            '&lt;PhoneNo&gt;011212321&lt;/PhoneNo&gt;' &&
          '&lt;/Address&gt;' &&
          '&lt;Address&gt;' &&
            '&lt;HouseNo&gt;7G&lt;/HouseNo&gt;' &&
            '&lt;Street&gt;Neuclear Power Plant&lt;/Street&gt;' &&
            '&lt;City&gt;Spring Field&lt;/City&gt;' &&
            '&lt;PhoneNo&gt;911&lt;/PhoneNo&gt;' &&
          '&lt;/Address&gt;' &&
      '&lt;/People&gt;' &&
      '&lt;People&gt;' &&
         '&lt;FirstName&gt;Bart&lt;/FirstName&gt;' &&
         '&lt;Surname&gt;Simpson&lt;/Surname&gt;' &&
           '&lt;Address&gt;' &&
             '&lt;HouseNo&gt;123x&lt;/HouseNo&gt;' &&
             '&lt;Street&gt;Evergreen Terracex&lt;/Street&gt;' &&
             '&lt;City&gt;Springfieldx&lt;/City&gt;' &&
             '&lt;PhoneNo&gt;011212321x&lt;/PhoneNo&gt;' &&
           '&lt;/Address&gt;' &&
       '&lt;/People&gt;' &&
    '&lt;/Friends&gt;' .
    DATA lt_person TYPE STANDARD TABLE OF t_person.
    TRY.
        CALL TRANSFORMATION xslt_person
        SOURCE XML input_xml
        RESULT  all_people = lt_person.
      CATCH cx_root.
        WRITE 'Problemo!'.
    ENDTRY.
    WRITE 'Now, debug the program to see the values read from the XML'.
    </PRE>
    <HR>
    and here is the XSLT Transformation program (xslt_person):
    <HR>
    <PRE>
    &lt;xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                        xmlns:sap="http://www.sap.com/sapxsl" version="1.0"&gt;
      &lt;xsl:strip-space elements="*"/&gt;
      &lt;xsl:template match="/"&gt;
        &lt;asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0"&gt;
          &lt;asx:values&gt;
            &lt;ALL_PEOPLE&gt;
              &lt;xsl:apply-templates select="//People"/&gt;
            &lt;/ALL_PEOPLE&gt;
          &lt;/asx:values&gt;
        &lt;/asx:abap&gt;
      &lt;/xsl:template&gt;
      &lt;xsl:template match="People"&gt;
        &lt;ALLMYFRIENDS&gt;  &lt;!This element name is not relevent... needed to just group the loop&gt;
          &lt;FIRSTNAME&gt;
            &lt;xsl:value-of select="FirstName"/&gt;
          &lt;/FIRSTNAME&gt;
          &lt;SURNAME&gt;
            &lt;xsl:value-of select="Surname"/&gt;
          &lt;/SURNAME&gt;
          &lt;ADDRESSES&gt;
            &lt;xsl:for-each select="Address"&gt;
              &lt;ADDRESS&gt; &lt;!This element name is not relevent... needed to just group the loop&gt;
                &lt;HOUSE_NO&gt;
                  &lt;xsl:value-of select="HouseNo"/&gt;
                &lt;/HOUSE_NO&gt;
                &lt;STREET_NAME&gt;
                  &lt;xsl:value-of select="Street"/&gt;
                &lt;/STREET_NAME&gt;
                &lt;CITY_NAME&gt;
                  &lt;xsl:value-of select="City"/&gt;
                &lt;/CITY_NAME&gt;
                &lt;PHONE_NO&gt;
                  &lt;xsl:value-of select="PhoneNo"/&gt;
                &lt;/PHONE_NO&gt;
              &lt;/ADDRESS&gt;
            &lt;/xsl:for-each&gt;
          &lt;/ADDRESSES&gt;
        &lt;/ALLMYFRIENDS&gt;
      &lt;/xsl:template&gt;
    &lt;/xsl:transform&gt;
    </PRE>
    <HR>
    HTH,
    Jayanta.

    thanks a LOT Jayanta..
    I was looking for an XSLT example for some time.. this one atleast got me started in the right direction..
    THANKS

  • XSLT-transformation in Java-Mapping with javax.xml

    Hi,
    we wanna use javax.xml for transformations in Java-Mapping.
    Inside the Java-mapping we read in XSL-files to transform a XML-stream. With XSLT 1.0 everything works fine - but with XSLT 2.0 we are getting runtime errors.
    Is it possible that javax.xml only supports XSLT 1.0?
    Regards
    Wolfgang

    Hi ,
    Jaxp 1.3 is available in this link -
    http://java.sun.com/webservices/jaxp/
    Use these jar files to process XSLT 2.0.
    Nanda

  • XSLT transformation in XML to ABAP: special characters issue

    Hi,
    I am parsing well-formed XML file that has the following data (:
    <projects><project><name>Wallis &amp; Futuna</name></project></projects>
    I use 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="projects">
        <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
            <PROJECTS>
              <xsl:for-each select="project">
                <PROJECT>
                  <NAME>
                    <xsl:value-of select="name"/>
                  </NAME>
                </PROJECT>
              </xsl:for-each>
            </PROJECTS>
          </asx:values>
        </asx:abap>
      </xsl:template>
    </xsl:transform>
    If I use the above example without &amp;amp; everything works fine, but the original XML fails with exception CX_XSLT_DESERIALIZATION_ERROR and message "Error during deserialization". Googling around did not give an answer.
    Any words of wisdom?
    Edited by: Alexei Isaev on Apr 26, 2011 5:04 AM
    Edited by: Alexei Isaev on Apr 26, 2011 5:05 AM

    Hi,
    Please visit the following link for reference.
    http://help.sap.com/abapdocu_70/en/ABAPCALL_TRANSFORMATION.htm
    Thanks & Regards,
    Harish

  • XSLT transformation of XML string

    Hello Everyone,
    This is my first endeavor to use XSLT and XML in our newly upgraded system.  I can't for the life of me figure out what is wrong with my code and would appreciate someone just glancing over it and pointing out what is likely a realy dumb problem.
    I have a program that reads a PEXR2002 IDoc. For testing purposes, I've hardcoded that IDoc number. It runs fine, creates the XML fine, the xslt in STRANS tests fine as well...but in the end my ls_table is blank.  I've been fuddling with this for a while and would really appreciate another pair of eyes taking a look at it.
    THANKS!!
    Greg
    My program. (xslt is below...really simple, but it's my first time).
    TYPES: BEGIN OF ty_table,
            sndprn LIKE edidc-sndprn,
            bgmref TYPE edif1004_r,
            moabetr TYPE edif5004_a,
            credat TYPE edidat8,
            datum TYPE edidat8,
          END OF ty_table.
    DATA: o_idoc TYPE REF TO cl_idoc_xml1, str type string, ls_table type ty_table. 
    CREATE OBJECT o_idoc
      EXPORTING
        docnum = '0000000000211014'.
    CALL METHOD o_idoc->get_xmldata_as_string
      IMPORTING
        data_string = str.
    CALL TRANSFORMATION ZUSL_PEXR2002_V1
    SOURCE XML str
    RESULT HEADER_DATA = ls_table.
    My XSLT....
    <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="/">
        <asx:abap version="1.0">
          <asx:values>
            <HEADER_DATA>
              <SNDPRN>
                <xsl:value-of select="PEXR2002/IDOC/EDI_DC40/SNDPRN"/>
              </SNDPRN>
              <BGMREF>
                <xsl:value-of select="PEXR2002/IDOC/E1IDKU1/BGMREF"/>
              </BGMREF>
              <MOABETR>
                <xsl:value-of select="PEXR2002/IDOC/E1IDKU5/MOABETR"/>
              </MOABETR>
              <CREDAT>
                <xsl:value-of select="PEXR2002/IDOC/EDI_DC40/CREDAT"/>
              </CREDAT>
              <DATUM>
                <xsl:value-of select="PEXR2002/IDOC/E1EDK03/DATUM"/>
              </DATUM>
            </HEADER_DATA>
          </asx:values>
        </asx:abap>
      </xsl:template>
    </xsl:transform>

    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

  • Transforming XML Data with XSLT in a servlet

    Trying to transform XML data using XSLT. The following code works fine outside of a servlet. But in a servlet it gives the following error :
    * Transformer Factory error
    javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerException: org.xml.sax.SAXException: Namespace not supported by SAXParser
    javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerException: org.xml.sax.SAXException: Namespace not supported by SAXParser
         at org.apache.xml.utils.DefaultErrorHandler.fatalError(DefaultErrorHandler.java:257)
         at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:813)
         at TransformationApp.XSLTTransformServlet.MyTransform(XSLTTransformServlet.java:79)
         at TransformationApp.XSLTTransformServlet.doGet(XSLTTransformServlet.java:39)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
         at org.apache.tomcat.core.Handler.service(Handler.java:287)
         at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
         at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
         at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
         at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
         at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
         at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
         at java.lang.Thread.run(Thread.java:484)
    Several articles hinted at setting the factory namespace attribute to TRUE. I have tried that but same results. Here is the code :
    static Document document;
    DocumentBuilderFactory factory =
    DocumentBuilderFactory.newInstance();
    //factory.setNamespaceAware(true);
    //factory.setValidating(true);
    try {
    File stylesheet = new File(argv[0]);
    File datafile = new File(argv[1]);
    DocumentBuilder builder = factory.newDocumentBuilder();
    document = builder.parse(datafile);
    // Use a Transformer for output
    TransformerFactory tFactory =
    TransformerFactory.newInstance();
    StreamSource stylesource = new StreamSource(stylesheet);
    Transformer transformer = tFactory.newTransformer(stylesource);
    DOMSource source = new DOMSource(document);
    StreamResult result = new StreamResult(System.out);
    transformer.transform(source, result);
    } catch (TransformerConfigurationException tce) {
    // Error generated by the parser
    System.out.println ("\n** Transformer Factory error");
    System.out.println(" " + tce.getMessage() );
    // Use the contained exception, if any
    Throwable x = tce;
    if (tce.getException() != null)
    x = tce.getException();
    x.printStackTrace();
    } catch (TransformerException te) {
    // Error generated by the parser
    System.out.println ("\n** Transformation error");
    System.out.println(" " + te.getMessage() );
    // Use the contained exception, if any
    Throwable x = te;
    if (te.getException() != null)
    x = te.getException();
    x.printStackTrace();
    } catch (SAXException sxe) {
    // Error generated by this application
    // (or a parser-initialization error)
    Exception x = sxe;
    if (sxe.getException() != null)
    x = sxe.getException();
    x.printStackTrace();
    } catch (ParserConfigurationException pce) {
    // Parser with specified options can't be built
    pce.printStackTrace();
    } catch (IOException ioe) {
    // I/O error
    ioe.printStackTrace();
    Any help would be greatly appreciated.

    I don't know that this is true, but i think the problem is the classpath.
    The runtime has his own parser. This parser is befor your xalan.lib in the classpath and the
    parser from the runntime don't support namespace.
    Try Tomcat 4.
    Regard Dietmar

  • How to use OAF transform sotred xml documents using XSLT...

    Does anyone have any experience using XSLT in OAF? Specifically, I have xml documents stored in a clob to which I wish to apply an XSLT transformation and then store the transformed documents back into the clob. Is there a way to apply an XSLT transformation using say BI-Publisher via OAF?

    "XML DIFF" are the keywords you can use to search for products that do this. Last time I looked there was a lot of XML Diff implementations, but none of them produced human-readable output that I really liked. I expect that's because XML diff is an easy thing for people to ask for but not an easy thing to do, given the considerable number of ways there are to change a document.

  • 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

  • How to perform an xslt transformation on an xml document dynamically ?

    Hi all,
    I'd like to perform an xslt tranformation on a dynamically generated xml code. I'm looking for a tag which can by useful for it. The tag should take both xml code and xslt code, passed as String arguments (not as names of xml and xslt files). I tried to use xtags library and jstl:transform tag but it did not work. It worked only with plain xml code passed to x-tag. When I try to perform a transformation on a tag body containing an output text tag, the transformation formats only this tag, not its content.
    For example:
    <xtags:style xslt="xslName.xsl">
    <h:outputText value="#{beanName.stringPropertyName}"/>
    </xtags:style>
    Thanks in advance
    Message was edited by:
    opad

    The issue is in the logic f your XSL mapping.
    Use the same source XML and use it with XML Spy to debug why it is not working as you want it to.
    Regards
    Bhavesh

  • 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.

  • How to generate XSL for an XML file to use it for XSLT transformation -SSIS?

    Hi All,
    Can anybody please help me to generate XSL for my attached XML file?
    I need to use the XSL file for XSLT transformation.
    Thanks & Regards,
    Sri

    Hi Vibhav,
    Thanks for the response.
    I am aware of the process but not sure how to generate XSL file. 
    Can you please refer me to any tool which can convert XML to XSL? or please can you transform my simple XML to XSL?
    Thanks & Regards,
    Sri

  • XSLT transformation not working in 1.5 (but was in 1.4)

    Gentlemen,
    I have a problem with some code that worked fine under 1.4 (at least up to 1.4.2_06), but now no longer works under 1.5.0 (I know this isn't the most recent, but I have yet to update).
    I use the following XSL template in order to take a string containing a valid XML definition, strip out all whitespace (this is ok, I know I dont need it), and then indent it in a nice readable format.
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="1.0" xmlns:xalan="http://xml.apache.org/xslt">
      <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" xalan:indent-amount="2"/>
        <xsl:strip-space elements="*"/>
          <xsl:template match="@*|node()">
            <xsl:copy>
              <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
          </xsl:template>
    </xsl:stylesheet>The code I use to perform the transformation is as follows :
    // read the XML string into a DOM document structure
    StringReader reader = new StringReader(xmlString);
    InputSource source = new InputSource(reader);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(source);
    // Input file to be transformed is the DOM document we have just created
    Source input = new DOMSource(doc);
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer(new StreamSource(new StringReader(TEMPLATE_AS_DEFINED_ABOVE)));
    // create output writer and transform
    StringWriter writer = new StringWriter();
    transformer.transform(input, new StreamResult(writer));
    System.out.println(writer.toString());As already stated, this produced the goods, in 1.4.2_06, but in 1.5.0 it results in the following error :
    java.lang.NullPointerException
         at gnu.xml.aelfred2.SAXDriver.getLineNumber(SAXDriver.java:1165)
         at com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.parseTopLevel(Parser.java:1077)
         at com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.parsePattern(Parser.java:1067)
         at com.sun.org.apache.xalan.internal.xsltc.compiler.Template.parseContents(Template.java:213)
         at com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.parseOwnChildren(Stylesheet.java:590)
         at com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.parseContents(Stylesheet.java:562)
         at com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.createAST(Parser.java:380)
         at com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:325)
         at com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:410)
         at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:791)
         at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:619)
         at com.ingenico.tests.ReportTest.prettifyXMLString(ReportTest.java:231)
         at com.ingenico.tests.ReportTest.<init>(ReportTest.java:100)
         at com.ingenico.tests.ReportTest.main(ReportTest.java:136)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
    ERROR:  'null'
    FATAL ERROR:  'Could not compile stylesheet'
    Exception in thread "main" javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
         at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:824)
         at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:619)
         at com.ingenico.tests.ReportTest.prettifyXMLString(ReportTest.java:231)
         at com.ingenico.tests.ReportTest.<init>(ReportTest.java:100)
         at com.ingenico.tests.ReportTest.main(ReportTest.java:136)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)I have a headache now and would appreciate some help - not with the headache, but the above error! :)
    Cheers in advance,
    Lee.

    have you tried to remove the xalan specific entries
    in the XSL and use that code:
    transformer.setOutputProperty("{http://xml.apache.org/
    xslt}indent-amount", "2");?Thanks for the reply.
    Unfortunately, Ive already tried this, and it's not the problem.
    If I remove the whole <xsl:template match /> section from the template, then the compilation error does not occur. I guess this narrows it down somewhat, but I don't know why that section is now failing under 1.5. (Ive since also tried with 1.5.0_03 - same error).

Maybe you are looking for