import java.io.File; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; public class Transform { /** * Performs an XSLT transformation, sending the results to System.out. * * @param args the command-line arguments */ public static void main(String[] args) { if (args.length != 2) { System.err.println("Usage: java Transform [xmlfile] [xsltfile]"); System.exit(1); } File xmlFile = new File(args[0]); File xsltFile = new File(args[1]); // JAXP reads data using the Source interface Source xmlSource = new StreamSource(xmlFile); Source xsltSource = new StreamSource(xsltFile); // The factory pattern supports different XSLT processors TransformerFactory transFact = TransformerFactory.newInstance(); try { Transformer trans = transFact.newTransformer(xsltSource); trans.transform(xmlSource, new StreamResult(System.out)); } catch (TransformerConfigurationException tce) { System.err.println(tce); } catch (TransformerException te) { System.err.println(te); } } }