home contribute faq download

FunctX XSLT Functions

functx:mmddyyyy-to-date

Converts a string with format MMDDYYYY (with any delimiters) to a date

Google
Webdatypic.com

Description

The functx:mmddyyyy-to-date function converts $dateString into a valid xs:date value. The order of the digits in $dateString must be MMDDYYYY, but it can contain any (or no) delimiters between the digits.

Arguments and Return Type

NameTypeDescription
$dateString xs:string? the MMDDYYYY string
return value xs:date?

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:mmddyyyy-to-date" as="xs:date?"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="dateString" as="xs:string?"/>

  <xsl:sequence select="
   if (empty($dateString))
   then ()
   else if (not(matches($dateString,
                        '^\D*(\d{2})\D*(\d{2})\D*(\d{4})\D*$')))
   then error(xs:QName('functx:Invalid_Date_Format'))
   else xs:date(replace($dateString,
                        '^\D*(\d{2})\D*(\d{2})\D*(\d{4})\D*$',
                        '$3-$1-$2'))
 "/>

</xsl:function>

Examples

XPath ExampleResults
functx:mmddyyyy-to-date('12-15-2004')
2004-12-15
functx:mmddyyyy-to-date('12152004')
2004-12-15
functx:mmddyyyy-to-date('12/15/2004')
2004-12-15

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, https://www.datypic.com
Datypic XSLT Services

Recommended Reading:

XQuery