title: How to transform a number (1,2,3, etc) into an ordinal number (1st, 2nd, 3rd, etc) using xslt
body: <p>Pretty simple question, how can I transform a number (1, 2, 3, etc) into a print friendly ordinal number (1st, 2nd, 3rd, etc) using xslt?</p>
  
  <p>Currently the following works for 1-20 but we may be seeing larger sets of entities getting ranked soon:</p>
  
  <pre><code>&lt;xsl:template name="FormatRanking"&gt;
      &lt;xsl:param name="Value"&gt;&lt;/xsl:param&gt;
  
      &lt;xsl:choose&gt;
          &lt;xsl:when test="$Value = '1'"&gt;
              &lt;xsl:value-of select="$Value"/&gt;st
          &lt;/xsl:when&gt;
          &lt;xsl:when test="$Value = '2'"&gt;
              &lt;xsl:value-of select="$Value"/&gt;nd
          &lt;/xsl:when&gt;
          &lt;xsl:when test="$Value = '3'"&gt;
              &lt;xsl:value-of select="$Value"/&gt;rd
          &lt;/xsl:when&gt;
          &lt;xsl:otherwise&gt;
              &lt;xsl:value-of select="$Value"/&gt;th
          &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
  
  &lt;/xsl:template&gt; 
  </code></pre>
  
  <p>The only way I would know how to do this would be to change the xsl:when's:</p>
  
  <pre><code>&lt;xsl:when test="$Value = '1'"&gt;
  &lt;xsl:when test="$Value = '2'"&gt;
  &lt;xsl:when test="$Value = '3'"&gt;
  </code></pre>
  
  <p>to (not even sure if this is correct):</p>
  
  <pre><code>&lt;xsl:when test="$Value = '1' or $Value = '21' or $Value = '31' ..."&gt;
  &lt;xsl:when test="$Value = '2' or $Value = '22' or $Value = '33' ..."&gt;
  &lt;xsl:when test="$Value = '3' or $Value = '22' or $Value = '33' ..."&gt;
  </code></pre>
  
  <p>I'd like to do something similar to this <a href="https://stackoverflow.com/questions/20156/ordinals-in-c#">Is there an easy way to create ordinals in C#?</a> but I'm not sure if it's possible in Xslt.</p>
  
  <p>At this point we only need an English solution.</p>