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| Name | Type | Description |
$num |
xs:integer? |
the number |
| return value |
xs:string |
XQuery Function Declaration| See XSLT definition. | | XQuery Syntax for July 2004 - January 2007 (1.0): |
|---|
declare namespace functx = "http://www.functx.com";
declare function functx:ordinal-number-en
( $num as xs:integer? ) as xs:string {
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 '')
} ; | | XQuery Syntax for May 2003: |
|---|
declare namespace functx = "http://www.functx.com"
define function ordinal-number-en
( $num as xs:integer? ) as xs:string {
fn:concat(xs:string($num),
if (fn:matches(xs:string($num),'[04-9]$|1[1-3]$')) then 'th'
else if (fn:ends-with(xs:string($num),'1')) then 'st'
else if (fn:ends-with(xs:string($num),'2')) then 'nd'
else if (fn:ends-with(xs:string($num),'3')) then 'rd'
else '')
} |
Examples| XQuery Example | Results |
|---|
functx:ordinal-number-en(1)
|
1st
|
functx:ordinal-number-en(12)
|
12th
|
History |
|