order nodes by dateTime
Hi, I am using BaseX 6.5 database. Say I have the documents : doc1, doc2 in my database and the first child node of these documents is "updatedTime". Say the "updatedTime" node of doc1 and doc2 have the values : 2011-02-07T14:40:00.78-05:00 and 2011-02-07T14:41:02.133-05:00 respectively. I am trying to return a sorted list of document names in the descending order of the updatedTime node. I tried the following xquery: for $doc_name in db:list() order by xs:dateTime(doc($doc_name)/updatedTime) descending return $doc_name The output I receive is [doc1, doc2]. But, the expected output is [doc2, doc1]. I tried both ascending and descending in the order by statement but I get the same output. I am not sure how the ordering of elements by dateTime works. Could you help? Thanks, Sony PS: This is a simplified version of my code. The actual nodes have namespace prefixes. I hope the solution would be consistent when namespaces are used.
Hi, The query works as expected after I fixed a minor xpath error. Thanks, Sony On Mon, Feb 7, 2011 at 5:43 PM, Sony Vijay <sony.vibh@gmail.com> wrote:
Hi,
I am using BaseX 6.5 database. Say I have the documents : doc1, doc2 in my database and the first child node of these documents is "updatedTime".
Say the "updatedTime" node of doc1 and doc2 have the values : 2011-02-07T14:40:00.78-05:00 and 2011-02-07T14:41:02.133-05:00 respectively.
I am trying to return a sorted list of document names in the descending order of the updatedTime node.
I tried the following xquery:
for $doc_name in db:list() order by xs:dateTime(doc($doc_name)/updatedTime) descending return $doc_name
The output I receive is [doc1, doc2]. But, the expected output is [doc2, doc1]. I tried both ascending and descending in the order by statement but I get the same output. I am not sure how the ordering of elements by dateTime works. Could you help?
Thanks, Sony
PS: This is a simplified version of my code. The actual nodes have namespace prefixes. I hope the solution would be consistent when namespaces are used.
participants (1)
-
Sony Vijay