xml - How to compare two date variables in XSLT? -
i've written simple xslt below. long , short want 2 things.
first, want print whether or not new order. purposes, order new if ordercreatedate , ordereditdate fields same.
second, want print 2 dates (to check work; formatting isn't important, yet.)
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" > <xsl:output method="text" indent="yes"/> <xsl:template match="/arrayofdp_rundatesall"> <xsl:variable name='ordercreatedate' select='dp_rundatesall[1]/ordercreatedate'/> <xsl:variable name='ordereditdate' select='dp_rundatesall[1]/ordereditdate'/> <xsl:choose> <xsl:when test='ordercreatedate != ordereditdate'> existing order! </xsl:when> <xsl:otherwise> new order! ordercreatedate <xsl:value-of select='$ordercreatedate' /> ordereditdate <xsl:value-of select='$ordereditdate' /> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
i expect above xslt, when record processed 2 separate dates, output should existing order!
.
however, see following output.
new order! ordercreatedate 2013-08-16t10:27:39 ordereditdate 2013-08-17t17:19:43.6
by rules described above, should have printed existing order!
(because 2 dates don't match). have done wrong result here?
you're missing dollar signs - should be
<xsl:when test='$ordercreatedate != $ordereditdate'>
your current test trying find elements called ordercreatedate
, ordereditdate
children of current context node, presume (given variable definitions) don't exist. it's checking whether '' != ''
, , taking otherwise
branch.
Comments
Post a Comment