[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Eliminating leading zeros

Subject: Re: Eliminating leading zeros
From: Florent Georges <darkman_spam@xxxxxxxx>
Date: Mon, 21 Aug 2006 14:06:37 +0200 (CEST)
xslt leading zero
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 
	
		
___________________________________________________________________________ 
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. 
http://fr.answers.yahoo.com 

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.