I can now generate an HTML file using the code:
FileInputStream xml = new FileInputStream("original.xml");
FileInputStream xsl = new FileInputStream("converter.xsl");
FileOutputStream out = new FileOutputStream("result.html");
Source xmlDoc = new StreamSource(xml);
Source xslDoc = new StreamSource(xsl);
Result result = new StreamResult(out);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer trans = factory.newTransformer(xslDoc);
trans.transform(xmlDoc, result);
However, I want to generate a Java String instead of an external HTML file, so that I can pass the result back to my JSP page by Ajax callback. How can I modify this code to do that?