Some recent coding (a rewrite of the “netMetric” toolset”) required an XML file to be transformed by an XSLT stylesheet and the results that transformed further by another stylesheet. This is simple enough to do by writing the output of the first transform to a temporary file and then using that as as the input to the second step. But that’s yuck - we want to seamlessly pass the first result as the input to the second. Chaining is one of the more powerful features of XSLT, and thanks to a post at blogger.ziesemer.com easy enough to achieve: class variables: Templates tgraphml;Templates talter;SAXTransformerFactory tFactory; setup in class constructor: // once parsed we can reuse these templatestFactory = (SAXTransformerFactory) TransformerFactory.newInstance();template1 = tFactory.newTemplates(new StreamSource(getClass().getResourceAsStream("transform1.xsl")));template2 = tFactory.newTemplates(new StreamSource(getClass().getResourceAsStream("transform2.xsl"))); in the class method doing the transform: TransformerHandler handler1 = tFactory.newTransformerHandler(template1);TransformerHandler handler2 = tFactory.newTransformerHandler(template2);// setup handler1 so it automatically passes its output onto handler2// then handler2 writes to final outputhandler1.setResult(new SAXResult(handler2));handler2.setResult(new StreamResult(new File("output.xml") ));Transformer t = tFactory.newTransformer();t.transform(new StreamSource( new File("input.xml"), new SAXResult(handler1)); Bingo! this all works nicely and faster than writing to temporary files. But then I wanted to pass parameters into the stylesheets and it got complicated. At first I thought it was a bug in Xalan (the XSLT processor) [1] or a problem with namespaces. The solution was to set the parameters on the transform associated with the handler NOT the transformer ‘t’ being used at the end… i.e. final String NAMESPACE_PREFIX = "{http://graphml.graphdrawing.org/xmlns}";handler2.getTransformer().setParameter(NAMESPACE_PREFIX + "system", settings.getSystem()); Attached is the second XSLT stylesheet (template2) which will add a section into a graphml file. This allows information about the graph to be stored in the graph itself - much neater. [1] a common thought for developers when their code doesn’t work.