views:

290

answers:

4

Hello,

I'm stuck with a string conversion to xs:date. I would really appreciate any help and tips!

I have a string that represents date in the format of "01 Jan 00", which I need to convert to xs:date, so that I can manipulate it further.

Is there a function or something already there so that I can convert my so ever difficult string representation of date? Would I need to write a function from scratch to convert month in "MN" format into its number representation?

Please help! :) Thank you!

Daria

+1  A: 

The EXSLT library might be a good option: http://www.exslt.org/

lrussell
I had a look at them. There are some that convert month numbers into strings (like 01 into Jan or January), but not the all way arond. And that's exactly what I need.
DashaLuna
that's exactly what's done in the sample i provided in my answer below
Stefan De Boey
A: 

i think you'll need a function for this one. something similar is described here

Stefan De Boey
A: 

You could bind an extension function to convert the date string to the desired format. The exact mechanism will depend on your XSLT engine.

In .NET, we can take the following method:

public class DateConv
{
    public string AsXsDate( string date )
    {
        return DateTime.Parse(date).ToString("yyyy-MM-dd");
    }
}

XsltArgumentList args = new XsltArgumentList();
args.AddExtensionObject("urn:date-conv", new DateConv());

xslt.Transform( input, args output );

and use it in a stylesheet like this:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:date="urn:date-conv">

    <xsl:template match="bookstore">
        <xsl:value-of select="date:AsXsDate('01 Jan 00')"/>
    </xsl:template>

</xsl:stylesheet>
Lachlan Roche
A: 

I ended up writing a simple function that would determine between two date formats I have in my XML: "01 Jan 00" and a standard date-time string "2000-01-01"; and convert the non-standard to standard "YYYY-MM-DD".

Then I use EXSLT functions (http://www.exslt.org/date/index.html) to manipulate with dates further.

DashaLuna