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 TypeName | Type | Description |
$num |
xs:integer? |
the number |
return value |
xs:string |
XQuery Function DeclarationSee XSLT definition. | 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 '')
} ; |
ExamplesXQuery Example | Results |
---|
functx:ordinal-number-en(1) |
1st |
functx:ordinal-number-en(12) |
12th |
History |
Recommended Reading:
|