W3C home > Mailing lists > Public > www-ql@w3.org > April to June 2001

Contents of WHERE a predicate?

From: Howard Katz <howardk@fatdog.com>
Date: Mon, 23 Apr 2001 21:30:43 -0700
To: <www-ql@w3.org>
Is the contents of a WHERE clause formally categorized as a predicate? And
if so, is this different from an inline XPath predicate? Specifically, I'm
wondering what to do in the following case, where the use of a string
equality test in a WHERE clause produces a markedly different result from
its use inline, depending on how the contents of the WHERE is to be

To wit, the query:

     LET $book := //book[  title = 'Data on the Web'  ]

would seem, both by common sense and by the definition in Section 2.4
(Predicates) of the XPath specification, to return the third book in
"bib.xml". Section 2.4 refers to a predicate expression being evaluated
successively against each node in the nodeset under test, with only those
nodes that succeed against the test being retained.

Section 3.4 (Booleans) on comparisons, on the other hand, says that if a
nodeset is compared against a string, the result is true if the result of
comparing even a single node in the nodeset against the string evaluates to

Given that, the result of recasting the same query in WHERE form:

    LET $book := //book
    WHERE $book/title = 'Data on the Web"

would seem to bring about the rather odd result of returning all 4 books in
the file, if the condition in the WHERE is seen as a comparison and not as a
predicate: The comparison evaluates to true because of 3.4, and the RETURN
statement gets executed, returning the entire nodeset.

Is this how the contents of the WHERE is to be interpreted then: as a
comparison? The most straightforward implementation of the grammar certainly
seems to favour the "comparison" approach, although it wouldn't be overly
difficult to implement the "predicate" interpretation instead.

Or can we simply call the comparison a predicate on $book/title and return
the more intuitive result? But then again, it might also seem odd to assign
$book to initially be one thing -- the entire nodeset -- and then somehow
magically transmute it en route, returning it as something else. Does that
wreak havoc with the algebra? Or is it more an issue of maintaining
consistency with XPath?

Is this what Issue #24 [xquery-xpath-coercions] is talking about when it
mentions non-intiuitve results and implicit existential quantification?
Lovely expression, that. No wonder you people seem to be having such a good
time. ;-)

Received on Tuesday, 24 April 2001 00:30:58 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:17:15 UTC