order nodes by dateTime
Tuesday, 8 February 2011 · 2 messages
SV
Sony Vijay8 Feb 2011 00:43 #
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_nameThe 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.
SV
Sony Vijay8 Feb 2011 01:05 #
Hi,
The query works as expected after I fixed a minor xpath error.
Thanks,
Sony
Quoted text · Sony Vijay · 30 lines
On Mon, Feb 7, 2011 at 5:43 PM, Sony Vijay <sony.vibh at 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. >
Written for BaseX 6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery