944,160 Members | Top Members by Rank

Ad:
Nov 4th, 2009
0

How to Compare Date in XPath Expression

Expand Post »
I have orders.xml like the following

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <orders>
  3. <order orderDate="1/1/2009" orderNo="1">
  4. <customer id="nnghiem" name="nguyen nghiem"/>
  5. <item id="item-1" price="25000" quantity="0"/>
  6. <item id="item-2" price="22000" quantity="3"/>
  7. </order>
  8. <order orderDate="2/2/2009" orderNo="2">
  9. <customer id="lp" name="lampard"/>
  10. <item id="item-1" price="25000" quantity="2"/>
  11. <item id="item-2" price="22000" quantity="8"/>
  12. </order>
  13. <order orderDate="3/3/2007" orderNo="3">
  14. <customer id="nnghiem" name="nguyen nghiem"/>
  15. <item id="item-1" price="25000" quantity="7"/>
  16. <item id="item-2" price="22000" quantity="6"/>
  17. </order>
  18. </orders>

I want to retrieve every order in '2009
I solved this problem by the following way:

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. String exp = "/orders/order[substring(@orderDate,string-length(@orderDate)-3)='2009']";
  2. //... some code lines

I wonder is there any way to compare date in this situation like this:

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. String exp = "/orders/order[@orderDate<'31/12/2009' and @orderDate>'1/1/2009']";

// get all orders between 1/1/2009 and 31/12/2009 (in year 2009)

but this exp will not return the expected result

How to solve this problem?

Thanks for your attention!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
extkml is offline Offline
3 posts
since Nov 2009
Nov 5th, 2009
0
Re: How to Compare Date in XPath Expression
XPath 1.0 only supports number comparison. XPath 2.0 understands the date type. With XPath 1.0 you need to do a string comparison. There is no other way.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Nov 5th, 2009
0
Re: How to Compare Date in XPath Expression
thanks for your reply
Reputation Points: 10
Solved Threads: 0
Newbie Poster
extkml is offline Offline
3 posts
since Nov 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in XML, XSLT and XPATH Forum Timeline: XPath Expression to calculate total amount for order details
Next Thread in XML, XSLT and XPATH Forum Timeline: XSLT as an HTML based Template





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC