• The 25 XPath function are extended by XSLT 1.0 to make 36 in total
    • conversions (eg, number())
    • string manipulation (eg, concat())
    • arithmetic (eg, floor(), sum())
    • getting node and identifier names (eg, lang())
    • boolean (eg, not())
    • context information (eg, last())

Alpahabetic List

Function Meaning
boolean Converts number, string, node-set to Boolean. Normally automatic
ceiling Convert to number and round up
concat Concatenates two or more string arguments into one
contains Tests whether a string has another string as a substring
count Number of nodes in the node-set, useful for upper bounds on traversals
current Returns the current node as a node-set
document Returns the root node of a URL to an XML file
element-available Checks whether an extension is available
false Returns the value false
floor largest integer less than the number
format-number Converts numbers into strings for output
function-available Test for extension function availability
generate-id Defines unique id for a node
id Returns the node as a node-set with that id
key Used with xsl:key to locate a node with a given key
lang Checks whether lang attribute is same as one given
last Number assigned to last node in a list of nodes
local-name Name of node without nameset part
name Local part of name of node
namespace-url xmlns value of namespace definition of node
normalize-space Reduces whitespace to single value
not Boolean negation
number Converts argument string to a number
position Number of node in list starting from 1
round Nearest integer value, 0.5 rounds up
starts-with Checks whether one string starts with the other
string Converts argument to string
string-length Length of string in characters
substring Returns part of string between the two values
substring-after Returns all the string after the sub-string specified
substring-before Returns all the string before the sub-string specified
sum Adds up all the node values
system-property Returns version of XSLT
translate Converts strings, eg upper to lower case
true Returns the value true
unparsed-entity-url Returns the URL for images etc

Numeric Functions

XPath provides some functions to aid the calculation of numeric values:

number()
Converts a string to a number, use it to be precise.
round()
Converts value to a number, round to nearest integer
  • round(1.6) is 2; round(1.4) is 1; round(1.5) is 2
ceiling()
Converts value to a number, round up to next highest integer
  • ceiling(1.6) is 2; ceiling(2) is 2; ceiling(-1.6) is -1
floor()
Converts value to a number, round down to next lowest integer
  • floor(1.6) is 1; floor(2) is 2; floor(-1.6) is -2
sum()
Converts the string value of each node in the node-set to a number and sum these numbers
count()
Returns the number of nodes in the node-set

String Manipulation

concat(string1 , string2 , string3,   ..  , stringn)
contains(string , substring)
normalize-space(string)
starts-with(string , substring)

The string parameter defines the string to which the function is applied. The substring parameter defines the operation to be performed. Frequently the result is a new string

concat
Concatenates all the strings together
contains
Returns true if substring part of string
normalize-space
Removes leading and trailing whitespace characters and replaces sequences of whitespace characters with a single space character
starts-with
Result is true if the string starts with the substring specified
string-length(string)
substring(string , numstart , numchars)
substring-before(string , substring)
substring-after(string , substring)
translate(string, fromchars , tochars)
string-length
The number of characters in the string is returned
substring
Counting from 1, the substring of length numchars starting at position numstart is returned
substring-before
The substring before the specified substring is returned
substring-after
The substring after the specified substring is returned
translate
Characters appearing in the fromchars parameter are replaced by the corresponding character in the tochars parameter otherwise the character is copied. If no character in tochars for the fromchars it is omitted

Tests and Conversions

boolean(value)           number(value)            string(value)
false()                  true()                   not(value)
boolean
If value is a number, 0 converts to false, anything else to true
Zero-length string and empty node-set convert to false
number
Boolean value: false becomes 0 and true becomes 1.
String value: Removes trailing and leading whitespace then converts to a number. Note + is not allowed but - is.
Node-set gets converted to string and then to a number.
string
Boolean values get turned to strings true and false. Numbers get converted to strings. A node-set gets converted to the value of the first node.
false
Returns value false
true
Returns value true
not
The input value is converted to a Boolean and then negated

Context Functions

position()
last()
position
The position of the current node in the set of nodes being processed. For xsl:for-each or xsl:apply-templates, the order of the set of nodes after any xsl:sort elements have been applied
last
Returns a number that defines the number of nodes being processed. For xsl:for-each or xsl:apply-templates, it is the number of nodes in the node-set being processed

Formatting Numbers

format-number(value, pattern)

Formats value with format defined by pattern. Result is a string:

  • 0 : indicates a digit will be placed here
  • # : indicates a digit will be placed here if it is not a leading zero
  • . : indicates where the decimal point is
  • , : indicates where a grouping character will appear
Number Format string
0.0123456789 ##0 0
-1.234 ##0 -1
12345678 ##0 12345678
-1.234 000 -001
0.00004 000.000 000.000
0.12345678 000.000 000.012
12345678 000.000 12345678.000
0.00004 ##0.0## 0.0
123 ##0.0## 123.0
12345678 ##0.0## 12345678.0
12345678 ###,###,##0.0## 12,345,678.0

Look up the standard or read a book if you need anything more complex!

Formatting

  • Be careful with regard to file size if you are doing real arithmetic
  • Numbers may get stored to a large number of decimal places
  • Formatting keeps the accuracy down to what is required and reduces file size