You could pass a list of file names to your xsl as a parameter and retrieve them in the stylesheet using the doc() function.

-Mike

On 6/20/13 8:40 AM, 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