// --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