Re: sorting, was: Version 3.0 now available!
Brought to you by:
bs_php,
nigelswinson
From: Peter R. <php...@pe...> - 2002-05-12 12:36:37
|
On Thursday 09 May 2002 23:37, Nigel Swinson wrote: > > > > BTW is it normal that e.g. > > "myElement | myOtherElement" > > (or maybe ".//myElement | .//myOtherElement") > > will return the elements not in the order they appear in the XML, but in the > > order as listed in the XPath-string? > > > I wish they could be listed as appearing in the XML, as this is the > > result > I > > get from MSXML. Is it not standardized, and up to the XPath-parser to > decide > > the returned order, or simply a PHPXPath bug? > > Could be. Looking at the XPath spec it says > > ========================== > The primary syntactic construct in XPath is the expression. An expression > matches the production Expr. An expression is evaluated to yield an object, > which has one of the following four basic types: > a.. node-set (an ***unordered*** collection of nodes without duplicates) > b.. boolean (true or false) > c.. number (a floating-point number) > d.. string (a sequence of UCS characters) > ========================== > > So we don't have to guarentee anything at all about the order. > > If you could locate something for us that says that the way we do it is > wrong then we can happily change it. I agree with you that it is probably > more useful to be in the doc order. hmm, this bit of the xpath spec seems very dubious to me. The data model section of XPath spec goes on at length about document order, and many functions such as preceding, following, first, last etc depend on nodes being in that order. If the Xpath xpression (evaluate in phpxpath terms) doesn't return nodes (i.e. set up the array) in that sequence, how can we use it? The particular case Philipp raises where you have a union is perhaps a special case, as it depends on whether you define 'union' as one result-set followed by another (what it seems phpxpath currently does) or merged into one (as I too think it should do). > Perhaps what we should do is to have a sort function. It takes a function > (An XPath expression?) that will determine which of two nodes are "greater" > and bubble sorts the list? ok if you have a structured-data type of xml file, but if you have a text-document type of node, such as <p>Here are a few examples: <li>first example</li> <li>example no 2</li> <li>a further example</li> and so on</p> How do you sort that, other than in document order? And if you add a further nnn <p> nodes - the norm in document files - how can they be used if not in document order? In what order can the 'nodes' of, say, a Shakespeare play be processed other than the one he wrote?! |