home contribute faq download

FunctX XSLT Functions

functx:ordinal-number-en

Reformats a number as an ordinal number, e.g. 1st, 2nd, 3rd.

Google
Webxsltfunctions.com

Description

The functx:ordinal-number-en function returns the corresponding ordinal number (in English) of $num. For example, if $num is 245, it will return "245th".

The $num argument must have the type xs:integer (or an untyped value that can be cast to xs:integer), or an error is raised.

Arguments and Return Type

NameTypeDescription
$num xs:integer? the number
return value xs:string

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:ordinal-number-en" as="xs:string"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="num" as="xs:integer?"/>

  <xsl:sequence select="
   concat(xs:string($num),
         if (matches(xs:string($num),'[04-9]$|1[1-3]$')) then 'th'
         else if (ends-with(xs:string($num),'1')) then 'st'
         else if (ends-with(xs:string($num),'2')) then 'nd'
         else if (ends-with(xs:string($num),'3')) then 'rd'
         else '')
 "/>

</xsl:function>

Examples

XPath ExampleResults
functx:ordinal-number-en(1)
1st
functx:ordinal-number-en(12)
12th

History

Published OnLast UpdatedContributor(s)
2006-06-272007-08-08Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Datypic XSLT Services

Recommended Reading:

XQuery