Subject: Re: [xsl] Invoking XALAN API with an in-memory XML/XSL string From: "Roger L. Costello" <costello@xxxxxxxxx> Date: Thu, 18 Apr 2002 09:16:28 -0400 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Invoking XALAN API with a, Michael Kay | Thread | correction*Re: [xsl] Str:tokenize m, Vasu Chakkera |
RE: [xsl] Matching values in the XM, Jarno . Elovirta | Date | RE: [xsl] XSL manipulating two XMLs, Najmi, Jamal |
Month |