Main components or actors for achieving this:
- XSL Stylesheet
- XML document (input data)
- JAXP Transform libraries
JAXP’s interpreting implementation of XSLT is Xalan. JAXP’s transformation libraries are found under javax.xml.transform package.
javax.xml.transform:
- Defines basic set of interfaces for XSLT processors.
- Defines factory class you use to get a Transformer object.
- You can configure the transformer with input and output objects, and invoke its transform() method to make the actual transformation.
- DOM (javax.xml.transform.dom) – uses DOM.
- SAX (javax.xml.transform.sax) – uses SAX event generator.
- Stream (javax.xml.transform.stream) – uses I/O stream.
try {
TransformerFactory factory = TransformerFactory.newInstance();
// Specify XSL document
Transformer transformer = factory.newTransformer(new StreamSource(xsl-document));
// Specify XML Input
StreamSource xmlsource = new StreamSource(xml-input);
// Specify Target Output
StreamResult output = new StreamResult(System.out);
// Do the magic
transformer.transform(xmlsource, output);
} catch (TransformerException) {
// Handle Exception Code
}
No comments:
Post a Comment