{
// Use the XSLTProcessorFactory to create a processor.
XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
// Compile the two stylesheets.
StylesheetRoot stylesheet = processor.processStylesheet("foo.xsl");
StylesheetRoot stylesheet2 = processor.processStylesheet("foo2.xsl");
// Don't really need to set the processor Stylesheet property, since it's
// still set from the 2nd processStylesheet, but it's good form....
processor.setStylesheet(stylesheet2);
// Get and set a DocumentHandler for final output.
processor.setDocumentHandler(stylesheet2.getSAXSerializer(System.out));
// Use the processor (which extends DocumentHandler) to instantiate the
// XSLTResultTarget object for the first transform.
XSLTResultTarget firstResult = new XSLTResultTarget(processor);
// firstResult now functions as a SAX DocumentHandler.