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 |
XSLT Function Declaration| See XQuery definition. | | XSLT 2.0 Syntax: |
|---|
<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| XSLT Example | Results |
|---|
functx:ordinal-number-en(1)
|
1st
|
functx:ordinal-number-en(12)
|
12th
|
History |
|