Returns the number of
fn:string-length
( xs:integer
fn:string-length
( $arg
as xs:string?
xs:integer
The function returns an xs:integer
equal to the length in characters of the value of $arg
.
Calling the zero-argument version of the function is equivalent to calling
fn:string-length(fn:string(.))
.
If the value of $arg
is the empty sequence, the function returns the
xs:integer
value zero (0).
The expression fn:string-length("Harp not on that string, madam; that is past.")
returns 45
.
The expression fn:string-length(())
returns 0
.
If $arg
is not specified and the context item is absent, a dynamic error is raised: .
Unlike some programming languages, a codepoint greater than 65535 counts as one character, not two.
There are situations where fn:string-length()
has a different effect
from fn:string-length(.)
. For example, if the context item
is an attribute node typed as an xs:integer
with the string value 000001
,
then fn:string-length()
returns 6 (the length of the string value of the node), while
fn:string-length(.)
raises a type error (because the result of atomization
is not an xs:string
).