XPTY0004
This error is a general type error that is raised when a value has a type that is incompatible with the type expected by a function or other expression. This could be because the type of the value is incorrect for the expression, which is the case when you try to multiply two strings. It could also arise if the value is a sequence of fewer or more items than are expected, for example when you pass the substring function a sequence of multiple strings instead of just a single string.
Common cases that raise this type error are:
Comparing values with incomparable types, for example,
"abc" = 1.Attempting to compare sequences of more than one value using the value comparison operators, for example,
(1, 2) eq (1, 2).Attempting arithmetic operations on values that are not numbers or dates, for example,
"abc" + "def".Calling a function with arguments that have incorrect types, for example,
substring(1234, 3), whose first argument is an integer instead of a string.Calling a function with too few or too many items in an argument, for example,
substring( ("a", "b"), 3), which passes a sequence of two items as the first argument instead of just one.Passing an invalid operand to a type constructor or
cast asexpression. This includes passing a nonliteral value when constructing a value of typexs:QName(or a type derived fromxs:QNameorxs:NOTATION). These types have a special constraint that they can only accept a literalxs:stringvalue, not an evaluated expression.Using an
order ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access