[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: monthNumber from monthName

Subject: Re: monthNumber from monthName
From: James Cummings <james@xxxxxxxxxxxxxxxxx>
Date: Sat, 21 Jan 2012 19:19:26 +0000
Re:  monthNumber from monthName
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.