Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries [Thread Prev] >Thread Next - Re: XPath expression to find minimum/earliest date-time? XPath expression to find minimum/earliest date-time?To: NULL Date: 9/4/2007 8:53:00 AM
Here's some sample XML that's representative of my actual (but much bigger)
XML:
<test>
<order>
<item_info>
<item>
<somedata>
<value>2007-09-15T15:00:00</value>
</somedata>
</item>
<item>
<somedata>
<value>2007-10-01T13:30:00</value>
</somedata>
</item>
<item>
<somedata>
<value>2007-09-24T16:35:00</value>
</somedata>
</item>
<item>
<somedata>
<value>2007-11-01T13:30:00</value>
</somedata>
</item>
</item_info>
</order>
</test>
I want my output XML to contain the earliest of the above dates. Now if I
make all those dates simple numbers like this:
<test>
<order>
<item_info>
<item>
<somedata>
<value>22</value>
</somedata>
</item>
<item>
<somedata>
<value>54</value>
</somedata>
</item>
<item>
<somedata>
<value>18</value>
</somedata>
</item>
<item>
<somedata>
<value>100</value>
</somedata>
</item>
</item_info>
</order>
</test>
then the following expression correctly returns the minimum number, 18.
/test/order/item_info/item[not(./somedata/value >
/test/order/item_info/item/somedata/value)]/somedata/value
But when the data is dates or strings, it doesn't work. I found some good
information at www.---.com that
included the nugget: "The XPath processor always evaluates these comparisons
in terms of numbers. You cannot use the less than and greater than operators
to order strings." That would seem to explain why the above expression
doesn't work with my data. The problem is that the above article didn't
provide any information about how one could compare strings.
I've written a function to convert a date to number of ticks, but since
finding the minimum date involves comparing an individual date (or number of
ticks) to a node set, I'm not sure how to get the whole node set converted
to number of ticks in order for the comparison to work.
Any suggestions?
Thanks,
Zoe
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
