|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] reversing element ordering, with a caveatHoward Katz howardk at fatdog.comSun Mar 15 19:44:00 PST 2009
Beautiful. I just removed the value() function following the path ending in @pubYear, as Saxon returned an "Unknown system function," and it worked perfectly. Thanks you, Howard _____ From: http://x-query.com/mailman/listinfo/talk [mailto:http://x-query.com/mailman/listinfo/talk] On Behalf Of Brian Maso Sent: Sunday, March 15, 2009 7:24 PM To: Howard Katz; http://x-query.com/mailman/listinfo/talk Subject: Re: reversing element ordering, with a caveat In XQuery, I think its just a matter of running over the distinct values of //book/@pubYear in descending order. Something like: (* Maybe there's a more elegant way of getting the sequence of years in descending order? *) let $descending-distinct-years := distinct-values(for $v in //book/@pubYear/value() order by $v descending return $v) for $year in $descending-distinct-years return //book[@pubYear = $year] This will retain original document ordering for elements with the same @pubYear value, but years will be descending from highest value to lowest. Brian Maso On Sun, Mar 15, 2009 at 6:04 PM, Howard Katz <http://x-query.com/mailman/listinfo/talk> wrote: 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 _______________________________________________ http://x-query.com/mailman/listinfo/talk http://x-query.com/mailman/listinfo/talk -------------- next part -------------- An HTML attachment was scrubbed... URL: http://x-query.com/pipermail/talk/attachments/20090315/f1477ef5/attachment.htm
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






