Re: [xsl] Testing by counting or positional predicate

Subject: Re: [xsl] Testing by counting or positional predicate
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 11 Jan 2001 13:08:12 +0000
Hi Dimitre,

> not($subset[count(. | $superset) > count($superset)])
> In case of a "smart" processor it will stop evaluating the above
> expression immediately when the first node from $subset that does
> not belong to $superset is found.
> In the best case just one node may be tried.
> In the worst case, the time must be similar to the time for uniting
> the two node-sets.

Very good point.  Of course, that's equivalent to:

not($subset[(.|$superset)[count($superset) + 1])

Because of optimisation on positional predicates, I was expecting

not(($subset|$superset)[count($superset) + 1])

would stop if it got to a (count($superset) + 1)th node. I don't know
how unioned node sets are constructed, but it could involve adding
each of the nodes in the other node set in turn. When the nth node for
the node set is added, it's returned.

In this example, it would mean that the above and your suggestion were
roughly similar; if iterating over nodes from an XPath expression is
more time-consuming than iterating over nodes behind the scenes (a not
unreasonable assumption), and performing unions of any kind is
relatively time-consuming, then it might feasibly be better just to
create one union and test that rather than creating a union for
potentially every node in the subset.

On the other hand, it might be that processors can't simply return the
nth node when it's added because unioned node sets have to be returned
in document order, and they might well not create unions by picking
the nodes out of each node set in document order, but rather by
starting with the largest node set and adding nodes from the other
node set one by one.

I guess it's a matter of testing to see. Anyone with a good testing
environment want to give it a go?



Jeni Tennison

 XSL-List info and archive:

Current Thread