import javax.xml.transform.stream.StreamSource;
import net.sf.saxon.s9api.*;
import java.io.File;

public class FifteenStagesS9Multi {

    /**
     * Applies a 15 stage pipeline.
     * args[0] is the input file
     * args[1] is the output file
     */
    public static void main(String[] args)
      throws SaxonApiException
    {
    
      Processor proc = new Processor(false);
      XsltCompiler comp = proc.newXsltCompiler();
        XdmNode in= proc.newDocumentBuilder().build(new StreamSource(new File(args[0])));
        Serializer out= new Serializer();
        out.setOutputFile(new File(args[1]));
        XsltTransformer stage1 = comp.compile(new StreamSource(new File("stage1.xsl"))).load();
        XsltTransformer stage2 = comp.compile(new StreamSource(new File("stage2.xsl"))).load();
        XsltTransformer stage3 = comp.compile(new StreamSource(new File("stage3.xsl"))).load();
        XsltTransformer stage4 = comp.compile(new StreamSource(new File("stage4.xsl"))).load();
        XsltTransformer stage5 = comp.compile(new StreamSource(new File("stage5.xsl"))).load();
        XsltTransformer stage6 = comp.compile(new StreamSource(new File("stage6.xsl"))).load();
        XsltTransformer stage7 = comp.compile(new StreamSource(new File("stage7.xsl"))).load();
        XsltTransformer stage8 = comp.compile(new StreamSource(new File("stage8.xsl"))).load();
        XsltTransformer stage9 = comp.compile(new StreamSource(new File("stage9.xsl"))).load();
        XsltTransformer stage10 = comp.compile(new StreamSource(new File("stage10.xsl"))).load();
        XsltTransformer stage11 = comp.compile(new StreamSource(new File("stage11.xsl"))).load();
        XsltTransformer stage12 = comp.compile(new StreamSource(new File("stage12.xsl"))).load();
        XsltTransformer stage13 = comp.compile(new StreamSource(new File("stage13.xsl"))).load();
        XsltTransformer stage14 = comp.compile(new StreamSource(new File("stage14.xsl"))).load();
        XsltTransformer stage15 = comp.compile(new StreamSource(new File("stage15.xsl"))).load();

        XdmDestination stage1result= new XdmDestination();
        stage1.setDestination(stage1result);
        stage1.setInitialContextNode(in);
        stage1.transform();

        in= null;
        XdmDestination stage2result= new XdmDestination();
        stage2.setDestination(stage2result);
        stage2.setInitialContextNode(stage1result.getXdmNode());
        stage2.transform();

        stage1result= null; stage1= null;
        XdmDestination stage3result= new XdmDestination();
        stage3.setDestination(stage3result);
        stage3.setInitialContextNode(stage2result.getXdmNode());
        stage3.transform();

        stage2result= null; stage2= null;
        XdmDestination stage4result= new XdmDestination();
        stage4.setDestination(stage4result);
        stage4.setInitialContextNode(stage3result.getXdmNode());
        stage4.transform();

        stage3result= null; stage3= null;
        XdmDestination stage5result= new XdmDestination();
        stage5.setDestination(stage5result);
        stage5.setInitialContextNode(stage4result.getXdmNode());
        stage5.transform();

        stage4result= null; stage4= null;
        XdmDestination stage6result= new XdmDestination();
        stage6.setDestination(stage6result);
        stage6.setInitialContextNode(stage5result.getXdmNode());
        stage6.transform();

        stage5result= null; stage5= null;
        XdmDestination stage7result= new XdmDestination();
        stage7.setDestination(stage7result);
        stage7.setInitialContextNode(stage6result.getXdmNode());
        stage7.transform();

        stage6result= null; stage6= null;
        XdmDestination stage8result= new XdmDestination();
        stage8.setDestination(stage8result);
        stage8.setInitialContextNode(stage7result.getXdmNode());
        stage8.transform();

        stage7result= null; stage7= null;
        XdmDestination stage9result= new XdmDestination();
        stage9.setDestination(stage9result);
        stage9.setInitialContextNode(stage8result.getXdmNode());
        stage9.transform();

        stage8result= null; stage8= null;
        XdmDestination stage10result= new XdmDestination();
        stage10.setDestination(stage10result);
        stage10.setInitialContextNode(stage9result.getXdmNode());
        stage10.transform();
        
        stage9result= null; stage9= null;
        XdmDestination stage11result= new XdmDestination();
        stage11.setDestination(stage11result);
        stage11.setInitialContextNode(stage10result.getXdmNode());
        stage11.transform();
        
        stage10result= null; stage10= null;
        XdmDestination stage12result= new XdmDestination();
        stage12.setDestination(stage12result);
        stage12.setInitialContextNode(stage11result.getXdmNode());
        stage12.transform();
        
        stage11result= null; stage11= null;
        XdmDestination stage13result= new XdmDestination();
        stage13.setDestination(stage13result);
        stage13.setInitialContextNode(stage12result.getXdmNode());
        stage13.transform();
        
        stage12result= null; stage12= null;
        XdmDestination stage14result= new XdmDestination();
        stage14.setDestination(stage14result);
        stage14.setInitialContextNode(stage13result.getXdmNode());
        stage14.transform();
        
        stage13result= null; stage13= null;
        XdmDestination stage15result= new XdmDestination();
        stage15.setDestination(out);
        stage15.setInitialContextNode(stage14result.getXdmNode());
        stage15.transform();
        
        stage14result= null; stage14= null;
        stage15result= null; stage15= null;
    }
}
