Subject: Re: [xsl] format string with leading zeros From: henry human <henry_human@xxxxxxxx> Date: Thu, 5 Jan 2012 08:56:56 +0000 (GMT) |
thanks, but It is a change in the specification. Here is the sample: Sample Input :12,345 output: After comma ever 8 digits And whole string should be 14 digits: Sample out: 00012,34500000 Best regards ----- Urspr|ngliche Message ----- Von: G. Ken Holman <gkholman@xxxxxxxxxxxxxxxxxxxx> An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx; "xsl-list@xxxxxxxxxxxxxxxxxxxxxx" <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Cc: Gesendet: 16:56 Mittwoch, 4.Januar 2012 Betreff: Re: [xsl] format string with leading zeros At 2012-01-04 15:46 +0000, henry human wrote: > Hi I have following scenario, the itemCode field must be 14 digits lang. I try to ignore the last two decimals of the itemCode field if the itemCode is more than 14 digits long (16 digits). And if the itemCode has less than 14, fill field with leading zeros so that the itemCodeCode is still 14 digits long. Input Example(1): itemCode : 0.0123456789 output itemCode: 000.0123456789 Input Example(2): itemCode : 0.01111123456789 output itemCode: 0.011111234567 Thanks you Does the following help? It uses two steps to first trim and then pad the input to produce the output. . . . . . . . . . Ken ~/t/ftemp $ xslt2 henry.xsl henry.xsl <?xml version="1.0" encoding="UTF-8"?> 000.0123456789 0.011111234567 ~/t/ftemp $ cat henry.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="urn:X-Henry" exclude-result-prefixes="my" version="2.0"> <xsl:template match="/"> <xsl:text>
</xsl:text> <xsl:value-of select="my:trim('0.0123456789')"/> <xsl:text>
</xsl:text> <xsl:value-of select="my:trim('0.01111123456789')"/> <xsl:text>
</xsl:text> </xsl:template> <xsl:function name="my:trim"> <xsl:param name="str"/> <xsl:variable name="temp" select="concat('00000000000000',substring($str,1,14))"/> <xsl:sequence select="substring($temp,string-length($temp)-13)"/> </xsl:function> </xsl:stylesheet> ~/t/ftemp $ -- Contact us for world-wide XML consulting and instructor-led training Free 5-hour video lecture: XSLT/XPath 1.0 & 2.0 http://ude.my/uoui9h Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Google+ profile: https://plus.google.com/116832879756988317389/about Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] format string with leadin, G. Ken Holman | Thread | Re: [xsl] Is there an OR for XSL IF, Wendell Piez |
[xsl] Quick references [Was: Is the, Tony Graham | Date | [xsl] what's the best way to do thi, Roelof Wobben |
Month |