Re: [xsl] Eliminating leading zeros

Subject: Re: [xsl] Eliminating leading zeros
From: Florent Georges <darkman_spam@xxxxxxxx>
Date: Mon, 21 Aug 2006 14:06:37 +0200 (CEST)
Mark Wilson wrote:


  I'll assume you use XSLT 1.0.  If not, there are other
solutions in XSLT 2.0.

> In order to sort item numbers with <xsl:sort> properly and
> prevent the sorted ouptput order of 1, 10, 100, 2, 3 and
> so on, I left pad the numbers with leading zeros: 001,002,
> 003, 010, 100 ....  so that I get 001, 002, 003, 010,
> 100 ... when I run a ascii sort

  You can instead use <xsl:sort data-type="number" .../>.

> [other elements are also sorted, so I cannot drop the
> ascii sort].

  I'm not sure to understand.  But assuming you have a good
reason to not using data-type="number" :

> I have been trying to figure out how to kill the leading
> zero after the sort

  After your example, it seems you'll always have exactly
three digits.  So you can use something like the following:

      <xsl:when test="starts-with(., '00')">
        <xsl:value-of select="substring(., 2)"/>
      <xsl:when test="starts-with(., '0')">
        <xsl:value-of select="substring(., 1)"/>
        <xsl:value-of select="."/>

  If not, you can use a recursive template that skip leading
zeros one by one.



 uncompressed/chunked Mon Aug 21 11:13:40 GMT 2006 
Dicouvrez un nouveau moyen de poser toutes vos questions quelque soit le sujet ! 
Yahoo! Questions/Riponses pour partager vos connaissances, vos opinions et vos expiriences. 

Current Thread