XQuery Reference

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

XQuery Aggregate Function Reference

This chapter provides descriptions of the XQuery aggregate functions available in the mapper functionality of WebLogic Workshop. You use the mapper functionality to generate queries and to edit these queries to add invocations to these provided XQuery functions. To learn more, see see Invoking Functions or Operators in a Query.

In addition to the XQuery functions and operators available in the mapper functionality, a larger set functions and operators is provided. You can manually add invocations to these functions and operators to queries in the Source View of the mapper functionality. For a list of these additional functions and operators, see the XQuery 1.0 and XPath 2.0 Functions and Operators - W3C Working Draft 16 August 2002 available from the W3C Web site at the following URL:

http://www.w3.org/TR/2002/WD-xquery-operators-20020816

This section lists the aggregate functions available from the Mapper tool:

 


xf: count

Counts the number items in the sequence.

Signatures

xf:count(item*$item-var) —>xs: unsignedInt

Table 7-1 Arguments
Data Type
Argument
Description
item*
$item-var
Represents the sequence to be counted.

Returns

Returns the number of items in a sequence passed into $item-var as an unsignedInt value.

Returns 0 if $item-var is the empty sequence. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Examples
Simple

Invoking count(("a","b","c")) returns the unsigned integer value of 3, as shown in the following example query:

<result>{xf:count(("a","b","c"))}</result>

The preceding query generates the following result:

<result>3</result>

Empty Sequence

Invoking count(()) returns the unsigned integer value of 0 because () is an empty sequence (contains no elements), as shown in the following example query:

<result>{xf:count(())}</result>

The preceding query generates the following result:

<result>0</result>

Related Topics

W3C count function description.

 


xf: avg

Determines the average of all the numbers in a sequence.

If the value of $item-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xf:avg(item* $item-var) —> xs: double?

Table 7-2 Arguments
Data Type
Argument
Description
item*
$item-var
Represents the sequence of numbers to add together.

Returns

Returns the average of all the numbers in a sequence passed into $item-var.

Examples
Simple

Invoking xf:avg(("3","1","2")) returns the value of 2.0, as shown in the following example query:

<result>{xf:avg(("3","1","2"))}</result>

The preceding query generates the following result:

<result>2.0</result>

Empty Sequences

Invoking xf:avg((1,(),6,2,9)) returns the value of 4.5, as shown in the following example query:

<result>{xf:avg((1,(),6,2,9))}</result>

The preceding query generates the following result:

<result>4.5</result>

Note: Instances of the empty sequence () are ignored.
Nodes

Invoking the following query returns the value of 50, as shown in the following example query:

let $x := <a>100</a>

let $y := <b>50</b>

let $z := <c>0</c>

return <result>{xf:avg(($x,$y,$z))}</result>

The preceding query generates the following result:

<result>50.0</result>

In this example, the value of the nodes are extracted before the numbers are averaged together—as if the data function had been invoked on each node in the sequence before being averaged together.

Related Topics

W3C avg function description.

 


xf: max

Finds the maximum value in a sequence.

If the value of $item-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xf:max(integer* $integer-var) —> xs: anySimpleType?

Table 7-3 Arguments
Data Type
Argument
Description
integer*
$integer-var
Represents the sequence to evaluate.

Returns

Returns the number with the highest value from the sequence passed into $item-var.

Examples
Simple

Invoking xf:max(("3","1","2")) returns the value of 3, as shown in the following example query:

<result>{xf:max(("3","1","2"))}</result>

The preceding query generates the following result:

<result>3</result>

Empty Sequences

Invoking xf:max((1,(),6,2,9)) returns the value of 9, as shown in the following example query:

<result>{xf:max((1,(),6,2,9))}</result>

The preceding query generates the following result:

<result>9</result>

Note: Instances of the empty sequence () are ignored.
Nodes

Invoking the following query returns the value of 100, as shown in the following example query:

let $x := <a>100</a>

let $y := <b>2</b>

let $z := <c>50</c>

return <result>{xf:max(($x,$y,$z))}</result>

The preceding query generates the following result:

<result>50</result>

In this example, the value of the nodes are extracted before the comparison to determine the maximum number is done—as if the data function had been invoked on each node in the sequence before the comparison. However, the string values of the nodes are extracted and compared and not the integer values of the node. In the preceding query, the string: 50 is reported as the maximum value because the ASCII value of the character 5 is greater than the ASCII value of the character 1, the first character in the string: 100. To compare the integer values of the nodes instead, first convert the node sequences to integers using the bea-xf:integer-sequence function and then invoke the xf:max function, as shown in the following example query:

let $x := <a>100</a>

let $y := <b>2</b>

let $z := <c>50</c>

return <result>{xf:max(bea-xf:integer-sequence(($x,$y,$z)))}</result>

The preceding query generates the following result:

<result>100</result>

Related Topics

W3C max function description.

BEA bea-xf: integer-sequence function description.

 


xf: min

Finds the minimum value in a sequence.

If the value of $item-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xf:min(integer* $integer-var) —> xs: anySimpleType?

Table 7-4 Arguments
Data Type
Argument
Description
integer*
$integer-var
Represents the sequence to evaluate.

Returns

Returns the number with the lowest value from the sequence passed into $item-var.

Examples
Simple

Invoking xf:min(("3","1","2")) returns the value of 1, as shown in the following example query:

<result>{xf:min(("3","1","2"))}</result>

The preceding query generates the following result:

<result>1</result>

Empty Sequences

Invoking xf:min((1,(),6,2,9)) returns the value of 1, as shown in the following example query:

<result>{xf:min((1,(),6,2,9))}</result>

The preceding query generates the following result:

<result>1</result>

Note: Instances of the empty sequence () are ignored.
Nodes

Invoking the following query returns the value of 2, the lowest number in the sequence, as shown in the following example query:

let $x := <a>100</a>

let $y := <b>2</b>

let $z := <c>50</c>

return <result>{xf:min(($x,$y,$z))}</result>

The preceding query generates the following result:

<result>100</result>

In this example, the value of the nodes are extracted before the comparison to determine the minimum number is done—as if the data function had been invoked on each node in the sequence before the comparison. However, the string values of the nodes are extracted and compared and not the integer values of the node. In the preceding query, the string: 100 is reported as the minimum value because the ASCII value of the character 1 is less than the ASCII value of the character 5, the first character in the string: 50. To compare the integer values of the nodes instead, first convert the node sequences to integers using the bea-xf:integer-sequence function and then invoke the xf:min function, as shown in the following example query:

let $x := <a>100</a>

let $y := <b>2</b>

let $z := <c>50</c>

return <result>{xf:min(bea-xf:integer-sequence(($x,$y,$z)))}</result>

The preceding query generates the following result:

<result>2</result>

Related Topics

W3C min function description.

BEA bea-xf: integer-sequence function description.

 


xf: sum

Determines the sum of all the items in a sequence.

Signatures

xf:sum(item*$item-var) —> xs: double?

Table 7-5 Arguments
Data Type
Argument
Description
item*
$item-var
Represents the sequence to evaluate.

Returns

Returns the sum of all the numbers in a sequence passed into $item-var.

Returns 0.0 if $item-var is the empty sequence. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Examples
Simple

Invoking xf:sum(("3","1","2")) returns the value of 6, as shown in the following example query:

<result>{xf:sum(("3","1","2"))}</result>

The preceding query generates the following result:

<result>6.0</result>

Empty Sequences

Invoking xf:sum((1,(),6,2,9)) returns the value of 18, as shown in the following example query:

<result>{xf:sum((1,(),6,2,9))}</result>

The preceding query generates the following result:

<result>18.0</result>

Note: Instances of the empty sequence () are ignored.
Nodes

Invoking the following query returns the value of 152, as shown in the following example query:

let $x := <a>100</a>

let $y := <b>2</b>

let $z := <c>50</c>

return <result>{xf:sum(($x,$y,$z))}</result>

The preceding query generates the following result:

<result>152.0</result>

In this example, the value of the nodes are extracted before the numbers are added to together—as if the data function had been invoked on each node in the sequence before being added together.

Related Topics

W3C sum function description.


  Back to Top       Previous  Next