This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Invoking XSLT styling from a Java servlet


Hi Folks,

Below is Java code to invoke XALAN with in-memory strings, representing
the XML and Stylesheet respectively.  I know that this code works.  I
have a program which invokes this method and it works great.

However, when I use this method within a Java servlet it fails.  I have
traced it down to this statement:

   Transformer transformer = tFactory.newTransformer(xsl_ss);

The javadocs mention this for the newTransformer() method: "Care must be
given not to use this object in multiple threads running concurrently". 
I am not running multiple threads in my servlet.  So, I can't imagine
that that is the problem.  I am really clueless as to what could be
going wrong.  Any help would be much appreciated.  [I am using Tomcat
4.0.3 as the Web server.]  /Roger

    // This code shows how to invoke xalan by passing to it the 
    // xml and xsl as 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);
        ** the following statement is where it fails **
        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();
    }


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]