[jdom-interest] HTML Transformation from xml/xsl

Peter.H.Roberts at bbh.com Peter.H.Roberts at bbh.com
Tue Oct 2 13:01:40 PDT 2001


Hello,

     I am currently using Xalan's Transformer Factory to output HTML from an XML/XSL transformation:-

public void transform (  PrintWriter out, String xmlFile,String xslFile)
       throws IOException, java.net.MalformedURLException
{
     System.out.println("transform JdomB6 " + CDSNJ.EOL +
                            xmlFile + " " + CDSNJ.EOL + xslFile);
     // Output goes in the response stream.
                InputStream xmlStream = null;
                InputStream xslStream = null;
     try
     {
       TransformerFactory tFactory = TransformerFactory.newInstance();
       URL xmlURL = new URL( xmlFile );
       java.net.URLConnection xmlURLConn = xmlURL.openConnection();
       xmlStream = xmlURLConn.getInputStream();
       Source xmlSource = new StreamSource(xmlStream);
       URL xslURL = new URL( xslFile );
       java.net.URLConnection xslURLConn = xslURL.openConnection();
       xslStream = xslURLConn.getInputStream();
       Source xslSource = new StreamSource(xslStream);
       // Generate the transformer.
       Transformer transformer = tFactory.newTransformer(xslSource);
       // Perform the transformation, sending the output to the response.
       transformer.transform(xmlSource, new StreamResult(out));
     }    catch (Exception e) {
       out.write(e.getMessage());
       e.printStackTrace(out);
     } finally {
       xmlStream.close();
       xslStream.close();
     }
}

Is this the preffered way of doing this, I see you have added new JDOMResult and JDOMSOurce but these only create Dom's after a transform.

Peter.





More information about the jdom-interest mailing list