3

Hopefully someone else out there uses Altova Mapforce for this.

Using XSLT to convert one xml to another, in the source XML they have the dates as M/D/YYYY, i need to convert them to the standard datetime format used by.. well, everything.

So, i'm playing with using the tokenize function of XSLT to split on / to get my parts, now, i want to take part 1 and say it's the day, but not sure how to assign results of the tokenize expression to variables using MapForce.

Anyone else do this? or rather, what's the best way to convert a string date to a datetime?

Thanks for the ideas

EDIT. my input is a string '1/31/2012' and my output needs to be xs:dateTime (or xs:date, assuming that xs:date can be easily converted to dateTime)

I've got a method setup to concatenate strings together and convert them to YYYY-MM-DD format, but it still reports that this is invalid for dateTime (Cast Failed, invalid lexical value 2012-1-31)

Perhaps YYYY-MM-DD is not the valid format for dateTime?

Beta033
  • 1,975
  • 9
  • 35
  • 48

3 Answers3

1

Ended up creating a component to do this. my particular problem was that '2012-1-31' cannot be formatted to a date or dateTime, however 2012-01-31 can. so this became as simple as formatting the number and padding with characters before trying to cast as a date.

Beta033
  • 1,975
  • 9
  • 35
  • 48
  • `2012-01-31` is a valid xs:date, but not a valid xs:dateTime. If you need a dateTime, just add `T00:00:00` to it. (`2012-01-31T00:00:00`) – Daniel Haley Jun 25 '12 at 16:00
0

This example uses EXSLT (since I don't have access to XSLT 2.0), but you get the idea.

<xsl:variable name='date_parts' select='str:split(root/date, "/")' />
<xsl:value-of select='concat($date_parts[3],$date_parts[1],$date_parts[2])' />

You can test it at this playgorund session

Mitya
  • 33,629
  • 9
  • 60
  • 107
0

You can use xs:datetime / format-dateTime from the libraries