Search code examples
xmlxpathxpath-1.0

XPath 1.0: Converting Timestrings


How can I convert Strings in this format dd/mm/yyyy hh:mm:ss into this format yyyy/mm/dd hh:mm:ss using XPAth 1.0?


Solution

  • Unfortunately, XPath 1.0 does not even support regular expression. Hence, I think you are stuck with using substring functions.

    The following is not very elegeant, but it should work ($date being your input string). It split the different parts and reconstruct the string afterwards.

    concat(
      substring-after(substring-after(substring-before($date, ' '), '/'), '/'),
      '/',
      substring-before(substring-after(substring-before($date, ' '), '/'), '/'),
      '/',
      substring-before(substring-before($date, ' '), '/'),
      ' ',
      substring-after($date, ' ')
    )