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
-
XML + XSLT help!! (3 messages)
- Posted by: joseph yi
- Posted on: November 08 2001 02:56 EST
Threaded Messages (3)
- XML + XSLT help!! by dong chengcheng on November 08 2001 03:02 EST
- XML + XSLT help!! by Jim Hall on November 08 2001 12:26 EST
- thanks a lot! by joseph yi on November 08 2001 13:39 EST
-
XML + XSLT help!![ Go to top ]
- Posted by: dong chengcheng
- Posted on: November 08 2001 03:02 EST
- in response to joseph yi
u can use a xslt processor,such as lotusxsl.
u can got it form ibm.alphawork site,and it has samples -
XML + XSLT help!![ Go to top ]
- Posted by: Jim Hall
- Posted on: November 08 2001 12:26 EST
- in response to dong chengcheng
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 -
thanks a lot![ Go to top ]
- Posted by: joseph yi
- Posted on: November 08 2001 13:39 EST
- in response to joseph yi
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