Calling Number Functions

This section describes the number functions that you can call in a query. The operations you can perform are

Converting an Object to a Number

In some situations, you might want to force a numeric comparison. The XPath processor performs a numeric comparison if either operand is numeric and neither is Boolean. (If one operand is Boolean, the XPath processor converts the other to Boolean and performs a Boolean comparison.) However, if neither operand is a numeric or Boolean value, you can call the number() function on one operand to convert it to a numeric value. The XPath processor automatically converts the other operand to a numeric value.

To perform a numeric comparison, you must call the number() function to convert a Boolean operand, if there is one, to a numeric value.

The format of the number() function is

number number(object?)  

If you omit the argument, the value of the argument defaults to a node set with the context node as its only member. Table 85 shows how the number() function converts its argument to a number:

Obtaining the Sum of the Values in a Node Set

To obtain the sum of the values of the nodes in a set, call the sum() function. The format is

number sum(node-set)  

For each node in the argument node-set, the XPath processor converts the string value of the node to a number. The sum() function returns the sum of these numbers.

Obtaining the Largest, Smallest, or Closest Number

To obtain the largest integer that is not greater than a particular number, call the floor() function. The format is

number floor(number)  

The floor() function returns the largest (closest to positive infinity) number that is not greater than the argument and that is an integer. For example:

To obtain the smallest integer that is not less than a particular number, call the ceiling() function. The format is

number ceiling(number)  

The ceiling() function returns the smallest (closest to negative infinity) number that is not less than the argument and that is an integer. For example:

To obtain the closest integer to a particular number, call the round() function. The format is

number round(number)  

The round() function returns the number that is closest to the argument and that is an integer. If there are two such numbers, the function returns the one that is closest to positive infinity. For example:

Metals, Mining & Crude-Oil Production

It can be very dark and dreary in a mine. That's why metal, mining & crude-oil production are using Stylus Studio as their light when it comes to data integration. See which of these top companies are using Stylus Studio to show them the way to XML!

XQuery Tutorial

This XQuery Tutorial is about "BUILDING XQUERY BASED WEB SERVICE AGGREGATION AND REPORTING APPLICATIONS".

EXSLT Tools

EXSLT support in Stylus Studio lets you extend XSLT 1.0 stylesheets and simplify many tasks including computing dates and times, performing mathematical computations, string manipulations and more.

Support for the Saxon XQuery Processor

Stylus Studio's XQuery tools feature integrated support for the Saxon SA 8.7.3 XQuery and XSLT processor so you can Edit, Debug and Run XQuery using Saxon. Java code generation support lets you deploy Saxon XQuery applications with just one click.

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member