Reputation: 467
Does the performance of XSLT improve when xsl variable is used instead of XPath expression? Update: I'm using Xalan for processing.
Upvotes: 1
Views: 244
Reputation: 243479
Does the performance of XSLT improve when xsl variable is used instead of XPath expression?
This depends on the XSLT processor being used. If the XSLT processor has a good optimizer, in many cases it does the factorization by itself and there is no real speed gain doing this by hand.
However:
"Saving" the result of evaluation in a variable can make the code shorter and more readable.
This is a good application of the DRY (Don't Repeat Yourself) best practices.
Relying on the Optimizer not always works.
We shouldn't rely on optimizers when writing portable code, that is intended to be executed by more than one different XSLT processors -- such as when writing a library of functions/templates.
With some XSLT 2.0 processors, such as Saxon, one can even have xsl:function
execution optimized, by turning on function memoization. In the case of Saxon this is done by setting the extension attribute saxon:memo-function
to "yes"
.
Upvotes: 3
Reputation: 7159
It is my experience that it does but more important it improves the readability of the code. It also make code reuse simpler.
Upvotes: 0