XSL+XML TO HTML

来源:互联网 发布:我的域名如何使用 编辑:程序博客网 时间:2024/04/28 20:05
</pre><pre name="code" class="java">package model;import java.io.ByteArrayOutputStream;import java.io.IOException;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 XSL2HTML {public static void main(String[] args) {String filePath = XSL2HTML.class.getClassLoader().getResource("").getPath();TransformerFactory tf = TransformerFactory.newInstance();try {//xsl数据加入transformerStreamSource source_xsl = new StreamSource(filePath+"/xsltest2.xsl");Transformer transform = tf.newTransformer(source_xsl);//转换成HTMLStreamSource source_xml = new StreamSource(filePath+"/xmltest2.xml");//以文件输出//StreamResult result = new StreamResult(filePath+"/xsl2html");//transform.transform(source_xml, result);//以字符串输出ByteArrayOutputStream bout = new ByteArrayOutputStream();transform.transform(source_xml, new StreamResult(bout));System.out.print(bout.toString());bout.close();} catch (TransformerConfigurationException e) {e.printStackTrace();} catch (TransformerException e) {e.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}


0 0
原创粉丝点击