[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Truncate input
Hi M Core,
Not sure if your question is about XSLT or XSL, since there's no mention of either in your post. If you want to format a number, you can use <xsl:decimal-format /> with format-number(value, format, name). The name in format-number refers to a name you predefined with <xsl:decimal-format />. Recall that <xsl:decimal-number /> is a top-level element. This means it must be right under your <xsl:stylesheet> instruction. You may also choose to format your number using the <xsl:number /> instruction or using string concatenation functions. If you need rounding, you can use the round(number) xpath function, but since you say that 3,45678 must become 3,45, I guess you need truncating. If you use round(), be aware that it only returns integers. -- using <xsl:number /> <xsl:number value="$yourinput" format="1.00" /> -- using round() <xsl:value-of select="round($yourinput * 100) div 100" /> -- using fixed() (will truncate) <xsl:value-of select="fixed($yourinput * 100) div 100" /> -- using string functions: <xsl:value-of select="concat ( substring-before( $yourinput, '.' ) , '.' , substring ( substring-after ( $yourinput, '.' ) , 1 , 2 ) )" /> You may have noticed that all these functions take input as a number that has a dot for decimal. You use a comma for decimal, so you may need to convert it. The easy thing to do that is using translate(string, tr, repl), I think: -- converting your number: <xsl:value-of select="translate ( $yournumber , ',' , '.' )" /> All the above snippets work with XSLT 1.0. But you can use them with 2.0 if you like or need it. There are many more possibilities. Cheers, Abel Braaksma http://abelleba.metacarpus.com m.core@xxxxxxxxxxxxxxxx wrote: Hi all,
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|