2

How can I convert a date contained in a string into a date value with XPath?

I got the string by formatting a date value with fn:format-date, and now I want the date value from the formatted string.

Thank you,

gioele
  • 9,748
  • 5
  • 55
  • 80
trin86
  • 157
  • 2
  • 2
  • 8

1 Answers1

1

You can use EXSLT's date:date(string). It is implemented in most XSLT processors but also as a pure XSLT function.

Documentation: http://www.exslt.org/date/functions/date/index.html.

gioele
  • 9,748
  • 5
  • 55
  • 80
  • Thanks for the reply but it says in your link that the date/time string specified as an argument must be a string in the format defined as the lexical representation of either xs:dateTime in or xs:date. If the argument is not in either of these formats, date:date returns an empty string (''). But my string date format is DD/MM/YYYY . Does it make a problem ? If it does how can i change the accepted date format? – trin86 Feb 20 '12 at 11:32
  • There is `date:parse-date()` but it unimplemented in most processors. Your best bet is to tokenize the date yourself, put it back in the required format and then then use `date:date()` to get a xs:date object. See http://www.saxonica.com/documentation/extensions/functions/analyze-string.xml for a starting point on how to read pieces of date from a date string. – gioele Feb 20 '12 at 13:33