I am working for a project which has many XSLT transformations. The transformations have to be as fast as possible.
For readability I wrote many of them dividing \"b
From a section of the the XSLT FAQ:
xsl:variables are dynamic values. These variables are not in cache, and run every time that they are referenced in XSL. Explicit type casting of xsl:variable improves the performance. You can do type casting with string() and boolean() functions.
For example:
Instead of using sub-elements, use attributes wherever possible. Using attributes instead of elements improves the performance. When performing XPath matches, attributes are faster because they are loosely typed. This makes validation of the schema easier.
When you match against attribute values, use enumerator attributes. Use multiple attribute names as bits, and set their values to true or false.
Keep the source documents small. If necessary split the document first.
Keep the XSLT processor (and Java VM) loaded in memory between runs
If you use the same stylesheet repeatedly, compile it first.
If you use the same source document repeatedly, keep it in memory.
If you perform the same transformation repeatedly, don't. Store the result instead.
Keep the output document small. For example, if you're generating HTML, use CSS.
Never validate the same source document more than once.
Split complex transformations into several stages.
Avoid repeated use of "//item".
Don't evaluate the same node-set more than once; save it in a variable.
Avoid if you can. For example, by using position().
Use , for example to solve grouping problems.
Avoid complex patterns in template rules. Instead, use within the rule.
Be careful when using the preceding[-sibling] or following[-sibling] axes. This often indicates an algorithm with n-squared performance.
Don't sort the same node-set more than once. If necessary, save it as a result tree fragment and access it using the node-set() extension function.
To output the text value of a simple #PCDATA element, use in preference to .