In XQuery, I think its just a matter of running over the distinct values of //book/@pubYear in descending order. Something like:<br><br>(* Maybe there's a more elegant way of getting the sequence of years in descending order? *)<br>
let $descending-distinct-years := distinct-values(for $v in //book/@pubYear/value() order by $v descending return $v)<br>for $year in $descending-distinct-years<br>return //book[@pubYear = $year]<br><br>This will retain original document ordering for elements with the same @pubYear value, but years will be descending from highest value to lowest.<br>
<br>Brian Maso<br><br><div class="gmail_quote">On Sun, Mar 15, 2009 at 6:04 PM, Howard Katz <span dir="ltr"><<a href="mailto:howardk@fatdog.com">howardk@fatdog.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I have a series of books ordered chronologically by publication date, 1942<br>
to 2009. I want to generate a file in which the books have the reverse<br>
chronological ordering, 2009 to 1942, but with the caveat that books<br>
*within* a particular year need to maintain the original document order<br>
relative to that year. In the following, the catid attributes within a<br>
particular year remain in ascending order after the transformation. (The<br>
catid's are used here only for demonstration purposes; they're not present<br>
in the actual document.)<br>
<br>
I'd be happy to see a solution either in XQuery or in XSLT. Here's some<br>
sample input and the output.<br>
<br>
Input:<br>
<br>
<library><br>
<book pubYear='1942' catid='1' ><br>
<otherStuff ... /></book><br>
<book pubYear='1942' catid='2' ><br>
<otherStuff ... /></book><br>
<book pubYear='1942' catid=' 3 ' ><br>
<otherStuff ... /></book><br>
...<br>
<br>
<book pubYear='2009' catid=' 2011' ><br>
<otherStuff ... /></book><br>
<book pubYear='2009' catid=' 2012 ' ><br>
<otherStuff ... /></book><br>
<book pubYear='2009' catid=' 2013 ' ><br>
<otherStuff ... /></book><br>
</library><br>
<br>
Output:<br>
<br>
<library><br>
<book pubYear='2009' catid=' 2011' ><br>
<otherStuff ... /></book><br>
<book pubYear='2009' catid=' 2012 ' ><br>
<otherStuff ... /></book><br>
<book pubYear='2009' catid=' 2013 ' ><br>
<otherStuff ... /></book><br>
...<br>
<br>
<book pubYear='1942' catid=' 1 ' ><br>
<otherStuff ... /></book><br>
<book pubYear='1942' catid=' 2 ' ><br>
<otherStuff ... /></book><br>
<book pubYear='1942' catid=' 3 ' ><br>
<otherStuff ... /></book><br>
</library><br>
<br>
TIA,<br>
Howard<br>
<br>
_______________________________________________<br>
<a href="mailto:talk@x-query.com">talk@x-query.com</a><br>
<a href="http://x-query.com/mailman/listinfo/talk" target="_blank">http://x-query.com/mailman/listinfo/talk</a><br>
</blockquote></div><br>