# XQuery 1.1

These new features are available only with Saxon-PE or Saxon-EE, and require XQuery 1.1 to be enabled (a) from the command line (-qversion:1.1) or Configuration and (b) from the query prolog (`xquery version "1.1";`).

The try/catch syntax from the draft XQuery 1.1 specification is implemented, but without the ability to declare variables to receive error information. This feature cannot be used with XQuery Updates.

A subset of the grouping syntax from the draft XQuery 1.1 specification is implemented. The `group by` clause must be preceded in the FLWOR expression by (a) a single `for` clause, which selects the sequence to be grouped, and (b) a single `let` clause, which defines the grouping key; the "group by" clause must name the variable that is declared in the `let` clause. For example: `for $x in //employee let $k := $x/department group by $k return ...`. Within the `return` clause, `$x` refers to the content of the current group, and `$k` to the current grouping key.

The "outer for" clause of a FLWOR expression is implemented. The implementation is functionally complete, but there is no optimization.

Computed namespace node constructors are supported, in the form `namespace prefix {uri-expression}` or `namespace {prefix-expression} {uri-expression}`.

In the query prolog, it is now possible to provide a default value for an external variable (for example, `declare variable $ext external := 0;`.

The `declare context item` declaration in the query prolog is implemented. This allows a required type and a default value to be declared for the context item. At present (the rules aren't entirely clear) it is possible to specify a value from the calling API, or to not specify a value, regardless whether "external" is specified or not. At present there is no interaction with the API facilities for defining a required type for the context item: both can be used independently.

The expression `validate as type-name { expr }` is implemented.

The functions `format-date()`, `format-time()`, and `format-dateTime()`, as specified in XSLT 2.0, are now also available in XQuery 1.1.

The function `format-number()` is now available, along with the new syntax in the Query Prolog to declare a (named or default) decimal-format. (This has entailed some internal change in the way decimal formats are managed, since XQuery allows each module to have its own set of named decimal formats.)

Higher-order functions

The new facility for higher-order functions is fully implemented, with one or two restrictions.

The syntax `my:function#3` is now available. This is synonymous with the extension available in earlier releases, `saxon:function('my:function', 3)`. This has also been extended so that it works with all functions; the Saxon extension previously worked only with user-written functions.

The `SequenceType` syntax `function()` is now available to denote the type of a function item, that is, the type of the result of `my:function#3` or `saxon:function('my:function', 3)`. You can also use a full type signature, for example `function(xs:int, xs:int) as xs:string*`.

The type `function()` is implemented as a new subtype of `Item` represented by the Java class `net.sf.saxon.om.FunctionItem`. Note that any code that assumes every Item is either a node or an atomic value is potentially affected.

Dynamic function calls can now be written, for example, as `$f(x, y)` rather than `saxon:call($f, x, y)` as previously. In this expression `$f` can be replaced by any primary expression or filter expression whose value is a function item.

Inline (anonymous) functions can be written, for example `function ($x as xs:integer) as xs:boolean {$x mod 2 eq 0}`. Such a function will typically be used as an argument in a function call expecting a parameter of type `function()`.

The functions `fn:function-name()`, `fn:function-arity()`, and `fn:partial-apply()` are implemented.

Saxon applies function coercion when a function is passed to another function, or when it is returned as a function result. However it also implements a proposed change to the specification whereby function coercion is not used for operations such as "instance of". These follow stricter type checking rules: a function `F(A,B)->T` is an instance of a type `F(X,Y)->U` if every T is an instance of U, every X is an instance of A, and every Y is an instance of B.

Next