What is the exact format of the "numeric" data as text?

I've found that "1000.00" will be treated as a number, 
but "1,000.00" will not.  However, number() always seems
to work, though I've not experimented with the effects of
mixing formats.  (Say, "1.000,00" in the XML, but "1,000.00"
in the JVM environment.)

I chalked the behavior up to a rationalization that runs like:
"Any inclusion of locale specific formatting shall result in
 the interpretation of the data as string, not number, unless
 explicitly converted."
Performance differences could come into play, I suppose.
If an 'implicit' conversion doesn't do a locale format check,
but the use of number() does, one would want the data to
be in the locale format of your JVM, and not use number()?

So if only one of XPath statements has to be qualified (use of
number()), are we seeing that one of your fields has 'extra'
formatting and the other doesn't?
Or, that the use of number() once in a test statement forces the
type checking/conversion for all other statements in that logical
portion of the test statement?
(I was expecting to hear that 
  number(//Number) < number(//HighestNumber)
would be needed for a 'working' test statement.)  


Everett


Dave wrote:
> 
> A couple little corrections:  The example makes more sense if you reverse
> the numeric values in the HighestNumber and Number nodes in the XML.  This
> way, the relevant xsl:when test doesn't get triggered when it should.  The
> other thing is that in my final example, I should have said <xsl:when
> test="//Number &lt; '2'"> rather than <xsl:when test="//Number<'2'">.
> 
> Dave
> 
> -----Original Message-----
> From: Dave [mailto:[EMAIL PROTECTED]]
> Sent: Monday, July 09, 2001 7:01 PM
> To: [EMAIL PROTECTED]
> Subject: RE: RelationalExpr doing alpha comparisons?
> 
> Gary,
> 
> Thanks for your response.  I'm using Xalan 2.1.0.  I'm invoking xalan
> through the JAXP interface in my Java code.  Here's the XML and XSLT I'm
> working with.  The XSLT is in the simplified stylesheet format:
> 
> XML:
> <PrimePowerFactorizations>
> <HighestNumber>100</HighestNumber>
> <Factorization>
> <Number>5</Number>
> </Factorization>
> </PrimePowerFactorizations>
> 
> XSLT:
> <html xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xsl:version="1.0">
> <head>
>         <title>Prime Power Factorizations</title>
> </head>
> <body>
>         <xsl:choose>
>                 <xsl:when test="//Factor">
>                         <p><xsl:value-of select="//Number"/> =
>                         <xsl:for-each select="//Factor">
>                                 <xsl:value-of select="Base"/>^<xsl:value-of 
>select="Exponent"/>
>                                 <xsl:if test="position()!=last()">*</xsl:if>
>                         </xsl:for-each></p>
>                 </xsl:when>
>                 <xsl:when test="//Number=0">
>                 </xsl:when>
>                 <xsl:when test="//Number=1">
>                         <p>Please enter a positive integer greater than one.</p>
>                 </xsl:when>
>                 <xsl:when test="//Number &gt; //HighestNumber">
>                         <p>This program is currently generating the numbers from
>                         <xsl:value-of select="//HighestNumber + 1"/> to
>                         <xsl:value-of select="//Number"/>.  Return to this
>                         page to see the highest number factored.</p>
>                 </xsl:when>
>         </xsl:choose>
> 
>         <p>The highest number factored by this program so far is <xsl:value-of
> select="//HighestNumber"/>.</p>
> 
>         <form method="POST"
> action="http://localhost:8080/primes/servlet/PrimeServlet";>
>                 <p>Enter a number you would like a prime power factorization for:
>                         <input type="text" name="Number" size="29"/>
>                         <input type="submit" value="Submit/Refresh" name="Submit"/>
>                 </p>
>         </form>
> </body>
> </html>
> 
> Again, the element that shows this issue is:
> <xsl:when test="//Number &gt; //HighestNumber">,
> whereas <xsl:when test="number(//Number) &gt; //HighestNumber">
> produces the correct result.
> 
> The same result can be produced when specifying a number as a string as in:
> <xsl:when test="//Number<'2'">
> 
> Please let me know what you figure out.
> Dave
> 
> -----Original Message-----
> From: Gary L Peskin [mailto:[EMAIL PROTECTED]]
> Sent: Monday, July 09, 2001 5:25 PM
> To: [EMAIL PROTECTED]
> Subject: Re: RelationalExpr doing alpha comparisons?
> 
> Dave --
> 
> I think that Michael Kay is correct on this.  It may be a bug in Xalan.
> What version of Xalan are you using and can you supply working XML and
> XSLT examples that will allow us to reproduce the problem?
> 
> Gary
> 
> Dave wrote:
> >
> > According to Michael Kay, a relational comparison doesn't compare strings,
> > but converts strings to numbers if possible and compares numeric values.
> >
> > When for example this element is evaluated by Xalan in my stylesheet:
> >
> > <xsl:when test="//Number &gt; //HighestNumber">
> >
> > where number and highest number contain numbers.
> >
> > It seems to compare the two nodes as strings, so for example, 5 is
> > considered greater than 100.  This seems contradictory to Kay's
> statements.
> >
> > It worked when I replaced the previous element with:
> >
> > <xsl:when test="number(//Number) &gt; //HighestNumber">.
> >
> > I'm just bothered that it didn't behave the way I thought it should.  Of
> > course I'm just a beginner at all this.  Is this a problem with Xalan,
> > Michael Kay, or me?
> >
> > Thanks,
> > Dave Kaplan

Reply via email to