Easy Tutorial
❮ Xquery Intro Xquery Reference ❯

XQuery Syntax


XQuery is case-sensitive, and elements, attributes, and variables in XQuery must be valid XML names.


Basic Syntax Rules of XQuery:

Some basic syntax rules:


XQuery Conditional Expressions

"If-Then-Else" can be used in XQuery.

See the example below: if ($x/@category="CHILDREN") then <child>{data($x/title)}</child> else <adult>{data($x/title)}</adult>

Note the syntax of "If-Then-Else": parentheses after the if expression are required. The else part is also required, but writing "else ()" is acceptable.

Result of the example above:


XQuery Comparisons

In XQuery, there are two ways to compare values.

Differences between these comparison methods:

Consider the following XQuery expression:

If the value of the q attribute is greater than 10, the expression returns true.

In this example, if only one q is returned and its value is greater than 10, the expression returns true. If more than one q is returned, an error occurs:

❮ Xquery Intro Xquery Reference ❯