Statement Type | Syntax | Remarks |
---|---|---|
literal node statement | "text";
123; true; :qname; ... |
Any literal value can appear directly at the statement level, which constructs a data node. The difference between text nodes and other literal value data nodes is that consecutive text nodes are always merged into one text node. |
enclosed expression statement | {
expr
} |
This statement is like the value-of element in XSLT. It evaluates the expression and then output the string value of the result as a text node. (It shall be changed to follow the semantics of enclosed expression in XQuery.) |
comment construction statement | comment(expr); |
Constructs a comment node. The string value of the body expression gives the content of the comment. |
element construction statement | element
(expr}
{ statements;
} |
Constructs an element
dynamically. The expr
should evaluates to a qname, which is the name of element to
construct. |
attribute construction statement | attribute
(expr)
{value} |
Constructs an attribute
dynamically. The expr
should
evaluates to a qname, which is the name of element to
construct. |
copy statement | copy(expr); |
Copies the result of the expr to the output. If the expr evaluates to a node, it is copied exactly; if the expr evaluates to an atomic value, it is copied as a data node; if the expr evaluates to a sequence, the items are copied individually. |
apply statement | apply(); apply(parameters)
mode m; |
Applies templates to the child nodes of the current item. |
apply-to statement | apply-to(expr); apply-to(expr ,
parameters); apply-to(expr , parameters) mode m; |
Applies templates to the
result of the expr . |
template <match-pattern>
name
(parameters)
priority number
{ statements;
}
The
match
pattern of a template is always
required. The name
of a template is optional. If it is
specified,
then the template can also be called as a normal statement function.
The parameters can be omitted if the template does not need any
parameter. The priority clause is also optional. [expr]
can be used; filed
predicate ?field
is not allowed in the path step;'|'
is not supported in this
beta release;It is possible for a source node to match more than one template rule. The template rule to be used is determined as follows:
First, all matching template rules that have lower import precedence than the matching template rule or rules with the highest import precedence are eliminated from consideration.
Next, all matching template
rules that have lower priority than
the matching template rule or rules with the highest priority are
eliminated from consideration. The priority of a template rule is
specified by the priority
clause on the template. The
value of this must be a real number (positive or
negative). The default
priority is computed as follows:
:*
preceded by
a child or attribute axis, then the priority is -0.25.There is a built-in template rule to allow recursive processing to continue in the absence of a successful pattern match by an explicit template rule in the stylesheet. This template rule applies to both element nodes and the root node. The following shows the equivalent of the built-in template rule:
template <* | /> { apply; }
There is also a built-in template rule for text and attribute nodes that copies the node through:
template <text() | @*> { copy of .; }
The built-in template rule for comments is to do nothing.
template <comment()> { }
You can override these built-in rules. However, as these rules may apply to many nodes, you need to take into consideration the impact on performance. Your templates will always be slower than the built-in templates whose handling are optimized by the query engine.
Below is an example showing the template transformation features of Candle: