日期:2014-05-19 浏览次数:20867 次
    public static void main(String[] args) {
        String xmlFileName = "d:/cdcatalog.xml";
        String xslFileName = "d:/cdcatalog.xsl";
        String htmlFileName = "d:/out.xml";
        transform(xmlFileName, xslFileName, htmlFileName);
    }
    public static void transform(String xmlFileName, String xslFileName,
            String htmlFileName) {
        try {
            TransformerFactory tFac = TransformerFactory.newInstance();
            Source xslSource = new StreamSource(xslFileName);
            Transformer t = tFac.newTransformer(xslSource);
            File xmlFile = new File(xmlFileName);
            File htmlFile = new File(htmlFileName);
            Source source = new StreamSource(xmlFile);
            Result result = new StreamResult(htmlFile);            
            t.transform(source, result);
        } catch (TransformerConfigurationException e) {
            e.printStackTrace();
        } catch (TransformerException e) {
            e.printStackTrace();
        }
    }