XPath not
Overview
The not()
function inverts the meaning (and as such; the result) of the argument.
not()
function can have different results from an inverse comparison (for example, !=
as the negative of =
). See the examples below for more explanation.
Examples
This query returns all customers whose names are not equal to “Jansen”:
//Sales.Customer[not(Name = 'Jansen')]
In this case, the above query returns the same result as the following query:
//Sales.Customer[Name != 'Jansen']
The following query returns all the customers who have not placed at least one order:
//Sales.Customer[not(Sales.Customer_Order/Sales.Order)]
The following query returns all the customers who have placed no orders with a TotalPrice
of more than 30,000, including those who have not placed any orders at all:
//Sales.Customer[not(Sales.Customer_Order/Sales.Order/TotalPrice > 30000)]
The query above does not return the same result as the one below, which returns all the customers who have placed at least one order with a TotalPrice
of less than 30,000, regardless of the number of orders they have placed worth more than 30,000:
//Sales.Customer[Sales.Customer_Order/Sales.Order/TotalPrice <= 30000]
For example, if a customer has placed two orders—one for 15,000 and one for 35,000—this query will return this customer, while the not query will not. Customers who have not placed any orders will not be returned by this query.