如何使用 Xalan 更改一些现有的 Java XSLT 代码以使用 Saxon 和 TinyTree
我有一些现有的 Java 代码,它们以编程方式执行 XSLT 转换 - 最初使用 Xalan。 我已将其重构为能够使用另一个(外部配置的)TransformerFactory。
我尝试过使用 Saxon(v6.5.3 和 v8.7)工厂,但没有看到任何性能改进 - 如果有的话 Saxon 比 Xalan 更慢并且使用更多内存。
我知道我可以使用 Saxon TinyTree 获得一些性能优势,但无法弄清楚如何使用此代码来实现这一点。
我的代码的形式是;
TransformerFactory tf = (TransformerFactory) transformerFactoryClass.newInstance();
Transformer t = tf.newTransformer(pTransformFile);
t.transform(new StreamSource(pSourceFile), new StreamResult(pTargetFile));
其中“transformerFactoryClass”是已配置的 TransformerFactory 类的实例
- Xalan 的 org.apache.xalan.processor.TransformerFactoryImpl
- Saxon 8.7 的 net.sf.saxon.TransformerFactoryImpl 和
- Saxon 6.5.3 的 com.icl.saxon.TransformerFactoryImpl
有什么建议吗?
I have some existing Java code that does an XSLT transform programmatically - originally using Xalan. I have refactored it to be able to use another (externally configured) TransformerFactory.
I have tried using the Saxon (v6.5.3 and v8.7) factory, but do not see any perfromance improvements - if anything Saxon is slower and uses more memory than Xalan.
I understand that I could get some performance dvantage using the Saxon TinyTree, but can not figure out how to do so with this code.
My code is of the form;
TransformerFactory tf = (TransformerFactory) transformerFactoryClass.newInstance();
Transformer t = tf.newTransformer(pTransformFile);
t.transform(new StreamSource(pSourceFile), new StreamResult(pTargetFile));
Where 'transformerFactoryClass' is an instance of the configured TransformerFactory class
- org.apache.xalan.processor.TransformerFactoryImpl for Xalan
- net.sf.saxon.TransformerFactoryImpl for Saxon 8.7, and
- com.icl.saxon.TransformerFactoryImpl for Saxon 6.5.3
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Saxon 7 文档 推断您可以
tf.setAttribute (net.sf.saxon.FeatureKeys.TREE_MODEL,Builder.TINY_TREE);
然而他们也说这是默认的。
Saxon 7 docs infer you can
tf.setAttribute(net.sf.saxon.FeatureKeys.TREE_MODEL,Builder.TINY_TREE);
However they also say that that is the default.
实际上,当你给 Saxon 一个 StreamSource 时,它应该默认在内部使用 TinyTree。
至于速度:正如 Saxon 作者打趣的那样,Xalan 会执行两种可能性之一,具体取决于样式表:快速或正确。 撒克逊人总是正确地做事,这在某些情况下意味着它更慢。 部分问题在于,XSLT 1.0 规范定义了某些行为方式,很难正确优化(但如果将行为更改为不合规,则更容易)。
然而,无论如何,我总是发现 Saxon 与更复杂的样式表一样快或更快。 对于更简单的情况,Xalan 通常更快。
最后,Saxon 随着时间的推移已经进行了很多优化,因此请确保您使用更新的版本(Saxon 9.1)
Actually, when you give Saxon a StreamSource, it should by default use TinyTree internally.
As to speed: as Saxon author has quipped, Xalan does one of 2 possibilities, depending on stylesheet: fast or correct. Saxon always does things correctly, which in some cases means it is slower. Part of the problem is that XSLT 1.0 specification defines certain things to behave in a way that is very hard to optimize correctly (but rather easier if changing behavior to be non-compliant).
For what it's worth, however, I always found Saxon to be as fast or faster with more complicated stylesheets. Xalan is often faster for simpler ones.
Finally, Saxon has been optimized a lot over time, so make sure you use a more recent version (Saxon 9.1)