[xquery-talk] reversing element ordering, with a caveat
Howard Katz
howardk at fatdog.com
Sun Mar 15 18:04:27 PST 2009
I have a series of books ordered chronologically by publication date, 1942
to 2009. I want to generate a file in which the books have the reverse
chronological ordering, 2009 to 1942, but with the caveat that books
*within* a particular year need to maintain the original document order
relative to that year. In the following, the catid attributes within a
particular year remain in ascending order after the transformation. (The
catid's are used here only for demonstration purposes; they're not present
in the actual document.)
I'd be happy to see a solution either in XQuery or in XSLT. Here's some
sample input and the output.
Input:
<library>
<book pubYear='1942' catid='1' >
<otherStuff ... /></book>
<book pubYear='1942' catid='2' >
<otherStuff ... /></book>
<book pubYear='1942' catid=' 3 ' >
<otherStuff ... /></book>
...
<book pubYear='2009' catid=' 2011' >
<otherStuff ... /></book>
<book pubYear='2009' catid=' 2012 ' >
<otherStuff ... /></book>
<book pubYear='2009' catid=' 2013 ' >
<otherStuff ... /></book>
</library>
Output:
<library>
<book pubYear='2009' catid=' 2011' >
<otherStuff ... /></book>
<book pubYear='2009' catid=' 2012 ' >
<otherStuff ... /></book>
<book pubYear='2009' catid=' 2013 ' >
<otherStuff ... /></book>
...
<book pubYear='1942' catid=' 1 ' >
<otherStuff ... /></book>
<book pubYear='1942' catid=' 2 ' >
<otherStuff ... /></book>
<book pubYear='1942' catid=' 3 ' >
<otherStuff ... /></book>
</library>
TIA,
Howard
More information about the talk
mailing list