XQuery Reference
XQuery 3.1 is a superset of XPath 3.1. This reference covers what XQuery adds on top: FLWOR expressions, element and attribute constructors, the prolog, and typeswitch.
FLWOR — For, Let, Where, Order by, Return — is the loop at the heart of XQuery. Where an XPath path expression can only select nodes in document order, a FLWOR binds variables, filters, groups, sorts, and then shapes one result per iteration. If you have ever wanted XPath to produce a sorted report, or one summary row per author, this is the construct that does it.
Constructors are how XQuery builds new XML instead of only selecting existing XML. You write literal markup straight into the query, drop into expressions with curly braces, or compute element and attribute names at runtime. This is the capability that turns a query language into a transformation language — and it is the main reason people move a job from XPath to XQuery.
The prolog is everything before the main expression: version and namespace declarations, global variables, and your own functions. It is what lets an XQuery grow past a one-liner into a maintainable transformation, and it is the piece with no XPath equivalent at all. Every prolog item ends with a semicolon.
XQuery inherits XPath's if/then/else and its type system, then adds typeswitch — a branch on what a value *is* rather than on a boolean test. Together with instance of, cast as and treat as, these are the tools for writing a query that survives contact with messy, irregular documents rather than assuming every node looks the same.
XQuery 3.1 is a strict superset of XPath 3.1, so nothing you already know is wasted: a bare path expression like /catalog/book is a perfectly valid, complete XQuery. What changes is what becomes possible — sorting, grouping, named functions, and building new XML. This section is the orientation map for deciding which one a job actually needs.