xsl-list
[Top] [All Lists]

[xsl] monthNumber from monthName

2012-01-21 12:44:30
Hiya,

I have an xslt2 function which gets a lower-case month name as a
string and gives back its numerical equivalent. This is really
trivially done as:

<xsl:function name="jc:getMonth" as="xs:string"><xsl:param name="month"/>
    <xsl:choose>
        <xsl:when test="$month='january'">01</xsl:when>
        <xsl:when test="$month='february'">02</xsl:when>
        <xsl:when test="$month='march'">03</xsl:when>
        <xsl:when test="$month='april'">04</xsl:when>
        <xsl:when test="$month='may'">05</xsl:when>
        <xsl:when test="$month='june'">06</xsl:when>
        <xsl:when test="$month='july'">07</xsl:when>
        <xsl:when test="$month='august'">08</xsl:when>
        <xsl:when test="$month='september'">09</xsl:when>
        <xsl:when test="$month='october'">10</xsl:when>
        <xsl:when test="$month='november'">11</xsl:when>
        <xsl:when test="$month='november'">12</xsl:when>
        <xsl:otherwise>00</xsl:otherwise>
    </xsl:choose></xsl:function>


But in the back of my head, since the result is just a leading-zero
sequence number in a potential list of values.... I can't help
thinking there is a better way to do this.

If it was the month number I had and I wanted the month name, that'd
be easy as just grabbing that item from the sequence.

Suggestions?

-James

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>