On 29/08/2012 15:09, Gleb Gawriljuk wrote:
thanks for the rapid and helpful replys.
Q: Got the following query:

    let $x := doc('C:/Temp/ADOxxTokenGame_XMLFiles/Anfrage.xml') 
    if (not($x/Anfrage and $x/Anfrage/StudentID and $x/Anfrage/BuchID and $x/Anfrage/AnfrageID)) 
       return error() 
    else return $x/Anfrage

I receive the error, that saxon expects after 
    let $x := doc('C:/Temp/ADOxxTokenGame_XMLFiles/Anfrage.xml') 

a "return" and not a "if". Why is it valid to have a where at that position but not a if 

Because that's the way the grammar of FLWOR expressions works. A FLWOR expression consists of a sequence of clauses:

(for | let)+ where? order-by? return

Your query doesn't match that grammar. You need to promote the "return":

let $x := doc('C:/Temp/ADOxxTokenGame_XMLFiles/Anfrage.xml') 
return (    if (not($x/Anfrage and $x/Anfrage/StudentID and $x/Anfrage/BuchID and $x/Anfrage/AnfrageID)) 
       then error() 
    else $x/Anfrage )

Michael Kay