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: 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Eliminating leading zeros, Michael Kay | Thread | [xsl] RE : Re: [xsl] Eliminating le, Florent Georges |
Re: [xsl] Eliminating leading zeros, David Carlisle | Date | Re: [xsl] Eliminating leading zeros, Mark Wilson |
Month |