Previous: XPath Axis - XPath - Next: XPath Examples

node-set functions

A number of functions are available and may be used to find out information about a node-set.

number last()
Returns a number equal to the size of the node-set.
number position()
Returns a number representing the position of the context node in the expression evaluation context
number count(node-set)
Returns the number of nodes in the argument node-set.
node-set id(object)
Returns the node-set according to the unique ID passed in as the argument.
string local-name(node-set?)
Returns the local name of the given node-set. If the node-set is omitted, then the context node's local name is returned.
string namespace-uri(node-set?)
Returns the namespace URI of the node in the nodeset that is first in document order. If the node-set argument is omitted, then the namespace URI of the context node is returned.
string name(node-set?)
Returns the qualified name of the node in the node-set that is first in document order. If the node-set is empty, the name of the context node is returned.

String Functions

string string(object?)
Converts the given object to a string; if the object argument is omitted, then a node-set containing only the context node is used. For a node-set, the first member node in document order is returned as a string; other data types are converted as would generally be expected. See, Section 4.2 of the XPath spec for more information.
string concat(string, string, string*)
The concat function returns its arguments concatenated together to form a single string.
boolean starts-with(string, string)
Returns true if the first argument begins with the second argument, false otherwise.
boolean contains(string, string)
Returns true if the first argument string contains the second argument string, false otherwise.
string substring-before(string, string)
Returns the portion of the first string argument that precedes the second string argument. For example, substring("2001/08/20", "/") returns 2001.
string substring-after(string, string)
Returns the portion of the first argument string that follows the second argument string. For example, substring("2001/08/20", "/") returns 08/20.
string substring(string, number, number?)
Returns a portion of the first string argument, beginning with the character specified by the second argument, with a length specified by the third optional argument. The position of the first character in a string is 1, not 0, so substring("hijklmno", 3) returns jklmno, while substring("hijklmno", 3, 3) returns jkl.
number string-length(string?)
Returns the number of characters in the argument; if the argument is omitted, then the number of characters in the string representation of the context node is returned.
string normalize-space(string?)
Returns a string which is the same as the argument string (or string value of the context node) except the leading and trailing whitespace is stripped and any whitespace within the string is replaced by a single space.
string translate(string, string, string)
Returns the first argument translated by applying the last two arguments. The second argument is a list of characters to search for in the first argument, and the third argument is a list of characters used to replace characters in the first argument if they match in the second argument. For example, translate("boink", "bnkio", "Bnkio") returns Boink. translate("bar", "abcr", "ABCR") returns BAR.

Boolean Functions

boolean boolean(object)
Returns a boolean representation of the given object. Numbers are true if they are not zero or NaN, a node-set is true if it is not empty, and a string is true if its length is greater than zero.
boolean not(boolean)
Returns the inverse of the argument; true if the argument is false, false if the argument is true.
boolean true()
Returns true.
boolean false()
Returns false.
boolean lang(string)
Returns true if the argument matches the xml:lang attribute of the context node or the nearest ancestor node.

Number Functions

number number(object?)
Returns the number representation of the argument, or if it is omitted, of the context node. A string is converted to a number if it consists of an optional minus sign followed by a number followed by whitespace. Any other string is converted to NaN. Booleans are converted to 1 if true, 0 if false, and node sets are first converted to strings, and then to numbers.
number sum(node-set)
Returns the sum of the node-set found by converting the nodes in the nodeset first to strings and then to numbers.
number floor(number)
Returns the largest integer number that is not greater than the argument.
number ceiling(number)
Returns the smallest integer (closest to -infinity) that is not less than the argument.
number round(number)
Returns the integer that is closest to the argument.

Log in or register to write something here or to contact authors.