Hi France,
The semantics of general comparisons in XQuery (==, != etc.) is "existential". Each item of a sequence is compared against each item of the other sequence. If a single test returns true, the final result is true (and the remaining comparisons are usually skipped). Otherwise, the result if false. If one of the sequences is empty, there is nothing to compare, and the result will always be false:
1 = 1 → true (2,3) = (1,2) → true 1 = () → false () = () → false () != () → false
Inverting the operator, and inverting the if branches or using the not() function helps you out:
let $node := () return if(not($node/@class = 'blue')) then 'not blue' else 'blue'
Best, Christian
The code below returns 'blue', but I was expecting 'not blue'. The class attribute on an empty node is null; null != blue.
let $node := () return if($node/@class != 'blue') then 'not blue' else 'blue'
-- France Baril Architecte documentaire / Documentation architect france.baril@architextus.com