Sequence Types
A sequence type is used in a query to specify the expected type of a sequence of zero, one, or more items. When declaring functions, sequence types are used to specify the types of the parameters as well as the return value. For example, the function declaration:
declare function local:getProdNums ($catalog as element( )) as xs:integer*
{$catalog/product/xs:integer(number)};uses two sequence types:
element( ), to specify that the$catalogparameter must be one (and only one) elementxs:integer*, to specify that the return type of the function is zero to manyxs:integervalues
Sequence types are also used in many type-related expressions, such as the cast as, treat as, and instance of expressions. The syntax of a sequence type is shown in Figure 11-2.

Figure 11-2. Syntax of a sequence type[a]
Occurrence Indicators
An occurrence indicator can be used at the end of a sequence type to indicate how many items can be in a sequence. The occurrence indicators are:
?
For zero or one items
*
For zero, one, or many items
+
For one or many items
If no occurrence indicator is specified, it is assumed that the sequence can have one and only one item. For example, a sequence type of xs:integer matches one and only one atomic value of type xs:integer. A sequence type of xs:string* matches a sequence that is either the empty sequence or contains one or more atomic values of type ...
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