[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 caveat

Howard Katz howardk at fatdog.com
Sun Mar 15 18:04:27 PST 2009


  reversing element ordering
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



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.