[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Invoking XALAN API with an in-memory XML/XSL strin
Michael Kay wrote: > > Just give the parser the character string to play with directly: > > StringReader sr = new StringReader(xsl); > StreamSource ss = new StreamSource(ss); Thanks Michael! It works great. For those who might be interested, here is the Java code to do transformations either in-memory, or from files: // This code shows how to do a transformation where the xml and // xsl are in-memory strings public static String doTransform(String xml, String xsl) throws TransformerException, TransformerConfigurationException, FileNotFoundException, IOException { TransformerFactory tFactory = TransformerFactory.newInstance(); StringReader xsl_sr = new StringReader(xsl); StreamSource xsl_ss = new StreamSource(xsl_sr); Transformer transformer = tFactory.newTransformer(xsl_ss); StringReader xml_sr = new StringReader(xml); StreamSource xml_ss = new StreamSource(xml_sr); StringWriter out_sw = new StringWriter(); StreamResult out_sr = new StreamResult(out_sw); transformer.transform(xml_ss, out_sr); return out_sw.toString(); } // This code shows how to transformation where the xml and // xsl are files. The result is sent to a file. public static void doTransform(String xmlfilename, String xslfilename, String outfilename) throws TransformerException, TransformerConfigurationException, FileNotFoundException, IOException { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(new StreamSource(xslfilename)); transformer.transform(new StreamSource(xmlfilename), new StreamResult(new FileOutputStream(outfilename))); } /Roger XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|