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
Saxonica


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

Hi
 
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,
 
Thanks.
 
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);
             
              try
              {
                     SchemaManager schemaManager = proc.getSchemaManager();
                    
                     System.out.println("Loading input XSD");
                     schemaManager.load(inputXsdSource);
                     System.out.println("Done");
                    
                     System.out.println("Validating input XML");
                     schemaManager.newSchemaValidator().validate(inputXmlSource);
                     System.out.println("Done");
 
                     XsltCompiler compiler = proc.newXsltCompiler();
                    
                     System.out.println("Compiling XSLT");
                     XsltExecutable xsltExec = compiler.compile(xsltSource);
                     System.out.println("Done");
                    
                     System.out.println("Loading XSLT");
                     XsltTransformer transformer = xsltExec.load();
                     System.out.println("Done");
                    
                     transformer.setSource(inputXmlSource);
                     transformer.setDestination(target);
                    
                     System.out.println("Transforming");
                     transformer.transform();
                     System.out.println("Done");
              }
              catch (Exception ex)
              {
                     System.out.println(ex.getMessage());
              }
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help