|
Subject: Re: [xsl] monthNumber from monthName From: James Cummings <james@xxxxxxxxxxxxxxxxx> Date: Sat, 21 Jan 2012 19:19:26 +0000 |
On Sat, Jan 21, 2012 at 19:13, Graydon <graydon@xxxxxxxxx> wrote:
> On Sat, Jan 21, 2012 at 06:43:57PM +0000, James Cummings scripsit:
> [snip]
> <xsl:function as="xs:string" name="d:getMonthName">
> B <xsl:param name="monthName"/>
> B <xsl:variable name="monthNames"
> B B B
select="('january','february','march','april','may','june','july','august','s
eptember','october','november','december')"/>
> B <xsl:sequence
> B B B select="format-number(if (index-of($monthNames,$monthName) castable
as xs:integer)
> B B B B B B B B B B B B B then
index-of($monthNames,$monthName)
> B B B B B B B B B B B B B else 0,'00')"
> B />
> </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. B 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
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] monthNumber from monthNam, Graydon | Thread | Re: [xsl] monthNumber from monthNam, Graydon |
| Re: [xsl] monthNumber from monthNam, Graydon | Date | Re: [xsl] XSLT translated into C/C+, Michael Kay |
| Month |