Re: [xslt] Problem with variables



My manager has pointed me to a lengthy discussion about format-number
that occurred on the xsl-list@lists.mulberrytech.com Mailing List last year.
Seems like this is an old argument I've stumbled into...
Essentially, the Java1.1 spec doesn't strictly define how the percent is to
be used -
it doesn't cover the position of the %, what to do if there are multiple %s,
etc.
It appears that MSXML and Saxon only handle the % if it appears on the right
of the number, libxml is happy for it to be on the left (but also works on
the right).
This definition is supposed to have changed / reworded over later versions
of Java.

Just done a bit of background reading into the XSLT2.0 Working Draft, and
it looks like they've really tightened down the definition.
It says the following (summarised a bit)

The picture string (the formatting pattern) may not contain more than one
percent (%) character.
The percent character (if present) must be to the right of the fractional
part of the picture string.
The percent character (if present) will be output on the right of the
formatted number.
It is a dynamic error if the picture string does not follow these rules
(i.e. would be an error for the % to be on the left).

So as everyone (libxml, MSXML, Saxon) accepts a % on the left, we would all
be wrong if we wanted to conform to XSLT2.0  :-))

Either way, I'm not sure it's worth doing anything with now until XSLT2.0
happens and libxslt gets upgraded.

Richard

----- Original Message -----
From: "Igor Zlatkovic" <igor@stud.fh-frankfurt.de>
To: <xslt@gnome.org>
Sent: Tuesday, May 21, 2002 3:21 PM
Subject: Re: [xslt] Problem with variables


> Here is what java 1.4.0 on Windows gives for the same number and the same
> format strings:
>
>   C:\Home\Igor\tmp>java NrTest
>   %25
>   %25.5
>   %25.480
>   %25.48
>
>   C:\Home\Igor\tmp>
>
> Well, given that the XSLT spec says that the java behaviour is
> authoritative, I would say that libxslt is conformant, MSXSL and Saxon are
> not.
>
> Oh, and thanks to you and Charlie for the info about '%'!
>
> Ciao
> Igor
>
> > According to the XSLT spec, the format-number function behaves as in
Java-
> >
http://java.sun.com/products/jdk/1.1/docs/api/java.text.DecimalFormat.html
> >
> > The per-cent (%) character multiplies the number by 100 then formats it,
> > The per-mille (?) character multiplies the number by 1000 then formats
it.
> >
> > Though it is odd you saying that msxml gives those results.
> > I'm testing libxslt using a testsuite comparing results from our own old
> > XSLT processor, Saxon and XT (These tests were built up a couple of
years
> > ago, so Saxon and XT might have changed since). All 3 processors
returned
> > the same results you found with MSXML.
> >
> > In fact, I've just tested Saxon 6.5.2, and that returns
> >
> >   %0
> >   %.3
> >   %.255
> >   %.2548
> >
> > Is there someone with Java handy who could verify which results are
> correct?
> > I strongly suspect libxslt is and everyone else is wrong...
> >
> > I'll get me a latest copy from CVS to see if it fixes my variable
problem.
> >
> > Thanks,
> > Richard
> >
> > ----- Original Message -----
> > From: "Igor Zlatkovic" <igor@stud.fh-frankfurt.de>
> > To: <xslt@gnome.org>
> > Sent: Tuesday, May 21, 2002 2:05 PM
> > Subject: Re: [xslt] Problem with variables
> >
> >
> > > Hello,
> > >
> > > strange, when I run it, I get
> > >
> > >   C:\Home\Igor\tmp>xsltproc b.xsl a.xml
> > >
> > >     %25
> > >     %25.5
> > >     %25.480
> > >     %25.48
> > >   C:\Home\Igor\tmp>
> > >
> > > But, I am using the current CVS version, not the 2.4.21 release.
Perhaps
> > the
> > > problem you are having is gone in the meantime.
> > >
> > > I would ask a question: I am puzzled about the meaning of the '%'
> > character
> > > in the format string. My book says that per-cent and per-mille
> characters
> > > are allowed, but does not say what they are for, neither it provides
an
> > > example. To make things more puzzling, MSXSL gives a different result:
> > >
> > >   C:\Home\Igor\tmp>msxsl -u 4.0 a.xml b.xsl
> > >
> > >     %
> > >     %.3
> > >     %.255
> > >     %.2548
> > >   C:\Home\Igor\tmp>
> > >
> > > Now, can someone tell me what the per-cent and per-mille characters in
> the
> > > format string mean? Which processor from the two above produced the
> > correct
> > > result?
> > >
> > > Ciao
> > > Igor
> > >
> > >
> > > > Can someone suggest whats going wrong here? I've had a look through
> the
> > > > libxslt code, but can't find anything obvious.
> > > >
> > > > (Using Igor's Win32 binaries libxml2.2-4-21, libxslt1.0.17 on
Win2000)
> > > >
> > > > a.xml:
> > > > <?xml version="1.0"?>
> > > > <AAA author="nicmila@idoox.com">
> > > >      <BBB>bbb</BBB>
> > > >      <CCC>ccc</CCC>
> > > > </AAA>
> > > >
> > > > b.xsl:
> > > > <?xml version="1.0"?>
> > > > <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
> > > > version="1.0">
> > > > <xsl:output method="text"/>
> > > > <xsl:variable name="G">0.2548</xsl:variable>
> > > > <xsl:template match="/">
> > > >   <xsl:text>
> > > >   </xsl:text>
> > > >   <xsl:value-of select="format-number($G,'%')"/>
> > > >   <xsl:text>
> > > >   </xsl:text>
> > > >   <xsl:value-of select="format-number($G,'%#.#')"/>
> > > >   <xsl:text>
> > > >   </xsl:text>
> > > >   <xsl:value-of select="format-number($G,'%#.000')"/>
> > > >   <xsl:text>
> > > >   </xsl:text>
> > > >   <xsl:value-of select="format-number($G,'%#.#####')"/>
> > > > </xsl:template>
> > > > </xsl:stylesheet>
> > > >
> > > > C:\libxml\libxslt-1.0.17.win32\util>xsltproc b.xsl a.xml
> > > > xsltproc c.xsl a.xml
> > > > runtime error: file c.xsl line 4 element variable
> > > > Global variable G already defined
> > > > %25%25.5%25.480%25.48
> > > >
> > > > There appears to be two problems here:
> > > > 1) The runtime error stating that variable "G" is already defined.
> > > > 2) I'd expect the formatted numbers to each appear on new lines (but
> > this
> > > > could quite easily go down to a gap in my understanding of
> <xsl:text/>)
> > > >
> > > > Any ideas?
>
>
> _______________________________________________
> xslt mailing list, project page http://xmlsoft.org/XSLT/
> xslt@gnome.org
> http://mail.gnome.org/mailman/listinfo/xslt


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com




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