- From: Jeni Tennison <jeni@jenitennison.com>
- Date: Fri, 23 Apr 2004 15:44:43 +0100
- To: Murali Mani <mani@CS.UCLA.EDU>
- Cc: www-ql@w3.org, Philippe Michiels <philippe.michiels@ua.ac.be>
Hi Murali, > Thanks for the responses.. Thanks especially for illustrating text () and > string () functions.. Note that text() isn't a function, it's a node test. When you do something like: text() = "Adam" this is short for: child::text() = "Adam" The "child::text()" is a location path that selects all the text nodes that are children of the context node. On the other hand, string() is a function that takes a node as an argument and returns its string value. When you do: string(.) = "Adam" this isn't short for anything (in XPath 2.0; in XPath 1.0 it's short for string(self::node()) = "Adam"). >> Note: The original question used the query >> //student["Adam"]/advisor. It's not clear what XML structure that >> is supposed to query. If it's: >> >> <student>Adam<advisor>Benny</advisor></student> >> >> then you need //student[text()[1] = "Adam"]/advisor (test the first >> child text node against the string), but this is badly designed XML >> (mixed content for data-oriented information), so I assume that >> this isn't what was wanted. > > The above was the example in mind, even I believe it is bad design > for "data oriented applications"; but that was not the concern.. > > Do we need text ()[1] = "Adam", isn't text () = "Adam" sufficient? It depends what you want to test and how much you can guarantee about the structure of your document. If you do text() = "Adam" then this will test all the text node children of the context node against the string "Adam". If you know (somehow) that there's only one text node child of your <student> element then obviously this will always give exactly the same result as text()[1] = "Adam". On the other hand, text()[1] might give you unanticipated results sometimes, for example if someone does: <student> <?editor cursor?>Adam<advisor>Benny</advisor></student> then text()[1] will give you the space before the processing instruction. These problems are precisely why it isn't a good idea to use mixed content for data like this. > I thought a predicate expression such as > > (x op y) is true, if (x op y') is true for some y' in y... Am I right?? You're right that general comparisons (=, !=, <, <=, > and >=) are existential: they do all possible pairs of comparisons between the items in the operand sequences and return true if any one of those comparisons are true. This isn't the case for all operators: the value comparisons (eq, ne, lt, le, gt and ge) give you an error if either argument is a sequence containing more than one item. > what is the semantics of (x op y) if x is a collection? is it valid > for x to be a collection? Do you mean "sequence"? Yes, x can be a sequence. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/
Received on Friday, 23 April 2004 11:19:39 UTC