[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: date formatting function
On Sep 25, 2004, at 5:30 PM, Michael Kay wrote:
A minor observation, you could write this much more consisely and efficiently as I've reworked the stylesheets. I now have two modes -- month and day -- with the former template looking like this: <xsl:template match="mods:date | mods:dateIssued" mode="month"> <xsl:param name="source"/> <xsl:param name="prefix"/> <xsl:param name="suffix"/> <xsl:variable name="month-part" select="('January','February','March','April','May','June','July','Augus t', 'September','October','November','December')[xs: int(substring(current(),6,2)]"/> <xsl:variable name="month-part-abbrev" select="('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug', 'Sept','Oct','Nov','Dec')[xs:int(substring(current(),6,2)]"/> <xsl:value-of select="$prefix"/> <xsl:value-of select="$month-part"/> <xsl:value-of select="$suffix"/> </xsl:template> I'm now back to my original problem, which is that I don't know upfront the form of my dates, so this gives me this error when I have a date like YYYY: Cannot convert zero-length string to an integer So how can I rework this all to properly handle: <date>2000</date> <date>2000-11</date> <date>2000-11-30</date> <date>Summer</date> My config file now looks in part like: <reftype name="article"> <creator> <names/> </creator> <date> <year> <prefix> (</prefix> <suffix>) </suffix> </year> </date> <title> <suffix>, </suffix> </title> <container> <title font-style="italic"> <suffix>, </suffix> </title> <origin/> <part-details> <date> <month/> <day> <prefix> </prefix> </day> </date> <volume/> <issue> <prefix>(</prefix> <suffix>)</suffix> </issue> <pages/> </part-details> </container> </reftype> .... and the templates that deal with it: <xsl:template match="cs:date"> <xsl:param name="source"/> <xsl:apply-templates> <xsl:with-param name="source" select="$source"/> </xsl:apply-templates> </xsl:template> <xsl:template match="cs:year"> <xsl:param name="source"/> <xsl:param name="prefix"/> <xsl:param name="suffix"/> <xsl:apply-templates select="$source/mods:year"> <xsl:with-param name="prefix" select="cs:prefix"/> <xsl:with-param name="suffix" select="cs:suffix"/> <xsl:with-param name="source" select="$source"/> </xsl:apply-templates> </xsl:template> <xsl:template match="cs:month"> <xsl:param name="source"/> <xsl:param name="prefix"/> <xsl:param name="suffix"/> <xsl:apply-templates select="$source/mods:originInfo/mods:dateIssued | $source/mods:part/mods:date" mode="month"> <xsl:with-param name="prefix" select="cs:prefix"/> <xsl:with-param name="suffix" select="cs:suffix"/> <xsl:with-param name="source" select="$source"/> </xsl:apply-templates> </xsl:template> I'm not even sure the separate modes is a good idea, but I see no alternative. Bruce
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|