Does the performance of XSLT improve when xsl variable is used instead of XPath expression?
Update: I’m using Xalan for processing.
Does the performance of XSLT improve when xsl variable is used instead of XPath
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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:functionexecution optimized, by turning on function memoization. In the case of Saxon this is done by setting the extension attributesaxon:memo-functionto"yes".