Re: [xslt] format-number inconsistent with java results



On Fri, Jun 14, 2002 at 02:16:48PM -0700, Ken Neighbors wrote:

  Hi Ken,

> I was trying to format a fractional number *without* a leading zero,
> but was unable to.  For example, format-number(0,'.0') returns "0.0"
> instead of ".0" as I would expect.
> 
> I fixed this and while I was at it I checked some other cases at
>   http://www.zvon.org:9001/saxon/cgi-bin/XLab/XML/addressbook.html?stylesheetFile=XSLT/format-number.xslt
> and compared the results with libxslt (cvs snapshot as of 13 June 2002).
> Here are the cases I found that differed with regard to leading zeros
> and trailing decimal points:
> 
>   function call             : libxslt : zvon(java I assume)
> 
>   format-number(-1.0, '.' ) :      -1 : -1.
>   format-number(-0.5, '.' ) :      -1 : -0. (but I think this should be -1.)
>   format-number( 0.0, '.' ) :      0  : 0.
>   format-number( 0.5, '.' ) :      1  : 0. (but I think this should be 1.)
>   format-number( 1.0, '.' ) :      1  : 1.
> 
>   format-number(-1.0,'#.' ) :      -1 : -1.
>   format-number(-0.5,'#.' ) :      -1 : -0. (but I think this should be -1.)
>   format-number( 0.0,'#.' ) :      0  : 0.
>   format-number( 0.5,'#.' ) :      1  : 0. (but I think this should be 1.)
>   format-number( 1.0,'#.' ) :      1  : 1.
> 
>   format-number(-1.0,'0.' ) :      -1 : -1.
>   format-number(-0.5,'0.' ) :      -1 : -0. (but I think this should be -1.)
>   format-number( 0.0,'0.' ) :      0  : 0.
>   format-number( 0.5,'0.' ) :      1  : 0. (but I think this should be 1.)
>   format-number( 1.0,'0.' ) :      1  : 1.
> 
>   format-number(-1.0, '.#') :    -1   : -1.0
>   format-number(-0.5, '.#') :    -0.5 : -.5
>   format-number( 0.0, '.#') :    0    : .0
>   format-number( 0.5, '.#') :    0.5  : .5
>   format-number( 1.0, '.#') :    1    : 1.0
> 
>   format-number(-1.0, '.##') :   -1   : -1.0
>   format-number(-0.5, '.##') :   -0.5 : -.5
>   format-number( 0.0, '.##') :   0    : .0
>   format-number( 0.5, '.##') :   0.5  : .5
>   format-number( 1.0, '.##') :   1    : 1.0
> 
>   format-number(-0.5, '.0') :    -0.5 : -.5
>   format-number( 0.0, '.0') :    0.0  : .0
>   format-number( 0.5, '.0') :    0.5  : .5
> 
>   format-number(-0.5,'#.0') :    -0.5 : -.5
>   format-number( 0.0,'#.0') :    0.0  : .0
>   format-number( 0.5,'#.0') :    0.5  : .5

  I must admit, the couple of time I tried to read the Java spec associated
to number formatting I just ended up with a big headache, and I was really
pleased to delegate this part to William and Bjorn. This mean, you're 
probably right, I just can't tell !

> Attached are fixes to numbers.c and numbersInternals.h to produce the
> above results consistent with java (except for the cases I noted
> above).  Also included are additional test cases for
> tests/numbers/format-number.xsl.

  Excellent !

> I assume the java interpretation of these patterns is a reasonable way
> to go (except for the round-off discrepancy).  If not, let me know and
> I'll try to update my patch for the desired behavior.
> 
> Also let me know if I should submit these bug reports/patches another
> way--this is my first patch to libxslt and I think I followed the
> guidelines at http://xmlsoft.org/XSLT/bugs.html.

  Well, you found a problem, exposed it, provide a patch to fix it and
added associated regression tests, honnestly it's hard to find a better
way to help the project. As I said I can't tell if the output is "the
Right One" but I applied your patch since 1/ it seems to improve the
conformance level 2/ it includes regression test so if there is disagreement
we can just change the parts identified as being in error.

  Thanks a lot for your contribution, as said I applied and commited it !

Daniel

P.S.: you may want to subscribe to the list in case there is on-going
      discussion on the patch, it's relatively low traffic.

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard@redhat.com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]