On 18/10/2010 10:50, Christophe Marchand wrote:
                TransformerFactory tFactory = new net.sf.saxon.TransformerFactoryImpl();
                Transformer t = tFactory.newTransformer(new StreamSource(this.getClass().getClassLoader().getResourceAsStream("com/continental/corporation/yourXsl.xsl")));
                OutputStream out = new FileOutputStream(outputFile);
                t.transform(new DOMSource(yourDomStructure), new StreamResult(out));
                out.close();


This example supposed your XSL is in your sources, and then copied into your jar file.

Thanks for responding to this enquiry. But I wouldn't recommend using a DOMSource unless there is a very good reason: Saxon is much more efficient when you allow Saxon to build the source tree in its own format, rather than using a DOM.

So the example might become

                TransformerFactory tFactory = new net.sf.saxon.TransformerFactoryImpl();
                Transformer t = tFactory.newTransformer(new StreamSource(this.getClass().getClassLoader().getResourceAsStream("com/continental/corporation/yourXsl.xsl")));
                OutputStream out = new FileOutputStream(outputFile);
                t.transform(new StreamSource(xmlInputURL), new StreamResult(out));
                out.close();


More generally, information about running XSLT from Java can be found at

http://www.saxonica.com/documentation/using-xsl/embedding.html

The example given by Cristophe uses the JAXP interface. You can find more examples of how to use JAXP in the sample program TraxExamples.java which is included in the saxon-resources download file (available on SourceForge as an optional download). This download also includes examples for the s9api API, which is the Saxon-specific transformation API.

Michael Kay
Saxonica