RE: [xsl] Peculiar Problem in .xsl file

Subject: RE: [xsl] Peculiar Problem in .xsl file
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Fri, 6 Dec 2002 10:04:21 -0000
I think your code is correct and your processor is buggy. Which XSLT
processor are you using?

When a string is compared to a number, they should be compared as
numbers, not as strings.

Try doing 
<xsl:variable name='month' select='number(substring ($date, 5, 2))'/>

to force a numeric comparison.

[Note, this kind of problem is one of the reasons that many people are
so keen to add stronger typing to the language].

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Chandra -
> Sent: 06 December 2002 05:50
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Peculiar Problem in .xsl file
> 
> 
> Hi Guys,
>   I am trying to print out a html file with a date in words, 
> given date in a 
> xml file in number format
> XSL file:
> <xsl:variable name='month' select='substring ($date, 5, 2)'/>
> 	<xsl:choose>
> 		<xsl:when test='$month=01'>
> 			<xsl:text>January </xsl:text>
> 		</xsl:when>
> 		<xsl:when test='$month=02'>
> 			<xsl:text>February </xsl:text>
> 		</xsl:when>
> 		<xsl:when test='$month=03'>
> 			<xsl:text>March </xsl:text>
> 		</xsl:when>
> 		<xsl:when test='$month=04'>
> 			<xsl:text>April </xsl:text>
> 		</xsl:when>
> 		<xsl:when test='$month=05'>
> 			<xsl:text>May </xsl:text>
> 		</xsl:when>
> 		<xsl:when test='$month=06'>
> 			<xsl:text>June </xsl:text>
> 		</xsl:when>
> 		<xsl:when test='$month=07'>
> 			<xsl:text>July </xsl:text>
> 		</xsl:when>
> 		<xsl:when test='$month=08'>
> 			<xsl:text>August </xsl:text>
> 		</xsl:when>
> 		<xsl:when test='$month=09'>
> 			<xsl:text>September </xsl:text>
> 		</xsl:when>
> 		<xsl:when test='$month=10'>
> 			<xsl:text>October </xsl:text>
> 		</xsl:when>
> 		<xsl:when test='$month=11'>
> 			<xsl:text>November </xsl:text>
> 		</xsl:when>
> 		<xsl:when test='$month=12'>
> 			<xsl:text>December </xsl:text>
> 		</xsl:when>
> 	</xsl:choose>
> 
> When valuepassed into the date variable is 20020516, I don't 
> get a month. 
> Infact if the month is from 01 to 09, I dont get a month in 
> words. If the 
> month is 10 to 12, I get a month displayed. Very very 
> peculiar. I am unable 
> to find the solution. I tried and printed out the value of the month 
> variable. It seems to take the 2 digits correctly. However it 
> doesn't go 
> into the appropraite month code when the month starts with 
> 0!! For example, 
> if the month is 05, it doesnt go into this part of the code: 
> <xsl:when test='$month=05'> <xsl:text>May </xsl:text> 
> </xsl:when> If the month were 10, 11 or 12, the code works 
> fine. Can anyone guess what the problem is... Thanks in 
> advance, Chandra
> 
> 
> 
> _________________________________________________________________
> The new MSN 8: advanced junk mail protection and 2 months FREE* 
> http://join.msn.com/?page=features/junkmail
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread