Result format

The result of a query is a sequence of nodes and atomic values - which means it is not, in general, an XML document. This raises the question as to how the results should be output.

The Saxon command line processor for XQuery by default produces the output by converting the result sequence to a document following the rules of the XQuery document{} constructor, and then serializing this document.

XQuery 3.1 defines the adaptive output method to handle non-XML output: you can select this with the command line option !method=adaptive. (On some shells, the "!" may need to be escaped as "\!".) The adaptive output method attempts to display each of the items in the result in an intuitive format: XML format for nodes, string format for atomic values, JSON format for maps and arrays.

Another alternative offered by Saxon is wrapped format, requested using the -wrap argument. This wraps the result sequence as an XML document, and then serializes the resulting document. Each item in the result sequence is wrapped in an element (such as result:element or result:atomic-value) according to its type. The sequence as a whole is wrapped in a result:sequence element.