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:
Counts the number items in the sequence.
xf:
count
(item*$item-var)
—>xs:
unsignedInt
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.
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:
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:
W3C count function description.
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.
xf:
avg
(item* $item-var
) —> xs:
double?
Returns the average of all the numbers in a sequence passed into $item-var
.
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:
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:
Note: | Instances of the empty sequence () are ignored. |
Invoking the following query returns the value of 50, as shown in the following example query:
return <result>{xf:avg(($x,$y,$z))}</result>
The preceding query generates the following 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.
W3C avg function description.
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.
xf:
max
(integer* $integer-var)
—> xs:
anySimpleType?
Returns the number with the highest value from the sequence passed into $item-var
.
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:
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:
Note: | Instances of the empty sequence () are ignored. |
Invoking the following query returns the value of 100, as shown in the following example query:
return <result>{xf:max(($x,$y,$z))}</result>
The preceding query generates the following 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:
return <result>{xf:max(bea-xf:integer-sequence(($x,$y,$z)))}</result>
The preceding query generates the following result:
W3C max function description.
BEA bea-xf: integer-sequence function description.
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.
xf:
min(
integer* $integer-var
) —> xs:
anySimpleType?
Returns the number with the lowest value from the sequence passed into $item-var
.
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:
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:
Note: | Instances of the empty sequence () are ignored. |
Invoking the following query returns the value of 2, the lowest number in the sequence, as shown in the following example query:
return <result>{xf:min(($x,$y,$z))}</result>
The preceding query generates the following 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:
return <result>{xf:min(bea-xf:integer-sequence(($x,$y,$z)))}</result>
The preceding query generates the following result:
W3C min function description.
BEA bea-xf: integer-sequence function description.
Determines the sum of all the items in a sequence.
xf:
sum
(item*$item-var
) —> xs:
double?
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.
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:
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:
Note: | Instances of the empty sequence () are ignored. |
Invoking the following query returns the value of 152, as shown in the following example query:
return <result>{xf:sum(($x,$y,$z))}</result>
The preceding query generates the following 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.
W3C sum function description.