O'Reilly logo

XQuery by Priscilla Walmsley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 $catalog parameter must be one (and only one) element

  • xs:integer*, to specify that the return type of the function is zero to many xs:integer values

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.

Syntax of a sequence typeThe detailed syntax of < element-attribute-test > is shown in Figure 13-4.

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required