xsl-list
[Top] [All Lists]

RE: date formatting function

2004-09-25 14:30:54

Now, the bigger question: I need to later internationalize date 
formatting.  To that end, , where the root of the config file I am 
using to configure the formatting will hold an xml:lang attribute 
("cs:citationstyle/@lang") .

So:

a)  how to do this with the above approach?

format-date() accepts parameters to indicate the language you want to use,
which will affect, for example, the names used for months. However, it won't
affect whether the month comes before the day. That's because most countries
don't have a single standard way of displaying dates - if you look at
British newspapers, for example, each one does it differently.

Also, of course, the number of languages supported "out of the box" in a
given processor may not include all the languages you want. (Saxon basically
includes English, plus German more as an example of how to roll-your-own
than as a genuine part of the product).

b)  what are the advantages/disadvantages of the format-date approach 
above, versus the below (which is what I currently have)?  In 
theory, I 
guess the format-date approach is only useful if it already 
handles all 
of the internationalization of month formatting I'm doing manually 
below.  In either case, I need to change things to make more 
configurable with respect to order and punctuation (9 September 2000 
vs. September 9, 2000, etc.).

Your code only seems to be handling English. Obviously if you write your own
formatting you can make it more flexible but it's more code to write and
test.


<xsl:template match="mods:date | mods:dateIssued | 
mods:url/@dateLastAccessed">
   <xsl:variable name="month-part">
     <xsl:choose>
       <xsl:when test="substring(.,6,2) = '01'">January</xsl:when>
       <xsl:when test="substring(.,6,2) = '02'">February</xsl:when>
       <xsl:when test="substring(.,6,2) = '03'">March</xsl:when>
       <xsl:when test="substring(.,6,2) = '04'">April</xsl:when>
       <xsl:when test="substring(.,6,2) = '05'">May</xsl:when>
       <xsl:when test="substring(.,6,2) = '06'">June</xsl:when>
       <xsl:when test="substring(.,6,2) = '07'">July</xsl:when>
       <xsl:when test="substring(.,6,2) = '08'">August</xsl:when>
       <xsl:when test="substring(.,6,2) = '09'">September</xsl:when>
       <xsl:when test="substring(.,6,2) = '10'">October</xsl:when>
       <xsl:when test="substring(.,6,2) = '11'">November</xsl:when>
       <xsl:when test="substring(.,6,2) = '12'">December</xsl:when>
       <xsl:otherwise></xsl:otherwise>
     </xsl:choose>
   </xsl:variable>

A minor observation, you could write this much more consisely and
efficiently as

<xsl:variable name="month-part" 
              select="('January', 'February', 'March', ...)
                            [xs:int(substring(current(),6,2)]"/>

Michael Kay
http://www.saxonica.com/



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