XML News from Saturday, January 30, 2010

XQuery executing for about an hour now. O(N^2) algorithm perhaps? Maybe I should learn about indexes? Or is eXist just hung?

declare namespace xmldb="http://exist-db.org/xquery/xmldb";
declare namespace html="http://www.w3.org/1999/xhtml";
declare namespace xs="http://www.w3.org/2001/XMLSchema";
declare namespace atom="http://www.w3.org/2005/Atom";

for $date in distinct-values(
    for $updated in collection("/db/news")/atom:entry/atom:updated
    order by $updated descending
    return xs:date(xs:dateTime($updated)))
    
let $entries := collection("/db/news")/atom:entry[xs:date(xs:dateTime(atom:updated)) = $date]
return <div>
  for $entry in $entries
  return $entry/atom:title
  <hr />
</div>