[XPath] About fn:last()

As an implementor of XPath 2.0,I found that it's
difficult to determind the size of context sequence in
an efficient way.Fox example, we want to get the last
node of a sequence:
'/e1[predicate1]/e2[predicate2]/e3[predicate3]/e4[fn:last()]',if
the resulting sequence is very long(e.g. 1,000,000
nodes) and the data is stored in a file,in the worst
case,we'll have to use 1,000,000 IO operations to get
the value of fn:last() and another 1,000,000 IO
operations to iterate to the last node.Note that it is
 difficult to optimize the query if the last predicate
combine fn:last() with other functions(e.g.
'[fn:last() - fn:position() > 10 ]'). 

So although fn:last() has provided a more powerful way
to manipulate xml data,it has also introduced danger
into XPath: Implementors have to choose a worse way to
meet the specification and the implementation is
limited to operate on small xml data.

In fact,fn:last() is frequently used to locate the
last item of a sequence,and other case is rare.So a
better solution is to let fn:last() return a boolean:
true if the current item is the last member of a
sequence,and false if it is not.Now fn:last() function
like an EOF marker of a  file stream: You won't know
the size of a file until you reach the EOF,but you can
elect to count it during the iteration.And now
fn:last() can be used to operate on a xml stream from
the network on the fly: We don't need to wait for the
whole xml stream to get the value of fn:last().


_________________________________________________________
Do You Yahoo!? 
ÏÓÓÊÏä̫С£¿ÑÅ»¢µçÓÊ×ÔÖúÀ©ÈÝ£¡
http://cn.rd.yahoo.com/mail_cn/tag/10m/*http://cn.mail.yahoo.com/event/10m.html

Received on Thursday, 3 June 2004 00:10:49 UTC