transform.java

来自「dom4j与Transform配合操作XML文档,并调用Xslt进行格式化的例子」· Java 代码 · 共 28 行

JAVA
28
字号
package com.zhujiayun.test;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import java.io.*;
public class Transform { 
  /**
   * Performs an XSLT transformation, sending the results
   * to System.out.
   */
  public static void main(String[] args) throws Exception {
//    if (args.length != 2) {
//      System.err.println("Usage: java Transform [xmlfile] [xsltfile]");
//      System.exit(1);
//    }
    File xmlFile = new File("E:\\\\xslt test\\\\page.xml");
    File xsltFile = new File("E:\\\\xslt test\\\\pagination.xsl");     // JAXP reads data using the Source interface
    Source xmlSource = new StreamSource(xmlFile);
    Source xsltSource = new StreamSource(xsltFile);
    // the factory pattern supports different XSLT processors
    TransformerFactory transFact = TransformerFactory.newInstance();
    Transformer trans = transFact.newTransformer(xsltSource);
    trans.transform(xmlSource, new StreamResult(System.out));
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?