<name>…</name>Direct element constructor — literal markup in the query
Markup written directly in the query builds a brand-new element in the result. The new node is not part of the source document, which is why results from constructor queries have no meaningful document position or ancestry back into your input.
Example: <row>{$b/title}</row>
attr="{EXPR}"Attribute inside a constructed element
Attributes on a direct constructor take either a literal string or an enclosed expression. The expression's value is atomised and converted to a string, so passing a node yields its string value rather than the node itself.
Example: <row id="{$b/@id}">{$b/title}</row>
{EXPR}Enclosed expression — switch from text back to query
Inside constructed markup everything is literal text until a curly brace opens an expression. To output a literal brace, double it: {{ and }}. Enclosed expressions can appear in element content and in attribute values.
Example: <total>{count(//book)}</total>
element {EXPR} {…}Computed element constructor — name decided at runtime
Use a computed constructor when the element name is not known until the query runs — for example, renaming elements from a lookup table. The first braces give the name, the second the content.
Example: element {$b/name()} {$b/string()}
attribute {EXPR} {…}Computed attribute constructor
The attribute counterpart of a computed element. It must appear where an attribute is allowed — typically as the first thing in the content of an element constructor.
Example: attribute {'src'} {$b/@id}
text {EXPR}Computed text node
Builds a text node from an expression. Useful when you need a text node explicitly rather than letting the serializer produce one — for instance inside a sequence of mixed constructed nodes.
Example: text {string-join($b/title, ', ')}
declare boundary-space preserve;Keep whitespace-only text between constructed tags
By default XQuery strips boundary whitespace — the whitespace-only text nodes between literal tags in your constructors. Declaring preserve keeps it, which matters when you are producing whitespace-sensitive output.
Example: declare boundary-space preserve;