4 Wrapper for the Saxon processor to be easily invoked from BSH.
6 Author: Ovidiu Predescu <ovidiu@cup.hp.com>
9 Copyright (C) 2000 Ovidiu Predescu
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
29 import java.io.InputStream;
31 import com.icl.saxon.StyleSheet;
32 import org.xml.sax.InputSource;
33 import com.icl.saxon.ParameterSet;
34 import com.icl.saxon.trax.Processor;
35 import com.icl.saxon.trax.Templates;
36 import com.icl.saxon.trax.Transformer;
37 import com.icl.saxon.trax.serialize.Method;
38 import com.icl.saxon.trax.serialize.OutputFormat;
39 import java.io.FileOutputStream;
40 import com.icl.saxon.trax.Result;
44 public static void invoke(String filename, String outFilename)
47 URL top = new URL("file:/");
48 URL url = new URL(top, filename);
49 filename = url.toExternalForm();
50 Processor processor = Processor.newInstance("xslt");
51 InputSource docSource = new InputSource(filename);
53 = processor.getAssociatedStylesheets(docSource, null, null, null);
55 if (sources == null) {
56 System.err.println("No stylesheet found");
60 FileOutputStream out = new FileOutputStream(outFilename);
61 Result result = new Result(out);
62 Templates templates = processor.processMultiple(sources);
63 Transformer transformer = templates.newTransformer();
64 OutputFormat format = new OutputFormat();
65 format.setMethod(Method.XML);
66 format.setIndenting(true);
68 transformer.setOutputFormat(format);
69 transformer.transform(docSource, result);
73 System.err.println("Cannot process: " + e);