import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;

/**
 * Transform an XML file with an XSLT program
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class XSLT
{

    /**
     * The entry-point of the application
     *
     * @param args   The command line arguments (.xml, .xsl)
     */
    public static void main(String[] args) throws Exception
    {
        ByteArrayOutputStream    bos;
	StreamResult             result;
	StreamSource             program, source;
	Transformer              transformer;
	TransformerFactory       factory;



	// Create the streams
	source  = new StreamSource(new File(args[0]));
	program = new StreamSource(new File(args[1]));

        bos = new ByteArrayOutputStream(65536);// So we can process the result
	result  = new StreamResult(bos);


	// Create the factory
	factory = TransformerFactory.newInstance();
	transformer = factory.newTransformer(program);

	// Perform the transformation
	transformer.transform(source, result);

        // Print to the console
        System.out.print(bos.toString());
        
    }
}
