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

Re: Unexpected Results with format-number()

Subject: Re: Unexpected Results with format-number()
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 15 Aug 2007 22:00:52 -0400
Re:  Unexpected Results with format-number()
First I note your formatting pattern should be '$#,.00' and not "$,.00".

Next, converting your stylesheet to XSLT 1.0 and using the above pattern gets you what you need, so I suspect this is a simple oversight in Saxon that will probably be fixed soon given its creator follows this list.

I hope this helps.

. . . . . . . . . . . Ken

At 2007-08-15 18:20 -0500, Angela Williams wrote:

I've just noticed a difference in the way small numbers are formatting.
When I wrote this a few weeks ago, small numbers formatted with the
correct precision.  Now it seems the format string is being ignored.

I believe I was using Saxon 8.8 when I first wrote the code. I updated
to Saxon 8.9.0.4 yesterday, but that may just be a coincidence.

What am I missing?

Sample XML:
<?xml version="1.0" encoding="UTF-8"?>
<values>
   <amt>-0.003000</amt>
   <amt>-0.001500</amt>
   <amt>0.003000</amt>
   <amt>0.00</amt>
   <amt>0</amt>
</values>

Expected output:
amt: [-0.003]  formatted-value: [-$0.00]
amt: [-0.0015] formatted-value: [-$0.00]
amt: [0.003]   formatted-value: [$0.00]
amt: [0]       formatted-value: [$0.00]
amt: [0]       formatted-value: [$0.00]

Actual output:
amt: [-0.003]  formatted-value: [-$0]
amt: [-0.0015] formatted-value: [-$0]
amt: [0.003]   formatted-value: [$0]
amt: [0]       formatted-value: [$0]
amt: [0]       formatted-value: [$0]

Stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fk="http://www.the401kcompany.com/functions"
  version="2.0">

  <xsl:template match="/values">
    <html>
      <body>
        <xsl:apply-templates select="amt" />
      </body>
    </html>
  </xsl:template>

  <xsl:template match="amt">
    <p>
      <xsl:value-of select="fk:nbr-format(.)" />
    </p>
  </xsl:template>

  <xsl:function name="fk:nbr-format">
    <xsl:param name="amt" as="xs:double" />
    <xsl:variable name="picture" select="'$,.00'" />
      amt:              [<xsl:value-of select="$amt" />]
      formatted-value:  [<xsl:value-of
select="format-number(number($amt), string($picture))" />]
  </xsl:function>
</xsl:stylesheet>


--
Upcoming public training: XSLT/XSL-FO Sep 10, UBL/code lists Oct 1
World-wide corporate, govt. & user group XML, XSL and UBL training
RSS feeds:     publicly-available developer resources and training
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Jul'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

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.