Re: [xsl] Which XPath evaluates faster: count(../A) eq 1 or not( following-sibling::A)

Subject: Re: [xsl] Which XPath evaluates faster: count(../A) eq 1 or not( following-sibling::A)
From: "Wolfgang Laun wolfgang.laun@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 4 Nov 2014 15:11:31 -0000
Apart from implementation dependent effects: IIRC, this has been discussed
before, mentioning that a third variant using (the negation of) ../A[2]
also has its merits - appears to skirt the counting issue.

-W

On 4 November 2014 15:57, Michael Kay mike@xxxxxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

>
> 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

Current Thread