Conversion functions

The following conversion functions are supported:

  • boolean: converts arguments to Booleans according to the following rules:
    • If the argument is a negative or positive number, it is converted to a Boolean value true. If the argument is zero or an NaN value, it is converted to false.
    • If the argument is a non-empty node-set, it is converted to true. An empty node-set is converted to false.
    • If the argument is a non-empty string, it is converted to true. An empty string is converted to false.
    • If the argument is an object of a type other than the four basic types (node-set, Boolean, number, or string), it is converted to a Boolean in a way that is dependent on that type.
    • Full description: https://www.w3.org/TR/xpath-functions/#func-boolean
  • number: converts its argument to a number as follows:
    • A string that consists of optional white space, followed by an optional minus sign, followed by a number, followed by white space is converted to the IEEE 754 number that is nearest to the mathematical value represented by the string (according to the IEEE 754 round-to-nearest rule)
    • Any other string is converted to NaN.
    • Boolean true is converted to 1; Boolean false is converted to 0.
    • A node-set is first converted to a string and then converted in the same way as a string argument.
    • An object of a type other than the four basic types (node-set, Boolean, number, or string) is converted to a number in a way that is dependent on that type.
    • Full description: https://www.w3.org/TR/xpath-functions/#func-number
  • string: returns the string value of the argument. The argument could be a number, boolean or node-set.

Related Links