Plugging in the TransformerTo transform a dom4jb generated DOM or XPath tree by means of XSLT, you can use the transformation API for XML (TrAX) . The steps needed to plug such a dom4jb generated tree into the transformer are almost the same, as plugging in any other javax.xml.transform.Source object. In detail, you have to do the following steps:
For example, these steps could be done as follows:
import javax.xml.transform.Source;
import javax.xml.transform.Result;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import com.teamkonzept.dom4jb.dom.Document;
import com.teamkonzept.dom4jb.dom.Element;
...
// instantiate the root of the object, which should be
// transformed
Address address = new Address("Michael Mueller",
"Berliner Str. 12", "Berlin");
// instantiate transformer
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
// instantiate dom4jb DOM document
Document document = new Document();
// instantiate root element and plug it into the document
Element root = document.createElement("address", address);
document.appendChild(root);
// instantiate source object
Source src = new DOMSource(document);
// instantiate result object
Result result = new StreamResult(writer);
// do transformation
transformer.transform(src, result);
If you prefer to use the XPath implementation for the saxon processor - which is currently the more efficient way. Then the only thing you have to do is, use a com.teamkonzept.dom4jb.saxon.Document object instead of the com.teamkonzept.dom4jb.dom.Document object, w.r.t. the example above. |