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&#39;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">&lt;<a href="mailto:howardk@fatdog.com">howardk@fatdog.com</a>&gt;</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&#39;s are used here only for demonstration purposes; they&#39;re not present<br>
in the actual document.)<br>
<br>
I&#39;d be happy to see a solution either in XQuery or in XSLT. Here&#39;s some<br>
sample input and the output.<br>
<br>
Input:<br>
<br>
&lt;library&gt;<br>
        &lt;book pubYear=&#39;1942&#39; catid=&#39;1&#39; &gt;<br>
                &lt;otherStuff ... /&gt;&lt;/book&gt;<br>
        &lt;book pubYear=&#39;1942&#39; catid=&#39;2&#39; &gt;<br>
                &lt;otherStuff ... /&gt;&lt;/book&gt;<br>
        &lt;book pubYear=&#39;1942&#39; catid=&#39; 3 &#39; &gt;<br>
                &lt;otherStuff ... /&gt;&lt;/book&gt;<br>
        ...<br>
<br>
        &lt;book pubYear=&#39;2009&#39; catid=&#39; 2011&#39; &gt;<br>
                &lt;otherStuff ... /&gt;&lt;/book&gt;<br>
        &lt;book pubYear=&#39;2009&#39; catid=&#39; 2012 &#39; &gt;<br>
                &lt;otherStuff ... /&gt;&lt;/book&gt;<br>
        &lt;book pubYear=&#39;2009&#39; catid=&#39; 2013 &#39; &gt;<br>
                &lt;otherStuff ... /&gt;&lt;/book&gt;<br>
&lt;/library&gt;<br>
<br>
Output:<br>
<br>
&lt;library&gt;<br>
        &lt;book pubYear=&#39;2009&#39; catid=&#39; 2011&#39; &gt;<br>
                &lt;otherStuff ... /&gt;&lt;/book&gt;<br>
        &lt;book pubYear=&#39;2009&#39; catid=&#39; 2012 &#39; &gt;<br>
                &lt;otherStuff ... /&gt;&lt;/book&gt;<br>
        &lt;book pubYear=&#39;2009&#39; catid=&#39; 2013 &#39; &gt;<br>
                &lt;otherStuff ... /&gt;&lt;/book&gt;<br>
        ...<br>
<br>
        &lt;book pubYear=&#39;1942&#39; catid=&#39; 1 &#39; &gt;<br>
                &lt;otherStuff ... /&gt;&lt;/book&gt;<br>
        &lt;book pubYear=&#39;1942&#39; catid=&#39; 2 &#39; &gt;<br>
                &lt;otherStuff ... /&gt;&lt;/book&gt;<br>
        &lt;book pubYear=&#39;1942&#39; catid=&#39; 3 &#39; &gt;<br>
                &lt;otherStuff ... /&gt;&lt;/book&gt;<br>
&lt;/library&gt;<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>