// --SAXTransformerFactory is an interface
// --TransformerFactory is a concrete class
// --TransformerFactory actually returns a SAXTransformerFactory instance
// --We didn't care about that before, because we didn't use the
// --SAXTransformerFactory extensions. But now we do, so we cast the result.
SAXTransformerFactory stf =
(SAXTransformerFactory) TransformerFactory.newInstance();
XMLFilter filter1 = stf.newXMLFilter(new StreamSource(stylesheet1));
XMLFilter filter2 = stf.newXMLFilter(new StreamSource(stylesheet2));
// Wire the output of the reader to filter1
// and the output of filter1 to filter2
// --A filter is a kind of reader
// --Setting the parent sets the input reader
// --Since a filter is a reader, the "parent" could be another filter
filter1.setParent(reader);
filter2.setParent(filter1);
// Set up the output stream
StreamResult result = new StreamResult(System.out);
// Set up the transformer to process the SAX events generated
// by the last filter in the chain
Transformer transformer = stf.newTransformer();
SAXSource transformSource = new SAXSource(filter2, input);
transformer.transform(transformSource, result);
}
catch (TransformerConfigurationException tce) {
// Error generated by the parser