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

date formatting function

Subject: date formatting function
From: Bruce D'Arcus <bdarcus@xxxxxxxxxxxxx>
Date: Mon, 20 Sep 2004 23:09:21 -0400
xsl date formatting
I'm about to integrate the configuration code that Wendell helped me out with last week, but I'd like to work out one detail related to date formatting before doing so.

My configuration file currently has code like this for specifying date formatting:


So here I would end up with (YYYY).

I'm still struggling with how to specify rendering for MM-DD or MM, and I think I'd like to make the decision based on the XSLT code that would actually render the dates. So, I'd like to go back to this suggestion from Mike Kay on how to handle dates that could either be YYYY, YYYY-MM, or YYYY-MM-DD.

If you do want to use the gYearMonth data type, you can write your own
function f:format-gYearMonth which converts the value to a date:

xs:date(concat($gYM, '-01'))

and then applies format-date() to it.

Basically, what I want to be able to do is to specify a config option something like:


This would apply, for example, to the issue date in a periodical, where a complete citation -- with both year at the beginning and month later are both drawn from the same mods:dateIssued content -- would look like:

Doe, J. (2000) Some Title, Some Periodical, v2, n3, January, pp. 23-34.

.... or:

Smith, S. (1999) Some Other Title, Different Periodical, v2, n3, March 15, pp. 23-34.

So I want the function to do the proper thing whether the date is in the form YYYY, YYYY-MM, or YYYY-MM-DD, where in the first case, nothing would be rendered, in the second I'd get only the month, and the third the month and day. I also want there to be a parameter that specifies either the full month or abbreviated.

The function would then get invoked, I assume, within the template that maps the config file to the source data something vaguely like:

<xsl:template match="cs:month-day">
  <xsl:param name="source"/>
  <xsl:apply-templates select="bib:format-month-day{mods:mods)">
    <xsl:with-param name="prefix" select="cs:prefix"/>
    <xsl:with-param name="suffix" select="cs:suffix"/>

The date in this case can be either of these:

I understand conceptually I need to have a choose option in which I am testing if the string is castable as xs:gYearMonth or xs:date, and that if the former I need to concat the -01 to it but to ignore the day in formatting, but I'm not really clear how I put it all together.

Here's where I'm at now:

<xsl:function name="bib:format-month-day" as="xs:integer">
  <xsl:param name="mods" as="element(mods:mods)" />
  <xsl:variable name="date" as="element(mods:dateIssued)"
    select="$mods/mods:originInfo/mods:dateIssued" />
<!-- need above to work for mods:part/mods:date also -->
    <xsl:when test="$date castable as xs:date">
    <xsl:when test="$date castable as xs:gYearMonth">
   <xsl:when test="$date castable as xs:gYear">

Or is this the wrong approach, and I need to do the testing and formatting from within the cs:month-day template, with this function only creating the proper date format?


Current Thread


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.
First Name
Last Name
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.