10. XML templates

A command may be passed XPath expressions or XML templates as its arguments. An XML template is a literal XML element, possibly containing XPath 1.0 expressions delimited by curly braces ("{ }"). Examples:

<db:formalpara><db:title>TITLE HERE</db:title></db:formalpara>

<a href="{concat('#', $id)}" title="{$title}" class="xref"/>


The enclosed XPath expressions are evaluated as strings in the context of the current context node[1]. This means that these enclosed expressions must be found inside attribute values, text, comment or processing-instruction nodes.

If you want attribute values, text, comment or processing-instruction nodes to actually contain curly braces, then you must escape these curly braces by doubling them (that is, "{" becomes "{{" and "}" becomes "}}").

Note that whitespace is significant inside an XML template. Therefore do not indent XML templates.

An XML template is copied and its enclosed XPath expressions, if any, are substituted with their values, each time the template is passed as an argument to a command. Therefore, an XML template creates a new element each time it is used.

Sometimes, you want to pass a command a list of nodes rather than a single element. When this is the case, use a g:envelope element, where "g" is the prefix of namespace "urn:x-mlmind:namespace:group", as a container for these nodes. Example: replace context node (.) by a text node containing the value of its title attribute:

namespace g = "urn:x-mlmind:namespace:group";