[jdom-interest] JDOM and XSL

Tony Montgomery Smith tonyms at compuserve.com
Sun Feb 4 14:12:34 PST 2001

I tried Jan Peter Heckings suggestion (26 Jan). It needs a try/catch, because
there are lots of potential exceptions in there.

No problem, but I was stuck when it then complained that I hadn't set the system
property "javax.xml.transform.TransformerFactory". I tried setting it to:
"javax.xml.transform.sax.SAXTransformerFactory", but that didn't work.

Because I needed it to work quickly, I used the "brute force" technique at the
end of this note, which works fine.

2 routes to explore when I get time/get clever enough are:

*The tranformer result can be set to be a DOM document, and the DOM document can
be conveted to JDOM using the JDOM DOMBuilder
*Possibly best, if you can work it out, Xalan allows you to chain filters (see
UseXMLFilters). In principle, maybe the JDOM SAXBuilder can be made to join the

Brute force example:

  public Document transform(BufferedReader bufferedReader, String fileName)
    Document targetDoc = null;
      Processor processor = Processor.newInstance("xslt");
      Templates templates = processor.process(new InputSource(fileName));
      Transformer transformer = templates.newTransformer();
      CharArrayWriter cAW = new CharArrayWriter();

      transformer.transform(new InputSource(bufferedReader), new Result(cAW));
      SAXBuilder saxBuilder = new SAXBuilder();
      targetDoc = saxBuilder.build(new CharArrayReader(cAW.toCharArray()));
    catch (Exception e)
    return targetDoc;

More information about the jdom-interest mailing list