Table of contentsAppendices |
4.2 String FunctionsString Functionsstring string(object?) The string function converts an object to a string as follows:
If the argument is omitted, it defaults to a node-set with the context node as its only member. NOTE: string concat(string, string, string) The concat function returns the concatenation of its arguments. boolean starts-with(string, string) The starts-with function returns true if the first argument string starts with the second argument string, and otherwise returns false. boolean contains(string, string) The contains function returns true if the first argument string contains the second argument string, and otherwise returns false. string substring-before(string, string) The substring-before function returns the substring
of the first argument string that precedes the first occurrence of the
second argument string in the first argument string, or the empty
string if the first argument string does not contain the second
argument string. For example,
string substring-after(string, string) The substring-after function returns the
substring of the first argument string that follows the first
occurrence of the second argument string in the first argument string,
or the empty string if the first argument string does not contain the
second argument string. For example,
string substring( string , number , number? ) The substring function returns the substring of the
first argument starting at the position specified in the second
argument with length specified in the third argument. For example,
More precisely, each character in the string (see Strings) is considered to have a numeric position: the position of the first character is 1, the position of the second character is 2 and so on. NOTE: The returned substring contains those characters for which the position of the character is greater than or equal to the rounded value of the second argument and, if the third argument is specified, less than the sum of the rounded value of the second argument and the rounded value of the third argument; the comparisons and addition used for the above follow the standard IEEE 754 rules; rounding is done as if by a call to the round function. The following examples illustrate various unusual cases:
number string-length( string? ) The string-length returns the number of characters in the string (see Strings). If the argument is omitted, it defaults to the context node converted to a string, in other words the [string-value] of the context node. string normalize-space(string?) The normalize-space function returns the argument string with whitespace normalized by stripping leading and trailing whitespace and replacing sequences of whitespace characters by a single space. Whitespace characters are the same as those allowed by the S production in XML. If the argument is omitted, it defaults to the context node converted to a string, in other words the [string-value] of the context node. string translate(string, string, string) The translate function returns the first
argument string with occurrences of characters in the second argument
string replaced by the character at the corresponding position in the
third argument string. For example,
NOTE: |