W3C home > Mailing lists > Public > public-qt-comments@w3.org > September 2002

RE: Iteration functionality request for XPath 2.0

From: Kay, Michael <Michael.Kay@softwareag.com>
Date: Fri, 20 Sep 2002 12:30:54 +0200
Message-ID: <DFF2AC9E3583D511A21F0008C7E621060453DB9D@daemsg02.software-ag.de>
To: "Voytenko, Dimitry" <dvoytenko@sectordata.com>, "'public-qt-comments@w3.org'" <public-qt-comments@w3.org>

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

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:45:10 UTC