与 Xalan 一起使用 Saxon [英] Using Saxon alongside Xalan

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

问题描述

我有一个应用程序,我使用 Xalan 作为 XSLT 处理器.我现在想使用撒克逊人.我想确保所有现有的转换仍然有效.因此我想对所有现有的 XML 文件使用 Xalan.对于新的 XML 文件,我想使用 Saxon.总而言之,我想同时使用两个处理器.因此,我像这样实例化处理器:

I have an application where I use Xalan as XSLT processor. I now want to use Saxon. I want to be sure that all existing transformations still work. Therefore I want to use Xalan for all existing XML files. For new XML files, I want to use Saxon. To summarize I want to use both processors alongside. Therefore I instantiate the processor like this:

TransformerFactory.newInstance("com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl", null);
or
TransformerFactory.newInstance("net.sf.saxon.TransformerFactoryImpl", null);

在我现有的所有单元测试中,我都使用 Xalan.但是当我将 Saxon 添加到我的类路径时,其中一些失败了.失败的测试都使用 Apache FOP 来创建 PDF 文件.不同的是,现在生成的 PDF 中插入了一些制表符(缩进键)(不在可见内容中,我只是在比较字节码时看到它们).我认为这种行为很奇怪,因为我仍然使用 Xalan 并期望与我的类路径中没有 Saxon 时的结果相同.那么当 Saxon 在类路径中时还有什么变化?

In all my existing unit tests I use Xalan. But some of them fail when I add Saxon to my classpath. The tests that fail all use Apache FOP to create a PDF-file. The difference is that now some tabs (indent keys) are inserted in the generated PDF (not in the visible content, I just see them when I compare the bytecode). I think this behavior is strange because I still use Xalan and expect the same result as when I don't have Saxon in my classpath. So what else does change when Saxon is in the classpath?

当我添加

System.setProperty("javax.xml.transform.TransformerFactory",
            "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");

在我的测试中,它再次与类路径中的 Saxon 一起使用.但这不是我的生产环境的解决方案,因为我想在两个处理器之间动态切换.

to my tests, it again works with Saxon in the classpath. But this is no solution for my productive environment because I want to switch dynamically between the two processors.

那么有谁知道当我将 Saxon 添加到我的类路径时还有什么变化?非常感谢!

So does anyone know what else changes when I add Saxon to my classpath? Thank you very much!

更新:我已设置 jaxp.debug 标志并获得以下输出(在类路径中使用 Xalan 和 Saxon)

Update: I have set the jaxp.debug flag and get the following output (using Xalan with Saxon in the classpath)

    JAXP: created new instance of class org.apache.xalan.xsltc.trax.TransformerFactoryImpl using ClassLoader: null
JAXP: created new instance of class org.apache.xalan.xsltc.trax.TransformerFactoryImpl using ClassLoader: null
JAXP: created new instance of class org.apache.xalan.xsltc.trax.TransformerFactoryImpl using ClassLoader: null
Calling com.saxonica.SchemaFactoryImpl.isSchemaLanguageSupported("http://www.w3.org/2001/XMLSchema"); returning true
JAXP: created new instance of class org.apache.xalan.xsltc.trax.TransformerFactoryImpl using ClassLoader: null
JAXP: find factoryId =javax.xml.transform.TransformerFactory
JAXP: find factoryId =javax.xml.transform.TransformerFactory
JAXP: find factoryId =javax.xml.transform.TransformerFactory
JAXP: find factoryId =javax.xml.transform.TransformerFactory
JAXP: find factoryId =javax.xml.transform.TransformerFactory
JAXP: created new instance of class org.apache.xalan.xsltc.trax.TransformerFactoryImpl using ClassLoader: null

当我从类路径中删除 saxon 时,我得到以下输出:

When I remove saxon from the classpath, i got the following output:

JAXP: created new instance of class org.apache.xalan.xsltc.trax.TransformerFactoryImpl using ClassLoader: null
JAXP: created new instance of class org.apache.xalan.xsltc.trax.TransformerFactoryImpl using ClassLoader: null
JAXP: created new instance of class org.apache.xalan.xsltc.trax.TransformerFactoryImpl using ClassLoader: null
JAXP: created new instance of class org.apache.xalan.xsltc.trax.TransformerFactoryImpl using ClassLoader: null
JAXP: find factoryId =javax.xml.transform.TransformerFactory
JAXP: find factoryId =javax.xml.transform.TransformerFactory
JAXP: find factoryId =javax.xml.transform.TransformerFactory
JAXP: find factoryId =javax.xml.transform.TransformerFactory
JAXP: find factoryId =javax.xml.transform.TransformerFactory
JAXP: created new instance of class org.apache.xalan.xsltc.trax.TransformerFactoryImpl using ClassLoader: null

所以我真的使用了 Xalan 处理器.输出的不同之处在于,类路径中没有撒克逊人,我看不到该行

So I really use the Xalan processor. The difference in the output is that without saxon in the classpath i dont see the line

Calling com.saxonica.SchemaFactoryImpl.isSchemaLanguageSupported("http://www.w3.org/2001/XMLSchema"); returning true

阅读本文后问题 我添加了建议的行以获取有关所有工厂的信息.当我使用 xalan 处理器(在类路径中使用 saxon)时,我得到了

After reading this question I added the proposed lines to get information about all the factories. When I use the xalan processor (with saxon in the classpath), i got

DocumentBuilderFactory implementation: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl loaded from: Java Runtime
    XPathFactory implementation: org.apache.xpath.jaxp.XPathFactoryImpl loaded from: file:/D:/repository/xalan/xalan/2.7.1/xalan-2.7.1.jar
    TransformerFactory implementation: com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl loaded from: Java Runtime
    SAXParserFactory implementation: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl loaded from: Java Runtime

当我使用 Saxon 时我得到了

When i use Saxon i got

    DocumentBuilderFactory implementation: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl loaded from: Java Runtime
XPathFactory implementation: org.apache.xpath.jaxp.XPathFactoryImpl loaded from: file:/D:/repository/xalan/xalan/2.7.1/xalan-2.7.1.jar
TransformerFactory implementation: com.saxonica.config.EnterpriseTransformerFactory loaded from: file:/D:/repository/de/soptim/contrib/net/sf/saxon/Saxon-EE/9.8.0.14/Saxon-EE-9.8.0.14.jar
SAXParserFactory implementation: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl loaded from: Java Runtime

推荐答案

我认为您必须有一些使用 TransformerFactory.newInstance() 而不指定处理器的转换.尝试设置 jaxp.debug 系统属性以获取有关加载过程的诊断信息.

I think you must have some transformations that are using TransformerFactory.newInstance() without specifying a processor. Try setting the jaxp.debug system property to get diagnostics on the loading process.

我建议设置系统属性

System.setProperty("javax.xml.transform.TransformerFactory",
            "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");

以便默认调用 Xalan,并使用

so that Xalan is invoked by default, and using

TransformerFactory saxon = new net.sf.saxon.TransformerFactoryImpl();

在您想要调用 Saxon 的情况下.如果你想动态地做出决定,那么在你自己的代码中使用一些条件逻辑来控制它.

in cases where you want to invoke Saxon. If you want to make the decision dynamically, then control it using some conditional logic in your own code.

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

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