Math Module

Steve Ball

$Id: math.xsl,v 1.4 2004/10/08 06:37:25 balls Exp $


Introduction

This module provides mathematical functions.

Table of Contents

math:power - Power
math:cvt-hex-decimal - Conversion
math:ordinal - Ordinal number
math:ordinal-as-word - Returns an ordinal number
math:number-as-word - Returns a number as a word

Name

math:power — Power

Synopsis

<xsl:template name="math:power"><xsl:param name="base"/><xsl:param name="power"/>  ...</xsl:template>

Raises a number to a power.

Parameters
base

The base number. Must be a number.

power

The power to raise the number to. Must be an integer.

Returns

Returns base multiplied by itself power times. If the base or power are not numbers or if the power is fractional then an empty string is returned.



Name

math:cvt-hex-decimal — Conversion

Synopsis

<xsl:template name="math:cvt-hex-decimal"><xsl:param name="value"/>  ...</xsl:template>

Converts a hexidecimal value to a decimal value.

Parameters
value

The hexidecimal number. Must be a number in hexidecimal format.

Returns

Returns the value as a decimal string. If the value is not a number then a NaN value is returned.



Name

math:ordinal — Ordinal number

Synopsis

<xsl:template name="math:ordinal"><xsl:param name="number"/>  ...</xsl:template>

Gives the ordinal number of a given counting number. For example, 1 becomes "1st".

Parameters
number

An integer number.

Returns

Returns the number with an ordinal suffix.



Name

math:ordinal-as-word — Returns an ordinal number

Synopsis

<xsl:template name="math:ordinal-as-word"><xsl:param name="number" select="0"/><xsl:param name="conjunctive" select=""yes""/><xsl:param name="preceding" select="0"/>  ...</xsl:template>

This template returns the ordinal number for a given counting number as a word. For example "first" for 1.

Only handles numbers less than 10000000 (ten million).

Parameters
number

The counting number.

conjunctive

Whether to add the word "and" to the result, for example "one hundred and first" rather than "one hundred first". Default is "yes".

Returns

Returns the ordinal number as a string.



Name

math:number-as-word — Returns a number as a word

Synopsis

<xsl:template name="math:number-as-word"><xsl:param name="number" select="0"/><xsl:param name="conjunctive" select="true()"/>  ...</xsl:template>

This template returns the word for a given integer number, for example "one" for 1.

Only handles numbers less than 10000000 (ten million).

Parameters
number

The counting number.

conjunctive

Adds the word "and" where appropriate, for example.

Returns

Returns the number as a string.