date / variable problem

Questions about XML that are not covered by the other forums should go here.
wilkinsr
Posts: 6
Joined: Sun Apr 30, 2006 7:37 pm

date / variable problem

Post by wilkinsr »

I use this code to retrieve the month and year from a website, and want to retrieve the month name and year. The year works fine, but I get results like, MAY05 or JUNE06 for the month (month name and index). Any idea why this is happening? Any idea how I can get this thing to work.


<xsl:variable name="date" select="document('http://xobjex.com/cgi-bin/date.pl')/date"/>
<xsl:text>LAST REVISED: </xsl:text>
<xsl:variable name="month" select="$date/utc/month"/>
<xsl:choose>
<xsl:when test="$month = 01">January</xsl:when>
<xsl:when test="$month = 02">February</xsl:when>
<xsl:when test="$month = 03">March</xsl:when>
<xsl:when test="$month = 04">April</xsl:when>
<xsl:when test="$month = 05">May</xsl:when>
<xsl:when test="$month = 06">June</xsl:when>
<xsl:when test="$month = 07">July</xsl:when>
<xsl:when test="$month = 08">August</xsl:when>
<xsl:when test="$month = 09">September</xsl:when>
<xsl:when test="$month = 10">October</xsl:when>
<xsl:when test="$month = 11">November</xsl:when>
<xsl:when test="$month = 12">December</xsl:when>
<xsl:otherwise>INVALID MONTH</xsl:otherwise>
</xsl:choose>
wilkinsr
Posts: 6
Joined: Sun Apr 30, 2006 7:37 pm

Re: date / variable problem

Post by wilkinsr »

wilkinsr wrote:I use this code to get the month and year from a website, and want to retrieve the month name and year. The year works fine, but I get results like, MAY05 or JUNE06 for the month (month name and index). Any idea why this is happening or how I can get this thing to work.


<xsl:variable name="date" select="document('http://xobjex.com/cgi-bin/date.pl')/date"/>
<xsl:text>LAST REVISED: </xsl:text>
<xsl:variable name="month" select="$date/utc/month"/>
<xsl:choose>
<xsl:when test="$month = 01">January</xsl:when>
<xsl:when test="$month = 02">February</xsl:when>
<xsl:when test="$month = 03">March</xsl:when>
<xsl:when test="$month = 04">April</xsl:when>
<xsl:when test="$month = 05">May</xsl:when>
<xsl:when test="$month = 06">June</xsl:when>
<xsl:when test="$month = 07">July</xsl:when>
<xsl:when test="$month = 08">August</xsl:when>
<xsl:when test="$month = 09">September</xsl:when>
<xsl:when test="$month = 10">October</xsl:when>
<xsl:when test="$month = 11">November</xsl:when>
<xsl:when test="$month = 12">December</xsl:when>
<xsl:otherwise>INVALID MONTH</xsl:otherwise>
</xsl:choose>

<xsl:value-of select="$month"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$date/utc/year"/>
Radu
Posts: 9055
Joined: Fri Jul 09, 2004 5:18 pm

Post by Radu »

Hi,

The problem is that you have a

Code: Select all

<xsl:value-of select="$month"/>
in the stylesheet fragment which outputs the numeric version of the month. Remove that line and everything seems to work OK.

Regards,
Radu.
wilkinsr
Posts: 6
Joined: Sun Apr 30, 2006 7:37 pm

Post by wilkinsr »

Thanks, Radu. That did the trick.
Post Reply