My XQuery knowledge is pretty lacking but I’m trying to play around with XQIB (XQuery in the Browser), but even just setting a variable errors
let $foo := "bar"
…generates the error
MXQuery output the following error during compilation:
Line 1, Column 18: err:XPST0003 Error while parsing FFLWOR Expr: 'return' expected!
let $foo := "bar" ERROR
Unknown.anonymous(Unknown Source)
I’ve looked at the samples on the XQIB site, and it seems the let statements there are always in sub-routines, e.g. alerts or functions. Is this to suggest that in XQuery, code must always live in a function of sorts, rather than be free-standing?
For example, one of their examples is this, which of course works:
b:alert(
let $x := <a><b>2</b><c>4</c></a>
return xs:string($x/b * $x/c)
)
But this, my altered version, doesn’t.
let $x := <a><b>2</b><c>4</c></a>
b:alert(
return xs:string($x/b * $x/c)
)
What’s up with the latter? Thanks in advance for any help.
Your return is at the wrong position:
You only need a
returnif you used some (part of a) flwor-expression.letstarts one, so you will needreturnafter it. As you haven’t got one as parameter, you don’t need (and neither are allowed) to put areturnhere.