jaxp实现xslt转换示例

前端之家收集整理的这篇文章主要介绍了jaxp实现xslt转换示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

用TransformerFactory创建Transformer对象,用newInstance()方法得到工厂实例,再用newInstance()方法得到转换器实例。最后用transform()方法即可。


package test.chap05; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamResult; public class TestTranformer { public static final String SOURCE_XML_FILE = "E:/XML/jar-complier/Stocks.xml"; public static final String XSL_FILE = "E:/XML/jar-complier/forth.xsl"; public static final String OUT_FILE = "E:/XML/jar-complier/Stocks-forth.out.html"; public static void main(String[] args) { TransformerFactory factory = null; Transformer transformer = null; try{ factory = TransformerFactory.newInstance(); transformer = factory.newTransformer(new StreamSource(XSL_FILE)); transformer.transform(new StreamSource(SOURCE_XML_FILE),new StreamResult(OUT_FILE)); } catch(Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); } } }

原文链接:https://www.f2er.com/xml/300406.html

猜你在找的XML相关文章