Re: [xsl] XPath equivalence question

Subject: Re: [xsl] XPath equivalence question
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Thu, 01 Dec 2011 00:28:47 +0000
On 30/11/2011 23:48, Graydon wrote:
Does

<xsl:template match="/A//B">

match exactly the same thing as

<xsl:template match="B[/A]">?
Yes, I think so.

My presumption is that the second form is preferable on efficiency grounds -- on simple table lookup versus whatever tree-structure the descendant axis search produces -- but I don't actually know.


Saxon actually has different implementations for the two cases (I've often thought of normalizing patterns so they would end up the same internally, but have never got around to it). But the logic of the two implementations is pretty well identical, and I would be very suprised if there is any measurable performance difference.

You seem to be basing you reasoning on some kind of hypothetical implementation model which has no resemblance to the way it's implemented in Saxon and may have little resemblance to any other product. In both cases, in Saxon, the test whether a node matches the pattern will start by asking whether it is an element named B, and then proceed by asking whether it has an ancestor named A that is a child of the root document node. In both cases, if you do an apply-templates that selects a node named C, this rule won't even be considered and will have no impact on the performance.

Michael Kay
Saxonica

Current Thread