papanchatt Posted January 11, 2013 Share Posted January 11, 2013 Hi Guys, I need to compare Date&TIme in XSLT taking input from XML file . Two dates are coming as a variable in XML file. That is Hire entry moment and Last Prior entry time. IF Hire_Entry_Moment (its a DAte time ) is greater than Prior_entry_time (its a date time as well) it should print N. otherwise print Pass. i have used the following code : <xsl:variable name="Hire_Entry_Moment" select="ws:Worker/ws:Additional_Information/ws:Hire_Entry_Moment"/> <xsl:variable name="Prior_Entry_Time" select="ws:Header/ws:Prior_Entry_Time"/> <xsl:choose><xsl:when test="($Hire_Entry_Moment > $Prior_Entry_Time)"> (not sure abt the logic)<xsd:element name="Col2"><xsl:text>"N"</xsl:text></xsd:element></xsl:when><xsl:otherwise><xsd:element name="Col2"><xsl:text>"Pass"</xsl:text></xsd:element></xsl:otherwise></xsl:choose> It is not giving correct output.. Can u guys suggest a way?? Link to comment Share on other sites More sharing options...
Martin Honnen Posted January 11, 2013 Share Posted January 11, 2013 Well only XSLT 2.0 has support for date respectively dateTime data types. So using an XSLT 2.0 processor like Saxon 9, AltovaXML or XmlPrime you can use code like <xsl:when test="xs:dateTime($var1) gt xs:dateTime($var2)">...</xsl:when> but the input needs to be in the format defined by the W3C schema language which is yyyy-mm-ddThh:mm:ss (with an optional time zone specification trailing) e.g. 2013-01-11T16:41:00+01:00. If you use an XSLT 1.0 processor then the comparison operators less than and greater than only work for numbers so you would need to ensure the format is yyyymmddhhmmss or you would need to convert any input data to that format in your code. 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now