xsl-list
[Top] [All Lists]

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

2014-11-04 09:11:47
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(_at_)saxonica(_dot_)com <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> 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(_at_)saxonica(_dot_)com
+44 (0) 118 946 5893




On 4 Nov 2014, at 13:57, Costello, Roger L. costello(_at_)mitre(_dot_)org <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> 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



--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>