views:

554

answers:

2

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?

+1  A: 

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.

Stephen Denne
+1  A: 

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)

StaxMan