This version: exslt-math-010310.html

Most Recent version: http://www.jenitennison.com/xslt/exslt/math/

Previous version: exslt-math-010302.html

Author: Jeni Tennison

This document describes EXSLT 1.0 - Math. EXSLT 1.0 is a set of extension elements and functions that XSLT authors may find helpful when creating stylesheets. EXSLT 1.0 - Math covers those extension elements and functions that provide facilities to do with maths.

Other parts of EXSLT 1.0 include:

This document is a second draft for review by the implementers of XSLT processors and the XSLT stylesheet authors. It is based on discussions on XSL-List. Comments on this document should be sent to XSL-List.

This document has no official standing and has not been considered nor approved by any organization.

1. Introduction

2. Namespace

3. Math Functions

A. References

B. Implementations in EXSLT

C. Acknowledgements

D. Changes from Previous Version

This document describes EXSLT 1.0 - Math. EXSLT 1.0 is a set of extension elements and functions that XSLT authors may find helpful when creating stylesheets. EXSLT 1.0 - Math covers those extension elements and functions that provide facilities to do with maths.

The extension elements and functions defined within this document are governed by the general rules about extensions to XSLT covered in [14. Extensions] in [XSLT 1.0].

XSLT processors are free to support any number of the extension elements and functions described in this document. However, an XSLT processor must not claim to support EXSLT 1.0 - Math unless all the extensions described within this document are implemented by the processor. An implementation of an extension element or function in an EXSLT namespace must conform to the behaviour described in this document.

The namespace for the extension elements and functions described in this document is:

http://xmlns.opentechnology.org/xslt-extensions/math

Throughout this document, the prefix `math`

is used to refer to this namespace. Any other prefix can be used within a particular stylesheet (though a prefix must be specified to enable the extension functions to be recognised as extensions).

This section defines the extension functions in EXSLT 1.0 - Math.

**Function:** `number` **math:max**(`node-set`)

The math:max function returns the maximum, for each node in the argument node-set, of the result of converting the string-values of the node to a number using the number function. The numbers are compared as with the `>`

operator. If the node set is empty, `NaN`

is returned.

**Function:** `number` **math:min**(`node-set`)

The math:min function returns the maximum, for each node in the argument node-set, of the result of converting the string-values of the node to a number using the number function. The numbers are compared as with the `<`

operator. If the node set is empty, `NaN`

is returned.

**Function:** `node-set` **math:highest**(`node-set`)

The math:highest function returns the nodes for which the result of converting the string-value of the node to a number is maximum value for the node set, as calculated with math:max.

**Function:** `node-set` **math:lowest**(`node-set`)

The math:lowest function returns the nodes for which the result of converting the string-value of the node to a number is minimum value for the node set, as calculated with math:min.

**EXSLT Common**- Jeni Tennison.
*Extensions to XSLT 1.0 (EXSLT 1.0) - Common*. See http://www.jenitennison.com/xslt/exslt/common **XSLT**- World Wide Web Consortium.
*XSL Transformations (XSLT)*. W3C Recommendation. See http://www.w3.org/TR/xslt **XPath**- World Wide Web Consortium.
*XML Path Language*. W3C Recommendation. See http://www.w3.org/TR/xpath

This appendix holds example implementations of the functions defined in this document, using `exsl:function`

as described in [EXSLT Common].

**Function:** `number` **math:max**(`node-set`, `string`?)

<exsl:function name="math:max"> <xsl:param name="node-set" select="/.." /> <exsl:result select="number($node-set[not($node-set > .)])" /> </exsl:function>

**Function:** `number` **math:min**(`node-set`, `string`?)

<exsl:function name="math:min"> <xsl:param name="node-set" select="/.." /> <exsl:result select="number($node-set[not($node-set < .)])" /> </exsl:function>

**Function:** `node-set` **math:highest**(`node-set`, `string`?)

<exsl:function name="math:highest"> <xsl:param name="node-set" select="/.." /> <exsl:result select="$node-set[not($node-set > .)]" /> </exsl:function>

**Function:** `node-set` **math:lowest**(`node-set`, `string`?)

<exsl:function name="math:lowest"> <xsl:param name="node-set" select="/.." /> <exsl:result select="$node-set[not($node-set < .)]" /> </exsl:function>

This document describes functions that are currently in use in Saxon by Mike Kay. It has also been informed and inspired by discussions on XSL-List.

Also many thanks to Uche Ogbuji for his comments following implementation of these functions in 4XSLT.

- Changed the prefix used in this document from '
`num`

' to '`math`

'. - Changed wording on conformance in the Introduction.
- Removed arguments that require dynamic evaluation.
- Removed math:sum function as without dynamic evaluation, this is already supported in XSLT.
- Changed wording on math:max, math:min, math:highest and math:lowest to indicate that the node values are converted to numbers as with the number function.