Thanks. I have it working now with two input XML files (from different XSDs).


I have a couple of questions:


-          Before  I run the transformer, I must provide a source with XsltTransformer::setSource(), but we get our sources from the CollectionURIResolver implementation, so it would be handy if the transform could run without having to set the source initially (unless I’m misunderstanding and it is required, this is my first encounter with XSLT, MapForce and Saxon)

-          My initial email had another reply from Michael Sokolov saying I could pass the input file names as a parameter in the stylesheet using the doc() function – would this be preferable to using the CollectionURIResolver?






From: Michael Kay []
Sent: 21 June 2013 10:49
To: Mailing list for the SAXON XSLT and XQuery processor
Subject: Re: [saxon] Java API: transforms with multiple XML input files


The CollectionURIResolver can either return a sequence of nodes, or a sequence of URIs (or, IIRC, a mix of nodes and URIs, but that's unlikely).


If you choose to return nodes, they must implement the Saxon NodeInfo interface. They will usually be document nodes implementing DocumentInfo, but this is not necessary. Typically you can build the nodes using Configuration.buildDocument(), where the Configuration can be obtained from your s9api Processor using getUnderlyingConfiguration(). Or you could wrap a DOM Node.


If you choose to return URIs, they must be presented as instances of AnyURIValue. Saxon will obtain a document corresponding to each URI by effectively calling the doc() function. If you're starting with a File object, use new AnyURIValue(File.toURI().toString()) to create the AnyURIValue.


The sequence is returned in the form of a SequenceIterator. If you're happy to construct the list of nodes or URIs as a list in memory, then the simplest way of doing this is to build a List<NodeInfo> or List<AnyURIValue>, and then return a net.sf.saxon.tree.iter.ListIterator that wraps this list.


Michael Kay




On 21 Jun 2013, at 09:51, Urquhart, Callum wrote:




I’ve started to implement your second suggestion but I’m having problems with the collection URI resolver. The resolve() method must return an iterator to the sequence of files, a SequenceIterator, but I’m completely confused on which type this sequence is and therefore how to create a SequenceIterator from it. I assumed a collection of strings or object that represents a file URI would suffice but I can’t see which data type these should all be, can you advise?




From: Michael Kay [] 
Sent: 20 June 2013 14:13
To: Mailing list for the SAXON XSLT and XQuery processor
Subject: Re: [saxon] Java API: transforms with multiple XML input files


There are two ways you could do this.


One is to pass a sequence of document nodes as a parameter to the transformation. Given a file, you can construct an XdmNode using a s9api DocumentBuilder, and then you can construct a sequence containing these nodes using the XdmValue constructor. You then pass this as a parameter using transformer.setParameter(). You declare the parameter at the top level of the stylesheet using xsl:param. You can either supply a dummy "main input document" to the stylesheet, or start the execution at a named template.


Another way is to use a collection - typically the default (unnamed) collection. Define a class that implements CollectionURIResolver, and that returns the required documents when it is called; register it using processor.setConfigurationProperty(FeatureKeys.COLLECTION_URI_RESOLVER), and then get the collection using something like


<xsl:for-each select="collection()">


Michael Kay




On 20 Jun 2013, at 13:40, Urquhart, Callum wrote:



I am investigating software and libraries we can use to perform a series of transformations. The plan is to use MapForce to produce XSLTs and use the Java API of Saxon-EE to perform the actual transformations.


We need the ability to input several XML files into the same XSLT (i.e. merge/combine functionality) and produce the appropriate output (one or several files). I have some basic code (below) which uses the Saxon Java API to transform a single XML to single output file, but I can’t immediately see how to handle multiple input files into the same XSLT with the Java API. Is it possible, and if so , how do I do so?


I have seen examples via Google that use the command line to feed several XML files into an XSLT, but it’s not clear if this is feeding each XML file into the XSLT separately, or feeding all XML files into the XSLT in one operation.


Any help or comments would be useful,




Test code:


StreamSource inputXsdSource = new StreamSource(new File("mf-ExpReport.xsd"));

              StreamSource inputXmlSource = new StreamSource(new File("mf-ExpReport.xml"));

              StreamSource xsltSource = new StreamSource(new File("MappingMapToExpReport-Target.xslt"));

              Serializer target = new Serializer(new File ("output.xml"));


              Processor proc = new net.sf.saxon.s9api.Processor(true);




                     SchemaManager schemaManager = proc.getSchemaManager();


                     System.out.println("Loading input XSD");




                     System.out.println("Validating input XML");




                     XsltCompiler compiler = proc.newXsltCompiler();


                     System.out.println("Compiling XSLT");

                     XsltExecutable xsltExec = compiler.compile(xsltSource);



                     System.out.println("Loading XSLT");

                     XsltTransformer transformer = xsltExec.load();










              catch (Exception ex)




This email is sponsored by Windows:

Build for Windows Store.
saxon-help mailing list archived at


This email is sponsored by Windows:

Build for Windows Store.
saxon-help mailing list archived at