Thanks for your help. I have got it working based on your advice.

public class XslTester {
    public static void main(String ... args) throws Exception {
        Source xslSource = new StreamSource(XslTester.class.getResourceAsStream("MT103-STD.xsl"));
        Source xmlSource = new StreamSource(XslTester.class.getResourceAsStream("GPG-10.xml"));
        Processor processor = new Processor(false);
        MyOutputUriResolver outputUriResolver = new MyOutputUriResolver();
        processor.setConfigurationProperty(FeatureKeys.OUTPUT_URI_RESOLVER, outputUriResolver);
        XsltCompiler xsltCompiler = processor.newXsltCompiler();
        XsltExecutable xsltExecutable = xsltCompiler.compile(xslSource);
        XsltTransformer xsltTransformer = xsltExecutable.load();
        xsltTransformer.setParameter(new QName("region"), new XdmAtomicValue("APAC"));
        xsltTransformer.setDestination(new Serializer());
    private static class MyOutputUriResolver implements OutputURIResolver {
        private Map<String, StringWriter> results = new HashMap<String, StringWriter>();

        public void close(Result result) throws TransformerException {

        public Result resolve(String href, String base) throws TransformerException {
            StringWriter stringWriter = new StringWriter();
            results.put(href, stringWriter);
            return new StreamResult(stringWriter);
        public void flush() {
        public String getResullt(String href) {
            if (results.containsKey(href)) {
                return results.get(href).toString();
            } else {
                return null;


Kind regards

On Sun, Sep 5, 2010 at 1:27 PM, Meeraj Kunnumpurath <mkunnumpurath@googlemail.com> wrote:
Thanks Michael, for the extremely quick response. Couple of questions please,

1. Do I register the FQN of the OutputURIResolver implementation or an instance?
2. If it is an instance I would assume it is thread unsafe. However, if I use them serially do I need to flush between the transform calls?


On Sun, Sep 5, 2010 at 1:09 PM, Michael Kay <mike@saxonica.com> wrote:

> One of the requirements I have is to generate multiple documents
> (which are text output) out of the transformation. However, I don't
> want the result text output to be written to the file system, rather,
> I would like to get some in-memory reference to a stream or a byte array.
> 1. Can this be done using standard JAXP/TRAX API?

The standard JAXP/TRAX API only handles XSLT 1.0, it therefore doesn't
handle multiple output files at all.

In Saxon, if you want to capture multiple output files without writing
them to filestore, you need to write and register an OutputURIResolver.
> 2. I have implemented this using a custom destination and emitter
> using the Saxon API as below. Is there a better way of doing this?
I think using an OutputURIResolver is simpler. You can register it as

processor.setConfigurationProperty(FeatureKeys.OUTPUT_URI_RESOLVER_CLASS, "com.me.MyOutputURIResolver")

and it will be called when each output file is opened and closed.

Michael Kay

This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
saxon-help mailing list archived at http://saxon.markmail.org/