<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <link rel="stylesheet" href="advice.css" type="text/css"/>
        <link rel="icon" href="fold.ico" type="image/x-icon"/>
    </head>
    <body>
        <h1>XQuery gotchas</h1>
        <ul>
            <li>:= is assignment, eq is equality and = is like "in" - true if the intersection is not empty</li>
            <li> = is a powerful operator.  It evaluates to true if any value appears in both the sequences being compared: Thus:
<code>(1, 2, 3) = (3, 4, 5)</code>
and
<code>3 = (3, 4, 5)</code>
but there are some oddites.  For example
<code>() = ()</code>
is false, as is 
<code>() != ()</code>
            </li>
            <li>the minus sign needs space around it since $x-3 is a valid variable name which is not the same as $x - 3.</li>
            <li>check carefully for matching single and double quotes, round and square brackets and curly braces. 
 The java client will show the matching bracket, but errors are often poorly diagnosed by the XQuery compiler</li>
            <li>There is no check made on balancing tags so a script may generate XML which is not well-formed.</li>
            <li>The conditional expression must have the else part. Return the empty sequence () if one alternative is not required:
<code>
                    <pre>if ($x = 4) 
then "Four"
else ()</pre>
                </code>
            </li>
            <li> The abbreviated form in which multiple assignment statements can be separated by a comma:
<code>
                    <pre>let $x := 3
let $y := 4
let $x := "fred"</pre>
                </code>
Abbreviated to 
<code>
                    <pre>let $x := 3,
    $y := 4,
    $x := "fred"</pre>
                </code>
is convenient but can lead to errors when code is amended.  Consider avoiding this syntax.
</li>
        </ul>
    </body>
</html>
