Re: Select MaxDate from xml

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Horváth Szilárd wrote:
Hi!

How can I select node from xml where the value is the max? Like "Select * From table0 where date = (select max(date) from table0)". i don't use any DB Server just xml and dataset.

(a) XML is not a database, so it doesn't behave like one. There are some
passing resemblances, but it is a canonical error to conflate the two.
See the warning box on http://xml.silmaril.ie/authors/databases/

(b) Depending on your XML processing language you may or may not have a
max() function. XSLT 1.0 notoriously did not have one, but XSLT 2.0 has
fn:max(); but there are function libraries for XSLT 1.0 which provide
them (eg http://www.datypic.com/xsl/); otherwise you need to calculate
maxima with a recursive template. I have an old one somewhere if you are
constrained to use XSLT 1.0 without libraries.

(c) In any case, it is not a good idea to store dates with alpha months,
because any comparison is going to put April at the top and September at
the bottom. You should always store dates and times in ISO 8601 format
(2008-01-30T23:43:14): you can easily convert them to something
localised for your culture on output, but if you store them wrong,
you'll make them unusable.

(d) XSLT 1.0 did not handle ordering well by default, and XML, being
designed for text documents, does not in itself have the concept of a
"date" datatype; so to make numeric comparisons on date strings you need
to use a date library, or strip the punctuation from the strings (eg
translate(date,'-T:','')) to leave only digits. XSLT 2.0 has an
extensive and excellent selection of date functions to overcome this.

///Peter

<table0>
<row0>
<id>0</id>
<text>text0</text>
<date>2009-jan-30</date>
</row0>
<row1>
<id>1</id>
<text>text1</text>
<date>2009-jan-29</date>
</row1>
<row2>
<id>2</id>
<text>text2</text>
<date>2009-jan-31</date>
</row2>
</table0>
.



Relevant Pages

  • Re: Select MaxDate from xml
    ... My date which i vant to store is the current modification date and when i search the max date then is equal is the last item. ... How can I select node from xml where the value is the max? ... XSLT 1.0 notoriously did not have one, ... constrained to use XSLT 1.0 without libraries. ...
    (microsoft.public.dotnet.xml)
  • Re: Using PHP to parse specific XML tag content?
    ... XML --> HTML transformation in testing environment. ... run just fine under Windows using Cygwin, and, unless I'm ... but you have to learn XSLT or use whatever defaults ...
    (comp.lang.php)
  • Re: XML+Logs to Latex. XSLT?
    ... "language" and that Python will have any library that uses XSLT to do ... XSLT is definitely something like XML - because an XSLT file is an XML ... ElementTree API on top of the popular libxml2 and libxslt libraries ...
    (comp.lang.python)
  • Subject: ANN: 4Suite XML 1.0b2
    ... 4Suite XML - XML, XPath, XSLT, related technologies and support ... 4Suite RDF - RDF processing libraries and stand-alone DBMS ...
    (comp.lang.python.announce)
  • EditiX 2.1 - XML Editor & XSLT Debugger
    ... We are glad to announce the availability of EditiX 2.1. ... cross-platform and easy to use XML Editor and XSLT Debugger designed to ... New docking windows for the XSLT Editor ...
    (comp.lang.java.softwaretools)