saxon:evaluate-node

Allows XPath expressions to be read from a source document and evaluated at run-time.

evaluate-node() ➔ item()*

There are no arguments

Result

item()*

evaluate-node($node as node()) ➔ item()*

Arguments

 

$node

node()

The node containing the expression to be evaluated

Result

item()*

Details

Namespace: http://saxon.sf.net/

The supplied argument must be a node, and the string-value of the node must contain an XPath expression. The result of the function is the result of evaluating this XPath expression. This is useful where XPath expressions are held in source documents, for example to parameterize the calculations performed by a query or stylesheet, or to provide XPointer-like cross-references within a document.

The static context for the expression takes the in-scope namespaces and the base URI from the node containing the expression (or from its parent element, if it is an attribute or text node). The default namespace defined using xmlns="xyz.uri" is used as the default namespace for elements and types, so that unprefixed names in path expressions (for example //data/value) refer to unprefixed elements in the containing document.

The expression cannot refer to any variables defined outside the expression itself, and it cannot refer to user-defined types or user-defined functions. However, it has access to the standard function library (in the default function namespace) and to Saxon extension functions and Java methods.

In the dynamic evaluation context, the context item is the node supplied as the first argument, while the context position and size are both set to one. This means that the expression can be a relative path expression referring to nodes reachable from the node that contains the expression. (Note that if this node is an attribute, the context node is the attribute node itself, not the containing element.)

For example, given the following source document:

<doc xmlns:alpha="http://www.alpha.com/"> <data>23</data> <exp>preceding-sibling::alpha:data + 5</exp> </doc>

the expression saxon:evaluate-node(//alpha:exp) returns 28.

See also saxon:evaluate, which is a similar function intended for evaluating XPath expressions constructed dynamically by code in a stylesheet or query.