Skip to Content
avatar image
Former Member

Display XML-Data retreived from a SAP-System using XSL-Stylesheets

Hi everyone, I have the following scenario:

I have transformed some Data I retreived from a SAP/R3 System into XML-Format. I now want to send this XML-Data to the Browser as an XML-File where it should be displayed using a XSL-Stylesheet.

Can anyone tell me how this should be done?

Thanks for your help,

Thomas

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Nov 23, 2007 at 03:38 PM

    well, you could do xslt transformation on the serverside (in your servlet)

            OutputStream os = response.getOutputStream();
            Source xmlSource = new StreamSource(xmlFile);
            Source xsltSource = new StreamSource(xsltFile);
    
           
            TransformerFactory transFact = TransformerFactory.newInstance();
            Transformer trans = transFact.newTransformer(xsltSource);
    
            trans.transform(xmlSource, new StreamResult(os));
    
            os.close();
    

    regards franz

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thats sounds like a good idea as well Franz, thank you.

      What I just did now is adding the XSLT-File to the Project as a ressource, so it's now in the src-Folder and therefore I don't have to worry about the path on the server any more. That should solve the problem.

      Thanks for your help guys,

      Thomas

  • avatar image
    Former Member
    Nov 23, 2007 at 07:53 AM

    > Hi everyone, I have the following scenario:

    >

    > I have transformed some Data I retreived from a

    > SAP/R3 System into XML-Format. I now want to send

    > this XML-Data to the Browser as an XML-File where it

    > should be displayed using a XSL-Stylesheet.

    >

    > Can anyone tell me how this should be done?

    >

    > Thanks for your help,

    > Thomas

    Hello Thomas,

    As you have already outlined, the standard way would be to simply (a) write the XML data as text into the HTTP response and (b) include an XML processing instruction specifying the address of the stylesheet (which (c) transforms the XML into HTML).

    Does your question "how this should be done" refer to (a) or (b) (or even to (c))?

    Best regards,

    Jens

    P.S.: Here are some hints to each of the three possibilities:

    (a) I assume you are talking about a servlet context? In this case, do something like

      ...
      ServletOutputStream out = servletResponse.getOutputStream();
      out.write(xmlString.getBytes());
      out.flush();
      out.close();
      ...
    

    (b) Your XML should start with something like

    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <?xml-stylesheet type="text/xsl" href="path/to/my/stylesheet.xsl" ?>
    <root-element>
      ...
    </root-element>
    

    (c) There are countless good XSLT books and websites around, e.g. at http://www.zvon.org/xxl/XSLTutorial/Output/index.html

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Jens,

      yes, I now already have an XML file (a) and it starts correctly so it is displayed in teh browser (b).

      What I'm missing is my Stylesheet, mainly because I don't know where on the NetWeaver Server to put it.

      The context of my servlet is: "http://localhost:50000/Web_Module_Project/servlet"

      if I now for example tell my Sytelsheet to be at "/stylesheets/stylesheetOne.xsl" Where in the file system do I have to put my Stylesheet?

      Thanks for your help,

      Thomas