[jdom-interest] Best practices when using JDOM with XSLT and Servlets 2.2

Laurent Bihanic laurent.bihanic at atosorigin.com
Thu Mar 21 00:44:00 PST 2002


Hi Rob,

The best way to interface JDOM to XSLT processors is to use the 
org.jdom.transform.JDOMSource and org.jdom.transform.JDOMResult. These classes 
extends the javax.xml.transform.sax.SAXSource/SAXResult and should be 
recognized by all XSLT processors using SAX. Xalan and Saxon do.

Using JDOMSource is as simple as:
    templates.newTransformer().transform(new JDOMSource(myDoc), result);

result being a StreamResult wrapping response.getWriter().

Laurent


Rob Finneran wrote:
> Hello,
> 
> I'm using xerces-j 2.0.1, xalan-j 2.3.1, with jdom b8-rc1. I'm also using
> Jetty 3.1.3 which is a servlets 2.2 engine very simuliar to tomcat 3.2.
> 
> I dynamically build a JDOM tree from a database and I want to know the best
> pattern for apply a javax.xml.transform.Templates to the JDOM tree
> and then to send the result as html back to the browser.
> 
> Is the best method to use a SAX events outputter to a StringWriter() stream
> and then to send the String back to the browser via the servlet's
> Printwriter obtained via response.getWriter()? Doesn't the servlet buffer
> the response anyway, so the StringWriter output stream would be redundant.
> 
> I've seen something mentioned about sockets in the FAQ and I saw Brett M's
> example article, but I'm a little new to some of the java IO classes and
> coding patterns.
> 
> Any steering would be appreciated!!!
> 
> TIA
> 
> Rob




More information about the jdom-interest mailing list