package com.alethis.xml;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerException;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.Source;
import javax.xml.transform.Result;
import javax.xml.transform.OutputKeys;

public class TransformUsingXSLT {

    private static final String INPUT_FILE = "c:\\project\\xml\\in.xml";
    private static final String XSL_FILE   = "c:\\project\\xml\\trans.xsl";
    
    public static void main(String[] args) {

        /*
         *  System.setProperty("javax.xml.transform.TransformerFactory", "className");
         *     org.apache.xalan.processor.TransformerFactoryImpl
         *     com.icl.saxon.TransformerFactoryImpl  (Saxon 6)
         *     net.sf.saxon.TransformerFactoryImpl   (Saxon 7)
         *     oracle.xml.jaxp.JXSAXTransformerFactory
         */
        
        try {
            Source input  = new StreamSource(INPUT_FILE);
            Source xsl    = new StreamSource(XSL_FILE);
            Result output = new StreamResult(System.out);

            TransformerFactory factory = TransformerFactory.newInstance();
            Transformer transformer = factory.newTransformer(xsl);
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.transform(input, output);
        }
        catch (TransformerException te) {
            System.out.println("Transformer exception: " + te.getMessage());
        }
    }
}