<< Click to Display Table of Contents >> XPath basic functions examples |
The data model diagram below will be used as a guide to explain the basic XPath functions. Suppose you are employed in the Loans Department of a bank. Each loan in the Credit Request Process will have a Client allocated who may request one or more Products.
And: Compares two Boolean arguments that can be XPath expressions or the result of another XPath function. It returns true if they are both true. Otherwise it returns false.
Example: The request will need authorization if the client is Not VIP and is viable
<Request.RequestAuthorization> = <and(is-false(Request.Client.VIP),is-true(Request.Client.Viable))>
Avg: Obtains the average value of the elements in the collection. It can only be used on collections that return values of numeric attributes (whole numbers, decimals or currency).
Example: Obtain the average value of all Products.
var average= <avg(Request.Products.ValueRequested)>;
Count : Counts the number of elements in a collection.
Example: Returns the number of approved products in the Request.
var ProductNumber = <count(Request.Products[Approved= true])>;
Empty: Returns True when a collection is EMPTY and False otherwise.
Example: Validates that there is at least one product approved.
if (<empty(Request.Products[Approved= true])>) {
CHelper.ThrowValidationError("There are no approved products");
}
Equals: Compares two XPath arguments and returns true if they are equivalent. The arguments can be either XPath expressions or XPath functions.
Example: The request will need authorization if the client is Not VIP and is viable.
<Request.RequestAuthorization> = <and(equals(Request.Client.VIP, false),equals(Request.Client.Viable,true))>
Exist: Returns True when the collection has at least one element and False otherwise.
Example: Review if there is any product not checked
if (<exists(Request.Products[LegalizationComplete = false])>) {
CHelper.ThrowValidationError("There are products that have not been checked");
}
Greater than: Compares two XPath arguments and returns true if the first argument is greater than the second argument. Otherwise, it returns false. The arguments can be either XPath expressions or XPath functions that return integers, decimals, currency or dates.
Example: A validation is thrown when the client's income is less than the total value requested.
if(<greater-than(Request.TotalValueRequested,Request.Client.Income)>) {
CHelper.ThrowValidationError("The value requested exceeds the client's income")
}
Greater than or equals to: Compares two Xpaths arguments and returns true if the first one is greater than or equal to the second one The arguments can be either XPath expression or XPath functions that return integers, decimals, currency or dates.
Example: If the client is older than 65 a validation in thrown to include an additional insurance.
if(<greater-equals-than(Request.Client.Age,65)>) {
CHelper.ThrowValidationError("The client needs additional insurance due to the age")
}
Is Empty: Returns true if a string-type attribute is null or empty. Returns false otherwise.
Example: if the request needs authorization and the offer description has not been entered, a validation message should be displayed.
if(<and(is-true(Request.RequestAuthorization), is-empty(Request.OfferDescription))>){
CHelper.ThrowValidationError("The request requires authorization and the description has not been entered");
}
Is False: Evaluates an XPath expression or the result of an XPath function. It returns true if the expression result is false. Otherwise, it returns false.
Example: If the client is not viable, the request cannot continue.
if(<is-false(Request.Client.Viable)>){
CHelper.ThrowValidationError("The client is not viable. You may not continue");
}
Is not Empty: Returns true if a string-type attribute is filled. Returns false otherwise
Example: if the request does not need authorization the offer description has to be left blank.
if(<and(is-false(Request.RequestAuthorization), is-not-empty(Request.OfferDescription))>){
CHelper.ThrowValidationError("The description has to be left blank");
}
Is not Null: Returns true if any attribute is filled (not null). Returns false otherwise.
Example: if the penalized date for the client has been left blank, the request will require authorization.
if(<is-not-null(Request.DatePenalized)>){
<Request.RequestAuthorization>= true;
}
Is Null: Returns true if any attribute is null (not filled). Returns false otherwise.
Example: if the penalized attribute for the client has been left blank, the request will not require authorization.
if(<is-null(Request.Client.Penalized)>){
<Request.RequestAuthorization>= false;
}
Is True: Evaluates an XPath expression or the result of an XPath function. It returns true if the parameter is true. Otherwise it returns false.
Example: The request will need authorization if the client is Not VIP or has been reported to the Credit Bureau.
<Request.RequestAuthorization> = <or(is-false(Request.Client.VIP),is-true(Request.Client.ReportedOnCreditBureau))>
Less than: Compares two XPath arguments and returns true if the first one is less than the second one. The parameters can be either XPath expressions or XPath functions that return integers, decimals, currency or dates.
Example: A validation is thrown when the client's income is less than the total value requested
if(<less-than(Request.Client.Income, Request.TotalValueRequested)>) {
CHelper.ThrowValidationError("The value requested exceeds the client's income")
}
Less than or equals to: Compares two XPath arguments and returns true if the first argument is less than or equal to the second argument. The arguments can be either Xpaths expressions or XPath functions that return integers, decimals, currency or dates.
Example: If the date requested is less than or equal to the date penalized, the request cannot continue.
if(<less-equals-than(Request.DateRequested,Request.Client.DatePenalized)>) {
CHelper.ThrowValidationError("The request cannot continue")
}
Like: Compares two parameters and returns true if the second one is included in the first one. The parameters can be string XPath or fixed strings.
Example: The name of a person traveling must be the same in the departing flight and in the returning flight.
<Request.SamePerson> = <like(Request.DepartingUserName,Request.ReturningUserName)>
Max: Obtains the maximum value within the elements of a collection. The attribute must be number or currency.
Example: We will store in a variable the greatest value of the requested products that have been approved.
var maxValue = <max(Request.Products[Approved= true].ValueRequested)>;
Min: Obtains the minimum value within the elements of a collection. The attribute must be number or currency.
Example: We will store in a variable the smallest approved value of the requested products that have been approved.
var maxValue = <min(Request.Products[Approved= true].ValueApproved)>;
Not equals: Compares two XPath arguments and returns true if they are NOT equivalent. The arguments can be either XPath expressions or XPath functions.
Example: The request will need authorization if the client is Not VIP and is viable.
<Request.RequestAuthorization> = <and(not-equals(Request.Client.VIP, true),equals(Request.Client.Viable,true))>
Or: Compares two Boolean arguments that can be XPath expressions or the result of another XPath function. It returns False when both arguments are false. Otherwise it returns True.
Example: The request will need authorization if the client is Not VIP or has been reported to the Credit Bureau.
<Request.RequestAuthorization> = <or(is-false(Request.Client.VIP),is-true(Request.Client.ReportedOnCreditBureau))>
Sum: Adds the elements of a collection. It can only be used on collections that return values of numeric attributes (whole numbers, decimals or currency).
Example: We will store in a variable the sum of the value requested for all approved products.
var Result= <sum(Request.Products[Approved= true].ValueRequested)>;
Last Updated 1/6/2022 11:34:02 AM