473,407 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Dates as strings - using comparions in XPath

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') &gt;
string('2005-09-15T14:06:58')" />

<xsl:value-of select="string('2005-09-15T14:06:58') &gt;
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?

I keep staring at the code, but it doesn't get any clearer 8-(
Thanks!

Sep 23 '05 #1
2 1775


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') &gt;
string('2005-09-15T14:06:58')" />

<xsl:value-of select="string('2005-09-15T14:06:58') &gt;
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/
Sep 23 '05 #2
Martin Honnen wrote:
In those examples you compare
NaN > NaN
and that yields false


Thanks - I'd guessed that NaN was showing up somewhere, as both were
returning the same value (the old "propagating nulls" problem in
database-speak). I could have sworn XPath comparisons worked on strings
though!

I've re-written it to use <xsl:for-each><xsl:sort> and just return the
value of the first item.

Sep 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: J P Singh | last post by:
Hi All I am trying to query a database with a combination of surname and date of birth but it is giving me wrong results in certain conditions. It is the mm/dd/yyyy and dd/mm/yyyy stuff that...
2
by: AR | last post by:
Hi, How can I get strings separately which contain text nodes of a given element using XSL and XPath? For example, <a> aaa 111 <b>
6
by: Michael Hill | last post by:
I have this large array with dates in it. There is a function that sorts it for me. The only problem is that in order for it to get sorted properly I have to sort it AlphaNumerically first using ...
11
by: Peter Pfeiffer | last post by:
I've written several scripts that have "while" blocks which increment a date by one day if the date does not match one of a group of dates. However, sometimes it apparently steps out out the while...
8
by: netsurfer | last post by:
Hi: Have a question on making the date automatically filled in by what the user enters in by the date at the top. The date entered at the top would most likely be on a Wednesday then I need...
22
by: mike | last post by:
If I had a date in the format "01-Jan-05" it does not sort properly with my sort routine: function compareDate(a,b) { var date_a = new Date(a); var date_b = new Date(b); if (date_a < date_b)...
9
by: labelle | last post by:
I have an event listing on my website that is pulling from SQL. Unfortunately, the listing is displaying all events, especially those that are even 2 years old. I want to get rid of them and only...
2
by: =?Utf-8?B?U2JhdGNodQ==?= | last post by:
How will i read connection strings in all web.config files in one particualr machine?
5
by: jorgedelgadolopez | last post by:
Hi all, I am using the xpathnavigator evaluate function on .net (xpath 1 right?). Now I need to expand the code to do multiple contains, compare dates (such as 'before', 'between' and 'after'),...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.