Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


XPath expression to find minimum/earliest date-time?

From: "Zoe Hart" <zoe.hart@------.-----------.--->
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





transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent