XPath Aggregate Functions

Last modified: June 28, 2023

1 Introduction

This document describes XPath query aggregate functions.

The following XPath query aggregate functions are available:

2 avg

The avg() function returns the average of its argument.

2.1 Examples

This query returns the average total price of all placed orders:

avg(//Sales.Order/TotalPrice)

This query returns the average total price of all orders placed by a customer named “Jansen”:

avg(//Sales.Order[Sales.Customer_Order/Sales.Customer = 'Jansen']/TotalPrice)

3 count

The count() function counts all objects retrieved by the enclosed query and returns the value as an integer.

3.1 Examples

This query returns a count of all the placed orders:

count(//Sales.Order)

This query returns a count of all the orders placed by a customer named “Jansen”:

count(//Sales.Order[Sales.Customer_Order/Sales.Customer/Name = 'Jansen'])

4 max

The max() function returns the maximum value of its argument.

4.1 Examples

This query returns the highest total price found in any object:

max(//Sales.Order/TotalPrice)

This query returns the highest total price of an order placed by a customer named “Jansen”:

max(//Sales.Order[Sales.Customer_Order/Sales.Customer/Name = 'Jansen']/TotalPrice)

5 min

The min() function returns the minimum value of its argument.

5.1 Examples

This query returns the lowest total price found in any object:

min(//Sales.Order/TotalPrice)

This query returns the lowest total price of an order placed by a customer named “Jansen”:

min(//Sales.Order[Sales.Customer_Order/Sales.Customer/Name = 'Jansen']/TotalPrice)

6 sum

The sum() function returns the sum of its argument.

6.1 Examples

This query returns the sum of the total prices of all placed orders:

sum(//Sales.Order/TotalPrice)

This query returns the sum of the total prices of all the orders placed by a customer named “Jansen”:

sum(//Sales.Order[Sales.Customer_Order/Sales.Customer/Name = 'Jansen']/TotalPrice)