While doing XSLT optimization, I figured out that by avoiding parent node look-up the XSLT run duration reduces from 1 hour to ~20 seconds.
I just avoided below xsl line by passing relevant params to take the required decision and the performance just boosted.
<xsl:if test="parent::node() = /test">
...
</xsl:if>
I am using saxon8.jar library to perform XSLT that uses SAX-based XML parsing.
I understand that SAX is push-based, so referring back is costly. But, would like to get some more insight on the cost and the algorithm involved here.
Also, in my XSL I am referring same forward nodes many times using Xpath at different steps of execution. Then, why this did not turn into a bottleneck like the way referring to the parent node did?
I suspect that you meant parent::node() is /test
. That, is you want to know if the parent node is the same node as the /test node. That would be a very fast test. But using "=" is slow: it forms the string value of parent::node(), and the string-value of /test, and compares them as strings. The string value of /test is the concatenation of all the text nodes in the document, so it involves searching the whole document and building a potentially very large string.