import java.io.*; // JAXP packages import javax.xml.transform.*; import javax.xml.transform.stream.*; /** * Transform uses the XSL Transformation API to transform a given XML file * using a given XSL stylesheet. * * @author Thornton Rose * @version 1.0 */ public class Transform { /** * Construct an instance of this class. */ public Transform() { } //-------------------------------------------------------------------------- /** * Run the program. */ public static void main(String[] args) { // If not enough args, print usage. if (args.length < 2) { System.out.println( "Usage: Transform stylesheet xml-file"); System.exit(0); } // Get command-line args. File xslFile = new File(args[0]); File xmlFile = new File(args[1]); // Create xsl source, input source, and result streams. StreamSource xslSource = new StreamSource(xslFile); StreamSource xmlSource = new StreamSource(xmlFile); StreamResult outResult = new StreamResult(System.out); try { // Get transformer factory and transformer. TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(xslSource); // Do transformation. transformer.transform(xmlSource, outResult); } catch(Exception ex) { System.out.println(ex); } } }