最后我们来看看如何通过JAXP调用XSLT,同样很简单:
/**//*
* Created on 2005-2-24
* All rights reserved.
*
*/
package sean.home.test;
import java.io.File;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
/**//**
* @author Sean GAO
* <p>
*
[email protected] * </p>
*
*/
public class XSLTest {
public static void main(String[] args) throws Exception {
TransformerFactory factory = TransformerFactory.newInstance();
Source xmlSource = new StreamSource(new File(args[0]));
Source xlsSource = new StreamSource(new File(args[1]));
Transformer transformer = factory.newTransformer(xlsSource);
transformer.transform(xmlSource, new StreamResult(new File(args[3])));
}
}
是不是也跟SAX、DOM的接口很像?也是通过工厂方法获取一个Transformer实例然后提供输入和输出的文件路径,用它来transform即可。
本文地址:http://com.8s8s.com/it/it11203.htm