andunslg
andunslg

Reputation: 791

What is the best way to Optimize XSLT transformations?

I am using the code given below to XSLT transformations. I use Input and Output Streams for this transformation. Here xsltIn and xmlIn are input streams. I use the

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

Set saxon as the binding. So my Question is what is the best way to Optimize the processing. I heard about something called Streaming Templates.

javax.xml.transform.Result xmlResult = new javax.xml.transform.stax.StAXResult(XMLOutputFactory
    .newInstance().createXMLStreamWriter(new FileWriter(fileName)));javax.xml.transform.Source xsltSource = new javax.xml.transform.stream.StreamSource(xsltIn);
javax.xml.transform.Source source = new javax.xml.transform.stream.StreamSource(xmlIn);

javax.xml.transform.TransformerFactory transFact = javax.xml.transform.TransformerFactory
    .newInstance();
javax.xml.transform.Transformer trans = transFact.newTransformer(xsltSource);
trans.transform(source, xmlResult);

Upvotes: 0

Views: 815

Answers (1)

Michael Kay
Michael Kay

Reputation: 163595

Focus on measurement. Measure performance, assess the factors that influence performance (e.g. source document size), and once you understand the performance you are getting, you can start to think about how to improve it. How much of the end-to-end performance is spent on source document parsing, stylesheet compilation, transformation, serialization? If you don't know, then you need to find out.

Know your goals. What performance do you need and how far short of it are you currently? How much effort/time/money are you prepared to invest in order to achieve the required performance?

There are many things you could do to improve performance. For example, you could put in Saxon-EE to take advantage of its improved optimizer and bytecode generation. Or you could buy faster hardware. Or you buy consultancy from an XSLT expert. Whether any of those things would give you a good return on investment is impossible to say from the way the question is formulated.

Upvotes: 2

Related Questions