Java XML – JDOM2 – XSLTransformation

JDOM2 has classes that perform XSL transformation of the JDOM2 document. The input to the transformation is the JDOM2 document and an XML stylesheet and the output is whatever transformation the stylesheet specifies. In the example below we look at JDOM2 to do HTML transformation. By default, JDOM2 uses the JAXP TrAX classes for transformation. The important classes are :

  • JDOMSource – This class holds the input for the transformation. It can be a Document, node or list of nodes.
  • JDOMResult – This class holds the result of the transformation. It is generally a list of nodes or a JDOM2 document. The result tree may not be a well formed XML document.
  • XSLTranfomer – The class that wraps the transformation. It uses the JAXP TrAX classes for actual transformation. The javax.xml.transform.TransformerFactory java system property determines which XSLT engine is to be used. As specified in the code documentation this could be
    • Saxon 6.x: com.icl.saxon.TransformerFactoryImpl
    • Saxon 7.x: net.sf.saxon.TransformerFactoryImpl
    • Xalan: org.apache.xalan.processor.TransformerFactoryImpl
    • jd.xslt: jd.xml.xslt.trax.TransformerFactoryImpl
    • Oracle: oracle.xml.jaxp.JXSAXTransformerFactory

Lets look at an example of a transformation.The source XML can be downloaded from
and the xsl can be downloaded from

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to top