67,513
社区成员
发帖
与我相关
我的任务
分享
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();
}
}