|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileNotFoundException;
|
|
import javax.xml.transform.stream.StreamSource;
|
|
|
|
import net.sf.saxon.s9api.Processor;
|
|
import net.sf.saxon.s9api.Serializer;
|
|
import net.sf.saxon.s9api.SaxonApiException;
|
|
import net.sf.saxon.s9api.XsltCompiler;
|
|
import net.sf.saxon.s9api.XsltExecutable;
|
|
import net.sf.saxon.s9api.XsltTransformer;
|
|
|
|
public class Pipeline {
|
|
private Processor processor = null;
|
|
private XsltCompiler xslt_compiler1 = null;
|
|
private XsltCompiler xslt_compiler2 = null;
|
|
private XsltExecutable xslt_executable1 = null;
|
|
private XsltExecutable xslt_executable2 = null;
|
|
private XsltTransformer xslt_transformer1 = null;
|
|
private XsltTransformer xslt_transformer2 = null;
|
|
private Serializer destination2 = null;
|
|
private File xslt1 = new File("echo_given_sourcefile.xsl");
|
|
private File xslt2 = new File("print_elements.xsl");
|
|
|
|
|
|
public Pipeline() {
|
|
// common processor
|
|
processor = new Processor(false);
|
|
|
|
// transformer1
|
|
xslt_compiler1 = processor.newXsltCompiler();
|
|
|
|
try {
|
|
xslt_executable1 = xslt_compiler1.compile(new StreamSource(new FileInputStream(xslt1)));
|
|
} catch (FileNotFoundException e) {
|
|
e.printStackTrace();
|
|
} catch (SaxonApiException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
xslt_transformer1 = xslt_executable1.load();
|
|
|
|
// set source file
|
|
try {
|
|
xslt_transformer1.setSource(new StreamSource(new FileInputStream(xslt1))); // itself
|
|
} catch (FileNotFoundException e) {
|
|
e.printStackTrace();
|
|
} catch (SaxonApiException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
|
|
// transformer2
|
|
xslt_compiler2 = processor.newXsltCompiler();
|
|
try {
|
|
xslt_executable2 = xslt_compiler2.compile(new StreamSource(new FileInputStream(xslt2)));
|
|
} catch (FileNotFoundException e) {
|
|
e.printStackTrace();
|
|
} catch (SaxonApiException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
xslt_transformer2 = xslt_executable2.load();
|
|
|
|
// transformer2's destination
|
|
destination2 = new Serializer(System.out);
|
|
xslt_transformer2.setDestination(destination2);
|
|
|
|
// transformer1's destination
|
|
xslt_transformer1.setDestination(xslt_transformer2);
|
|
|
|
/*
|
|
// omit xml declaration in transformer2
|
|
xslt_transformer2.getUnderlyingController().setOutputProperty("omit-xml-declaration", "yes");
|
|
*/
|
|
|
|
// run transformation
|
|
try {
|
|
xslt_transformer1.transform();
|
|
} catch (SaxonApiException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
Pipeline p = new Pipeline();
|
|
}
|
|
}
|