Functions provided by XPath 1.0 that can be used in XSL mappings
Arguments within [squared brackets] are optional.
Node-set Functions
count(node-set) | Returns an integer number with the number of nodes in node-set . |
id (Id) | Selects the node with the unique ID specified in Id . Example: <xsl:value-of select="id('abc')/child::para"/> Selects the child node para of the node with the unique ID abc . |
last () | Returns an integer number with the position number of the last node in the current context. Example: <xsl:if test="position() = last()"> checks, if the current node is the last node. |
local-name ([node-set]) | Returns a string with the local part of a node name with namespace declaration. The optional argument node-set specifies a node-set. |
name ([node-set]) | Returns a string with the name of the current node. The optional argument node-set specifies a node-set. |
namespace-uri ([node-set]) | Returns a string with the namespace URI (Uniform Resource Identifier) of the current element or attribute node. The optional argument node-set specifies a node-set. Example: <xsl:value-of select="namespace-uri()"/> Returns the namespace URI (if existing) of the current node. |
position () | Returns an integer number with the position of the current node. The first node has the position number 1 . |
Boolean Functions
Boolean XPath functions return true/false
values and can be combined with logical operators.
boolean (Arg) | Checks if argument Arg is true and returns a boolean value. All arguments that are a positive number, a non-empty string or a non-empty node-set, will be interpreted as true . |
false () | Returns false . |
lang (Arg) | Returns true , if the language specified in argument Arg matches at least partially the language that has been specified in an xml:lang attribute. Example: lang("en") returns true , if the current node contains the attribute xml:lang="en" or matches partially like xml:lang="en-US" . |
not (Arg) | Returns the negation of a boolean expression in argument Arg . Example: <xsl:if test="not(element > 1)"> returns true , if the content of element is less or equal to 1 . |
true () | Returns true . |
Number Functions
XPath number functions return integer numbers and can be combined with logical operators.
ceiling (Arg) | Rounds up a number within the argument Arg to the next higher integer number and returns this integer number (e. g. 0.001 to 1 ). If necessary, the argument will be converted to a number first. Mathematically correct: Returns the smallest integer number that is not smaller than the argument Arg . |
floor (Arg) | Rounds down a number within the Arg to the next lower integer number and returns this integer number (e. g. 0.999 to 0 ). If necessary, the argument will be converted to a number first. Mathematically correct: Returns the biggest integer number that is not bigger than the argument Arg. |
number ([Arg]) | Converts the current node's content into a number and returns this number. Optionally, the argument Arg can specify a node-set, string, boolean value or another object to be converted. Boolean values true and false will be converted to 1 and 0 . Example: A string 3xy will be converted to 3 ; xy will be interpreted as NaN (Not a Number). |
round (Arg) | Rounds a number within the argument Arg to the next positive or negative integer number and returns this number. Numbers lower than [value].5 will be rounded down, fractions greater or equal [value].5 will be rounded up to the next higher integer number. Example: 0.49 will be rounded down to 0 , -1.5 will be rounded up to -1 . |
sum (node-set) | Creates the total sum of all node contents of the argument node-set and returns it as number. If necessary, the node contents will be converted to numbers first. Values that cannot be interpreted as numbers will be handled as NaN (Not a Number). |
String Functions
XPath string functions handle objects and return strings or boolean values when evaluating strings.
concat (Arg1, Arg2 [, ...] ) | Joins multiple strings that are handed over as arguments Arg1, Arg2 etc. and returns a string. If necessary, all arguments will be converted to a string first. |
contains (Arg, Substring) | Checks if the argument Substring is contained within the argument Arg and returns a boolean value. If necessary, all arguments will be converted to a string first. Example: <xsl:if test="contains('SoftProject', 'Project')"> returns the boolean value true. |
starts-with (Arg, Substring) | Checks if the argument Arg starts with the argument Substring and returns a boolean value. If necessary, all arguments will be converted to a string first. Example: <xsl:if test="starts-with('SoftProject', 'Soft')"> returns the boolean value true. |
normalize-space ([Arg]) | Removes leading and trailing whitespaces of the current node content, replaces multiple whitespaces, tabulators and line breaks with a single whitespace, and returns the node content as string. Optionally, an argument Arg can be used, which will be converted to a string, if required. |
string ([Arg]) | Converts the current node content into a string and returns this string. Optionally, the argument Arg may contain boolean values that will be converted to true or false . Decimal numbers will be simplified, if possible. Use the XSLT function formatnumbers() for all further number-to-string conversions. Example: <xsl:value-of select="string(4.00)"/> returns the string 4. Check if the value is a number: <xsl:if test="string(number(@value))!='NaN'"> . |
string-length ([Arg]) | Returns an integer number with the number of characters of the current node content. If necessary, all arguments will be converted to a string first. Optionally, an argument Arg can be used, which will be converted to a string, if required. |
substring (Arg, Start, [length]) | Extracts a substring of the argument Arg starting from the character Start , and returns a string. The character counting starts with 1 . Optionally, the argument Length can be used, which specifies the maximum length of the substring. |
substring-before (Arg, Substring) | Checks if a string in argument Arg contains a substring within the argument Substring and returns a string with all characters that precede the substring. If Substring is not contained in Arg , an empty string will be returned. Example: <xsl:value-of select="substring-before('2008/04/01', '/')"/> returns 2008. |
substring-after (Arg, Substring) | Checks if a string in argument Arg contains a substring within the argument Substring and returns a string with all characters that follow the substring. If Substring is not contained in Arg , an empty string will be returned. Example: <xsl:value-of select="substring-after('2008/04/01', '20')"/> returns 08/04/01. |
translate (Arg, Substring1, Substring2) | Searches in argument Arg for a string within the argument Substring1 , replaces this with the string within argument Substring2 , and returns the modified string. If necessary, the argument Arg will be converted to a string first. Each matching character of Substring1 will be replaced with the corresponding character from Substring2 . Example: <xsl:value-of select="translate('hello world', 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')" /> returns HELLO WORLD. |