java xsl转换xml文件,怎么用xsl转xml文件,java代码如何写

Java codepublic 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();

}

}

你可能感兴趣的:(java,xsl转换xml文件)