[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

Subject: Re: 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
stringreader streamsource
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.