Evaluating XPath expressions

The functions presented here evaluate an XPath 1.0 expression in the context of the node being queried.

Namespaces

Namespace prefixes in the query expression are resolved into namespace URIs using the prefix map provided to the query functions as a second argument. If the map argument is omitted or null, the default prefix map is used for resolving prefixes.

Result data types

The value of an XPath 1.0 expression can have several data types (a node set with several elements, the text value of an attribute, a number returned by the count() function, the Boolean result of a comparison). The value is converted to the function's result data type using XPath 1.0 semantics – which may very well differ from the conversion semantics in the scripting language. For example the XPath 1.0 conversion from string to Boolean returns true for all non-empty strings (including the string "false").

Functions

evalToNodes( xpath : String, prefix-map : Map ) : NodeList

Evaluates an XPath 1.0 expression in the node's context. If the result is a non-empty node-set, returns a list of the nodes in the set. Otherwise returns an empty list.

evalToNode( xpath : String, prefix-map : Map ) : Node

Evaluates an XPath 1.0 expression in the node's context. If the result is a non-empty node-set, returns the first node in the set. Otherwise returns null.

evalToString( xpath : String, prefix-map : Map ) : String

Evaluates an XPath 1.0 expression in the node's context and converts the result to a string value with the XPath 1.0 string() function.

evalToNumber( xpath : String, prefix-map : Map ) : Number

Evaluates an XPath 1.0 expression in the node's context and converts the result to a numeric value with the XPath 1.0 number() function.

evalToBoolean( xpath : String, prefix-map : Map ) : Boolean

Evaluates an XPath 1.0 expression in the node's context and converts the result to a Boolean value with the XPath 1.0 boolean() function.