简体   繁体   English

使用Xalan APi 2.7.1进行XSLT处理

[英]XSLT processing with Xalan APi 2.7.1

I have to do xsl transformations in which I will pass the sample input xml to finally achieved the final transformation xml , I have written the program using java api of a transformer , can some body please advise how canI write the same so that it works with xalan api 2.7.1 also , below is the code with jaa which I need to convert it with xalan compatible 我必须进行xsl转换,在该转换中,我将传递示例输入xml以最终实现最终的转换xml,我已经使用转换器的java api编写了该程序,请问有什么机构可以建议我如何编写该程序以便与xalan api 2.7.1也是,下面是jaa的代码,我需要将其与xalan兼容

import javax.xml.transform.*;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;

public class TestMain {
    public static void main(String[] args) throws IOException, URISyntaxException, TransformerException {
        TransformerFactory factory = TransformerFactory.newInstance();
        Source xslt = new StreamSource(new File("transform.xslt"));
        Transformer transformer = factory.newTransformer(xslt);

        Source text = new StreamSource(new File("input.xml"));
        transformer.transform(text, new StreamResult(new File("output.xml")));
    }
} 

The API you need to use for Xalan is the standard javax.xml.transform API, there's nothing to change. Xalan需要使用的API 标准的javax.xml.transform API,没有任何更改。 If Xalan is on your application's classpath then 如果Xalan在应用程序的类路径中,则

TransformerFactory.newInstance();

will create a Xalan transformer rather than using the Java built-in implementation (which is itself a fork of Xalan). 将创建一个Xalan转换器,而不是使用Java内置实现(它本身是Xalan的分支)。 If you want to force a particular transformer implementation then use the two-argument form 如果要强制执行特定的转换器,请使用两个参数的形式

TransformerFactory.newInstance("org.apache.xalan.processor.TransformerFactoryImpl", null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM