di*****@codesmiths.com wrote:
Losing my marbles here (some sleep would help!)
Why are the following XPath comparisons both returning false ?
<xsl:value-of select="string('2005-09-22T12:43:23') >
string('2005-09-15T14:06:58')" />
<xsl:value-of select="string('2005-09-15T14:06:58') >
string('2005-09-22T12:43:23')" />
Shouldn't these just act as simple string comparisons and behave
themselves? As the dates are ymd and 0 padded, then this is also
adequate for a date comparison?
For primitive values the <, >, <=, and >= operators in XPath 1.0 are
defined on numbers only so any operands are converted to numbers and
those are compared. In those examples you compare
NaN > NaN
and that yields false (NaN is the "number" value you get for anything
that can not be converted to a number).
See <http://www.w3.org/TR/xpath#booleans> where it says:
"When neither object to be compared is a node-set and the operator is
<=, <, >= or >, then the objects are compared by converting both objects
to numbers and comparing the numbers according to IEEE 754."
So you can try as hard as you want, XPath 1.0 does not do < or >
comparisons on strings.
As for those date/time strings I think you could try
translate('2005-09-15T14:06:58', '-T:', '') <
translate('2005-09-22T12:43:23', '-T:', '')
that would then yield numbers which could be compared.
--
Martin Honnen
http://JavaScript.FAQTs.com/