xsl-list
[Top] [All Lists]

Re: [xsl] monthNumber from monthName

2012-01-21 13:19:57
On Sat, Jan 21, 2012 at 19:13, Graydon <graydon(_at_)marost(_dot_)ca> wrote:
On Sat, Jan 21, 2012 at 06:43:57PM +0000, James Cummings scripsit:
[snip]
<xsl:function as="xs:string" name="d:getMonthName">
  <xsl:param name="monthName"/>
  <xsl:variable name="monthNames"
      
select="('january','february','march','april','may','june','july','august','september','october','november','december')"/>
  <xsl:sequence
      select="format-number(if (index-of($monthNames,$monthName) castable as 
xs:integer)
                          then index-of($monthNames,$monthName)
                          else 0,'00')"
  />
</xsl:function>

Ah, index-of() that was the thing I was vaguely remembering!  Many thanks!

This is insanely fragile unless you have strict checking to enforce case,
spelling, and language of month names.

Sure, as is the original. I'm regularising things from a very messy
text (but fairly consistent in the dates it has on page headings), so
when things don't match precise patterns I'm marking them and moving
on. It is a case of getting some automated markup in there to give
others a leg up in manually correcting the remaining ones.

If you're in a situation where you're going to get January, jan., jan, 
Janvier,
etc. you can take your original version and add tests, which has the advantage
of simplicity and ease of maintenance, or you can stuff all those tests into a
returnMonthName function, which has the advantage of abstraction and
compactness of expression.  But either way this sort of thing with
unconstrained string data month names is a pain.

Yeah, see what you mean.  But thanks for reminding me of index-of()!

-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>