[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: date formatting function
followup:
On Sep 21, 2004, at 8:00 AM, Bruce D'Arcus wrote: I guess my question, given what I want to do, is how should I construct the function; as a single function -- let's call it bib:format-month-day -- that when called takes any YYYY/YYYY-MM/YYYY-MM-DD string and returns the formatted date (with parameter for whether months are rendered as full or abbreviated)? Here's what I've done: <xsl:function name="mods:format-month-day"> <xsl:param name="date"/> <xsl:variable name="date" select="$date" /> <xsl:choose> <xsl:when test="$date castable as xs:gYearMonth"> <xsl:variable name="month-day" select="xs:date(concat($date, '-01'))"/> <xsl:value-of select="format-date($month-day,'[MNn,*-3].')"/> </xsl:when> <xsl:when test="$date castable as xs:date"> <xsl:value-of select="format-date($date,'[MNn,*-3]. [D]')"/> </xsl:when> </xsl:choose> </xsl:function> <xsl:template match="date"> <h2>Dates:</h2> <p class="date"> <xsl:value-of select="mods:format-month-day(.)"/> </p> </xsl:template> 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? 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.). <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> <xsl:variable name="month-part-abbrev"> <xsl:choose> <xsl:when test="substring(.,6,2) = '01'">Jan</xsl:when> <xsl:when test="substring(.,6,2) = '02'">Feb</xsl:when> <xsl:when test="substring(.,6,2) = '03'">Mar</xsl:when> <xsl:when test="substring(.,6,2) = '04'">Apr</xsl:when> <xsl:when test="substring(.,6,2) = '05'">May</xsl:when> <xsl:when test="substring(.,6,2) = '06'">Jun</xsl:when> <xsl:when test="substring(.,6,2) = '07'">Jul</xsl:when> <xsl:when test="substring(.,6,2) = '08'">Aug</xsl:when> <xsl:when test="substring(.,6,2) = '09'">Sept</xsl:when> <xsl:when test="substring(.,6,2) = '10'">Oct</xsl:when> <xsl:when test="substring(.,6,2) = '11'">Nov</xsl:when> <xsl:when test="substring(.,6,2) = '12'">Dec</xsl:when> <xsl:otherwise></xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="day-part"> <xsl:choose> <xsl:when test="substring(.,9,1) = '0'"> <xsl:value-of select="substring(.,10,1)" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="substring(.,9,2)" /> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:if test="substring(.,6,2)"> <xsl:text> </xsl:text> <xsl:value-of select="$month-part"/> </xsl:if> <xsl:if test="substring(.,9,2)"> <xsl:text> </xsl:text> <xsl:value-of select="$day-part"/> </xsl:if> <xsl:if test="substring(.,6,2)"> <xsl:text></xsl:text> </xsl:if> <xsl:if test="../@dateLastAccessed"> <xsl:text>, </xsl:text> <xsl:value-of select="substring(.,1,4)"/> </xsl:if> </xsl:template> 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
|