Getting Names for Days and Months

Problem

You want to convert from numerical values for days and months to symbolic values.

Solution

If internationalization is not important to your application, then the following simple code will do:

 <xsl:template name="date:get-day-of-the-week-name"> <xsl:param name="day-of-the-week"/> <xsl:choose> <xsl:when test="$day-of-the-week = 0">Sunday</xsl:when> <xsl:when test="$day-of-the-week = 1">Monday</xsl:when> <xsl:when test="$day-of-the-week = 2">Tuesday</xsl:when> <xsl:when test="$day-of-the-week = 3">Wednesday</xsl:when> <xsl:when test="$day-of-the-week = 4">Thursday</xsl:when> <xsl:when test="$day-of-the-week = 5">Friday</xsl:when> <xsl:when test="$day-of-the-week = 6">Saturday</xsl:when> <xsl:otherwise> error: <xsl:value-of select="$day-of-the-week"/> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="date:get-day-of-the-week-abbreviation"> <xsl:param name="day-of-the-week"/> <xsl:choose> <xsl:when test="$day-of-the-week = 0">Sun</xsl:when> <xsl:when test="$day-of-the-week = 1">Mon</xsl:when> <xsl:when test="$day-of-the-week = 2">Tue</xsl:when> <xsl:when test="$day-of-the-week = 3">Wed</xsl:when> <xsl:when test="$day-of-the-week = 4">Thu</xsl:when> <xsl:when test="$day-of-the-week = 5">Fri</xsl:when> <xsl:when test="$day-of-the-week = 6">Sat</xsl:when> <xsl:otherwise> error: <xsl:value-of select="$day-of-the-week"/> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="date:get-month-name"> <xsl:param name="month"/> ...

Get XSLT Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.