XML + XSLT help!!

Discussions

XML & Web services: XML + XSLT help!!

  1. XML + XSLT help!! (3 messages)

    I'm using Xerces and Xalan for my parsers.

    Basically I have two Strings, one is an XML document in String form, and the other is an XSL stylesheet in String form. I'm a newbie at XML so I haven't seen many examples where raw String input is used; all I see is the classic InputSource object.

    I am dynamically creating XML and XSL stylesheets and want to convert them into HTML output.

    Any ideas about how to do this? Some sample code would help a lot! TIA

    Threaded Messages (3)

  2. XML + XSLT help!![ Go to top ]

    u can use a xslt processor,such as lotusxsl.
    u can got it form ibm.alphawork site,and it has samples
  3. XML + XSLT help!![ Go to top ]

    Here is one way. create a java.io.StringReader with your String, then create a javax.xml.transform.stream.StreamSource with your StringReader. You can pass the StreamSource to the transformer.

    Say your XML and XSL are stored in the Strings strXML and strXSL respectively.

    Create the StreamSource object with the XML String:

    StringReader srXML = new StringReader(strXML);
    StreamSource ssXML = new StreamSource(srXML);

    Or do this one-liner:

    StreamSource ssXML = new StreamSource(new StringReader(strXML));

    Do the same for XSL:

    StreamSource ssXSL = new StreamSource(new StringReader(strXSL));

    They are ready for the transformer:

    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer trans = factory.newTransformer(ssXSL);
    Writer output = response.getWriter();
    trans.transform(ssXML, new StreamResult(output));
    output.flush();

    In all, you'll need to import the following classes:
    java.io.StringReader
    javax.xml.transform.Transformer
    javax.xml.transform.TransformerFactory
    javax.xml.transform.stream.StreamSource
    javax.xml.transform.stream.StreamResult
  4. thanks a lot![ Go to top ]

    Hey James,

    I was just about to post that I figured out how to make a reader (via StringReader), but I really appreciate the sample source that you've provided. Thank you very much!

    -j yi