N. America: 800 876 3101 | World: 44 (0) 1753 218 930

What's the proper way to use the node sequence (<< and >>) operators?

This is my XQuery:

let $referenceBook := /books/book[2]
let $book := /books/book
where $book/title << $referenceBook
return $book

This looks ok to me, but when I run it, I get the following error. Can you tell me why?

[DataDirect][XQuery][err:XPTY0004]A sequence of more than one item is not allowed as the first operand of '<<' (<title/>, <title/>, ...)

The "node before" (<<) and "node after" (>>) operators can only compare the document position of a single node to the position of another node. In your case, the let $book := /books/book instruction is assigning all the <book> elements in the input document to the $book variable, which means that $book/title corresponds to a sequence of many elements.

Perhaps what you mean to do is this:

let $referenceBook := /books/book[2]
for $book in /books/book
where $book/title << $referenceBook
return $book

 


Next Question!

Can I insruct XQuery to use numbers and not scientific notation in query results?

Submit Your DataDirect XQuery Tip or Trick

Tell us your XQuery Tip or Trick – if it gets published on our site, you’ll receive a

$10.00 Amazon.com
Gift Certificate!

Submit your tip or trick today.