It depends entirely on the XPath processor you are using.
For Saxon, I wouldn't expect to see a measurable difference. Unless there
happen to be 100,000 B elements before the A on which you are positioned, in
which case count(../A) might take rather longer.
Michael Kay
Saxonica
mike@xxxxxxxxxxxx
+44 (0) 118 946 5893
On 4 Nov 2014, at 13:57, Costello, Roger L. costello@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> Hi Folks,
>
> I am positioned in the XML tree at the first <A> element, within a <parent>
element.
>
> Requirement: There must be only one <A> element within <parent>.
>
> Here are two XPath expressions to check that there is only one <A> element:
>
> count(../A) eq 1
>
> or
>
> not(following-sibling::A)
>
> Which XPath expression evaluates faster?
>
> /Roger
|