XPath/XQuery starts-with function

Summary

Returns true if the string $arg1 contains $arg2 as a leading substring, taking collations into account.

Signatures

fn:starts-with(
$arg1 as xs:string?,
$arg2 as xs:string?
) as xs:boolean
fn:starts-with(
$arg1 as xs:string?,
$arg2 as xs:string?,
$collation as xs:string
) as xs:boolean

Properties

The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations.
The three-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations static-base-uri.

Rules

If the value of $arg1 or $arg2 is the empty sequence, or contains only ignorable collation units, it is interpreted as the zero-length string.

If the value of $arg2 is the zero-length string, then the function returns true. If the value of $arg1 is the zero-length string and the value of $arg2 is not the zero-length string, then the function returns false.

The collation used by this function is determined according to the rules in .

The function returns an xs:boolean indicating whether or not the value of $arg1 starts with a sequence of collation units that provides a match to the collation units of $arg2 according to the collation that is used.

Match is defined in .

Examples

The collation used in these examples, http://example.com/CollationA is a collation in which both "-" and "*" are ignorable collation units.

"Ignorable collation unit" is equivalent to "ignorable collation element" in .

The expression fn:starts-with("tattoo", "tat") returns true().

The expression fn:starts-with ( "tattoo", "att") returns false().

The expression fn:starts-with ((), ()) returns true().

The expression fn:starts-with ( "abcdefghi", "-a-b-c-", "http://www.w3.org/2013/collation/UCA?lang=en;alternate=blanked;strength=primary") returns true().

The expression fn:starts-with ( "a*b*c*d*e*f*g*h*i*", "a-bc-", "http://www.w3.org/2013/collation/UCA?lang=en;alternate=blanked;strength=primary") returns true().

The expression fn:starts-with ( "abcd***e---f*--*ghi", "abcdef", "http://www.w3.org/2013/collation/UCA?lang=en;alternate=blanked;strength=primary") returns true().

The expression fn:starts-with ( (), "--***-*---", "http://www.w3.org/2013/collation/UCA?lang=en;alternate=blanked;strength=primary") returns true().

The expression fn:starts-with ( "-abcdefghi", "-abc", "http://www.w3.org/2013/collation/UCA?lang=en;alternate=blanked;strength=primary") returns true().

Error Conditions

A dynamic error may be raised if the specified collation does not support collation units.