xsl-list
[Top] [All Lists]

Re: [xsl] Eliminating leading zeros

2006-08-21 05:06:55
Mark Wilson wrote:

  Hi

  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:choose>
      <xsl:when test="starts-with(., '00')">
        <xsl:value-of select="substring(., 2)"/>
      </xsl:when>
      <xsl:when test="starts-with(., '0')">
        <xsl:value-of select="substring(., 1)"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="."/>
      </xsl:otherwise>
    </xsl:choose>

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

  Regards,

--drkm




















        
 p5.vert.ukl.yahoo.com uncompressed/chunked Mon Aug 21 11:13:40 GMT 2006 
        
                
___________________________________________________________________________ 
Découvrez un nouveau moyen de poser toutes vos questions quelque soit le sujet 
! 
Yahoo! Questions/Réponses pour partager vos connaissances, vos opinions et vos 
expériences. 
http://fr.answers.yahoo.com 


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>