Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 4th, 2009, 06:46 AM
Registered User
 
Join Date: Nov 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Compare date in XPath Expression

I have orders.xml like the following

Code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<orders>
<order orderDate="1/1/2009" orderNo="1">
<customer id="nnghiem" name="nguyen nghiem"/>
<item id="item-1" price="25000" quantity="0"/>
<item id="item-2" price="22000" quantity="3"/>
</order>
<order orderDate="2/2/2009" orderNo="2">
<customer id="lp" name="lampard"/>
<item id="item-1" price="25000" quantity="2"/>
<item id="item-2" price="22000" quantity="8"/>
</order>
<order orderDate="3/3/2007" orderNo="3">
<customer id="nnghiem" name="nguyen nghiem"/>
<item id="item-1" price="25000" quantity="7"/>
<item id="item-2" price="22000" quantity="6"/>
</order>
</orders>
I want to retrieve every order in '2009
I solved this problem by the following way:

Code:
String exp = "/orders/order[substring(@orderDate,string-length(@orderDate)-3)='2009']";
//... some code lines
I wonder is there any way to compare date in this situation like this:

Code:
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!
 
Old November 4th, 2009, 06:53 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Never write dates as d/m/yyyy or m/d/yyyy. Firstly, no-one will know which format you intended; secondly you make it much harder to process the values. If you have existing data in this format, convert it to ISO format (yyyy-mm-dd) before you attempt to do any other processing with it.

You will then be able to use all the date-and-time handling machinery in XSLT 2.0 to process your dates, and even if you are using XSLT 1.0, you will be able to use library routines such as those in the EXSLT library.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference

Last edited by mhkay; November 4th, 2009 at 06:53 AM.. Reason: spelling





Similar Threads
Thread Thread Starter Forum Replies Last Post
Want jsp code to compare start date and end date rajeshree13 Java Basics 2 July 20th, 2009 03:10 AM
XPath 2.0 every expression stolte XSLT 5 November 24th, 2008 03:32 PM
XPath Expression NEO1976 XSLT 11 August 2nd, 2006 02:28 AM
compare these date fields and compare and get the susanring Oracle 1 July 24th, 2006 04:58 PM
Need help with XPATH Expression benomathew XSLT 1 May 12th, 2006 04:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.