RE: Iteration functionality request for XPath 2.0

> ....
> Sometimes it's very important to know if current node is the 
> last one in the node-set. There're two basic ways to do it in 
> XPath 1.0:
> **** FIRST APPROACH: using "position" and "last":
> 	<xsl:if test="position() = last()">
> 		....
> 	</xsl:if>
> 
> Drawbacks:
> 	If node-set implementation is iterative, i.e. new node 
> is fetched only when for-each instruction goes to a new cycle 
> and whole list of nodes is not cached in node-set object, 
> then the first call to last() function will go through all 
> nodes to find out their quantity. This will repeat the 
> node-set fetch procedure twice or will lead to the caching of 
> the nodes list.....

> In my point of view, this could be easily solved by extending 
> list of node-set/context functions with one more function, 
> something like "is-last" (another function "is-first" could 
> also be added for symmetry, eventhough it'd be redundant). 
> This function would return boolean true if current node is 
> the last node in the node-set. 

Saxon has an internal function like your is-last(), and its optimizer
rewrites the predicate [position()=last()] as [is-last()], for all the
reasons you mention.

I don't see a good reason why is-last() should be made available as a
user-visible function, when this construct is very easy for optimizers to
handle internally.

Michael Kay

Received on Friday, 20 September 2002 06:31:03 UTC