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
u can use a xslt processor,such as lotusxsl.
u can got it form ibm.alphawork site,and it has samples
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));
In all, you'll need to import the following classes:
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!