[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Comparing two dates when one is potentially malformed
Hi all -- I'm wondering about best practices when dealing with potentially malformed dates. I confess that I haven't worked with dates (xs:date, xs:time, xs:dateTime) very much and so I'm not sure if I'm thinking about things correctly. I have the following input: <test> <field name="publication_date" type="date"> <value>2011-12-01T00:00-08:00</value> </field> <field name="embargo_date" type="date"> <value>2011-12-01T00:00-08:00</value> </field> <submission-date>2011-11-17T08:11:17-08:00</submission-date> <publication-date>2011-12-01T00:00-08:00</publication-date> </test> And I'd like to do a comparison check on the field[@name='embargo_date'] vs the output of current-dateTime(). I have the following stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> <xsl:output encoding="UTF-8" indent="yes" method="xml"/> <xsl:variable name="c-dateTime" select="dateTime(xs:date(format-date(current-date(), '[Y]-[M,2]-[D,2]')), xs:time(format-time(current-time(), '[H]:[m]:[s][Z]')))"/> <xsl:template match="/"> <xsl:variable name="test-dateTime" as="xs:dateTime" select="test/field[@name='embargo_date']/value"/> <result><xsl:value-of select="if ($test-dateTime ge $c-dateTime ) then 'embargo me!' else 'all clear!'"/></result> </xsl:template> </xsl:stylesheet> I'm using Saxon HE-9.6.0.7 in oXygen 18.1, which gives me a compile time error of "FORG0001: Invalid dateTime value "2018-12-01T00:00-08:00" (Wrong delimiter after minute)". Is the right thing to do here to do some string parsing on the substrings in the values that I need to check? Is there some other way to convert the value in field[@name='embargo_date'] into an xs:dateTime? Thanks for your time and trouble. Best, Bridger
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|