Name

string( )

Synopsis

                     string string( )
string string(object o)

The string( ) function converts an object to a string according to these rules:

  • A node-set is converted to the string-value of the first node in the node-set. If the node-set is empty, it’s converted to the empty string.

  • A number is converted to a string as follows:

  • —NaN is converted to the string NaN.

  • —Positive Inf is converted to the string Infinity.

  • —Negative Inf is converted to the string -Infinity.

  • Integers are converted to their customary English form with no decimal point and no leading zeros. A minus sign is used if the number is negative, but no plus sign is used for positive numbers.

  • Nonintegers (numbers with nonzero fractional parts) are converted to their customary English form with a decimal point, with at least one digit before the decimal point and at least one digit after the decimal point. A minus sign is used if the number is negative, but no plus sign is used for positive numbers.

  • A Boolean with the value true is converted to the English word “true.” A Boolean with the value false is converted to the English word “false.” Lowercase is always used.

The object to be converted is normally passed as an argument, but if omitted, the context node is converted instead.

Warning

The XPath specification specifically notes that the “string function is not intended for converting numbers into strings for presentation to users.” The primary problem is that it’s not localizable and not attractive for large numbers. If you ...

Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.