与撒克逊人一起使用Xalan [英] Using Xalan alongside Saxon

查看:111
本文介绍了与撒克逊人一起使用Xalan的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中使用Xalan,但是需要将Saxon与参考实现一起使用以生成要进行比较的测试输出.我想在单元测试中同时使用它们. 但是,一旦我在项目.pom中添加了对Saxon的依赖关系,该应用程序似乎就在测试过程中对所有xslt和XPath操作都使用了Saxon:

I use Xalan in my application, but need to use Saxon with a reference implementation to generate test output to compare with. I want to use them both during unit tests. However, as soon as I add an dependency on Saxon in the project .pom, the application seems to use Saxon for all xslt and XPath operations during tests:

<dependency>
  <groupId>net.sf.saxon</groupId>
  <artifactId>Saxon-HE</artifactId>
  <version>9.4</version>
  <scope>test</scope>
</dependency>

由于不同的XPath行为,这使得主应用程序在生成输出时失败.在测试范围之外运行主应用程序时,它将起作用.

This makes the main application fail when generating output due to a different XPath behaviour. When running the main application outside of test scope it works.

在测试过程中如何使用Xalan运行主应用程序,而使用Saxon运行测试?

How can I run the main application using Xalan, but the tests using Saxon, during tests?

在运行Xalan和Saxon部件之前,我尝试设置以下属性:

I have tried setting the following property before running the Xalan and Saxon parts:

System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.processor.TransformerFactoryImpl ");
System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");

我还尝试将Xalan和Saxon部件放在不同的项目中,并且还尝试从第三个项目中使用它们,结果相同.

I have also tried to put the Xalan and Saxon parts in different projects, and I have also tried to use them both from a third project, with the same result.

推荐答案

避免依赖JAXP工厂机制来选择转换引擎.而是显式地加载您想要的引擎:它更可靠,更快.对于撒克逊人,请替换呼叫

Avoid relying on the JAXP factory mechanism for selecting your transformation engine. Instead load the engine you want explicitly: it's much more reliable and much faster. For Saxon, replace the call on

TransformerFactory.newInstance()

使用

new net.sf.saxon.TransformerFactoryImpl()

供Xalan使用

new org.apache.xalan.processor.TransformerFactoryImpl()

这篇关于与撒克逊人一起使用Xalan的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆