Friday, June 24, 2011

the let statement in XQuery

if you are trying to update a variable in a for loop in XQuery, you will face a lot of frustration

if you do this:

let $count := 1

for $bla in $mumble
     let $count := $count + 1


IT WILL NOT WORK! On the left hand side ot the "let" you will keep updating a local scope variable, while in the right hand side of the "let" you will access the global $count variable declared above the "for"

Read the excellent XQuery book http://www.javamonamour.org/2010/05/excellent-xquery-book.html by Priscilla Walmsley, especially chapter 9 "Working with Positions and Sequence Numbers" is dedicate to this quirk.

XQuery is not a normal programming language, there are operations that are simply not allowed. It can be frustrating sometimes - actually quite often - and the learning curve is not flat.



No comments: