XQuery Occurrence Indicators

The following section defines the supported XQuery occurrence indicators. An occurrence indicator defines how many times an item may occur. Occurrence indicators are used in XQuery function signatures to define how many items can be passed into a argument and how many items can be returned from a function.

None

If no occurrence indicator is specified, than the item must appear once and only once as shown in the following example function signature:

bea-xf:trim-left(xs:string $string-var) —> xs:string

In the preceding example, just a single item must be specified for the $string-var1 argument of the trim-left function. For example, the following would be a valid invocation of the normalizedString function:

<result>{bea-xf:trim-left("   abc   ")}</result> 

The following are invalid invocations of the normalizedString function, as specified by the occurrence indicator of the $string-var argument:

<result>{bea-xf:trim-left(())}</result> 
<result>{bea-xf:trim-left("   abc   ","   def   ")}</result> 

?

The ? occurrence indicator defines that the item can occur once or zero times. An item appearing zero times means that the empty sequence is passed in as an argument. (See the following example for details.) The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

The ? occurrence indicator is specified for both the $string-var1 and $string-var2 arguments of the following example XQuery function signature:

xf:tokenize(xs:string? $string-var1, xs:string? $string-var2) —> xs:string*

The ? occurrence indicator for the $string-var1 argument defines that the item can occur once or zero times, as shown in the following table.

Occurs This Many Times . . .
Example

Zero

tokenize((),"\s")

One

tokenize("Jane fell down the hill", "\s")

*

The * occurrence indicator defines that the item can contain zero or more items. The * occurrence indicator is specified in the return value of the following example XQuery function signature:

xf:tokenize(xs:string? $string-var1, xs:string? $string-var2) —> xs:string*

An * occurrence indicator as part of the return value of a function defines that zero or more items may be returned from that function, as shown in the examples of the following table.

Examples
How Many Items Are Returned?
What is Returned?

tokenize("","\s")

Zero


tokenize("Jane", "\s")

One

Jane

tokenize("Jane fell down", "\s")

Many (In this case, three)

("Jane", "fell", "down")

+

The + occurrence indicator defines that the item must appear one or more times.