Subject: Re: [xsl] Is there a way to skip non-numerical data while formatting numbers? From: "Rashmi Rubdi" <rashmi.sub@xxxxxxxxx> Date: Tue, 17 Apr 2007 23:56:02 -0400 |
Thanks a lot for taking the time to try the number formatting in the same environment as I'm using. Sorry it took me this long to try it.
The mistake was mine, it's in my 2nd post on this thread : I didn't enclose the name of the decimal format in single quotes and that's what threw the exception -- Sorry the single quotes were a little hard to notice.
Also I made a typo mistake ##,##,.00 by putting the comma before the dot while posting the message. The format used (which is ##,###.00 was correct).
I finally decided to start using the XSLT Reference books I have, in the XSLT 2.0 by Michael Kay , shows a very useful format that I didn't find online at w3schools. And that it, the format also includes the currency symbol within as in : $##,###.00 , which is very convenient as it eliminates the need to prefix the output explicitly with a $.
With Xalan-J 2.7.0 it works fine.
Here is a test case.
Input XML is: <x> <price>100</price> <shipping>a</shipping> </x>
XSLT stylesheet is: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:decimal-format name="currency_format" NaN="" />
<xsl:template match="/x"> <xsl:value-of select="format-number(number(price), '##,##.00', 'currency_format')"/> ?<xsl:value-of select="format-number(number(shipping), '##,##.00', 'currency_format')"/>? (<xsl:value-of select="format-number(number(price+shipping), '##,##.00', 'currency_format')"/>) </xsl:template>
</xsl:stylesheet>
The output produced is: 1,00.00 ?? ()
The error you are getting is due to the fact, that '##,##,.00' is not the right format pattern. It should be, '##,##.00'
On 4/16/07, Rashmi Rubdi <rashmi.sub@xxxxxxxxx> wrote: > David, > > Thank you for the very useful tip. > > I tried the following (with some variations): > > <xsl:decimal-format name="currency_format" NaN=""/> > > <xsl:value-of select="format-number(number(price), > '##,##,.00',currency_format)"/> > > but the above is throwing a > SystemId Unknown; Line #58; Column #102; java.lang.RuntimeException: > ElemTemplateElement error: Malformed format string: ##,##,,00 on > Xalan XSLT 1.0 parser. > > I wasn't getting the above error before (when I didn't use the > decimal-format option inside the format-number function. > > It could be possible that this is a bug in Xalan according to this post: > http://mail-archives.apache.org/mod_mbox/xml-xalan-cvs/200102.mbox/%3C20010215213041.1778.qmail@xxxxxxxxxx%3E > > I will check with the Xalan mailing list if it is their bug. > > -Rashmi > On 4/15/07, David Carlisle <davidc@xxxxxxxxx> wrote: > > > > you can specify the string used for Not a Number using > > xsl:decimal-format, it defaults to 'NaN' but you can make it '' > > > > David
-- Regards, Mukul Gandhi
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Is there a way to skip no, Mukul Gandhi | Thread | [xsl] Re: xsl-list Digest 14 Apr 20, Mike Wilt |
Re: [xsl] Finding distinct nodes us, Dimitre Novatchev | Date | Re: [xsl] Condition Based Count of , J. S. Rawat |
Month |