[xquery-talk] Recursive Sort

Jeremy Clifton j.clifton at intuiworx.com
Tue Jun 20 12:44:23 PDT 2006


Say I have the following XML:

<categories>
	<category id="1" name="Memory Sticks, Flash Drives, &amp; Memory  
Cards"/>
	<category id="2" name="USB Hubs &amp; Accessories">
		<category id="3" name="Chargers"/>
		<category id="4" name="Fans/Lights"/>
		<category id="7" name="Mousepads"/>
		<category id="8" name="Cords &amp; Cord Organizers"/>
	</category>
	<category id="11" name="Novelties &amp; Gadgets">
		<category id="18" name="LCD Clocks"/>
		<category id="19" name="MP3 Sunglasses"/>
		<category id="20" name="USB Watches"/>
		<category id="21" name="Multi-Function Pens"/>
	</category>
	<category id="22" name="General Accessories"/>
	<category id="23" name="Gift Boxes"/>
</categories>

Is it possible to create an XQuery expression that will return the  
contents of that document, but with the category nodes sorted  
alphabetically by their name attribute, recursively? IE, each level  
of the hierarchy is sorted? If so, is this possible via a simple  
FLWOR expression, or am I looking at having to define a recursive  
user-defined function?

Or, am I barking up the wrong tree, and should I enforce that order  
when the XML document is created/edited?

Thanks,
Jeremy

---
Jeremy Clifton <j.clifton at intuiworx.com>
IntuiWORX - Intuitive, Innovative Software Development
http://www.intuiworx.com
Toll Free:       1-800-267-1708
Chattanooga, TN: (423) 443-3972
Asheville, NC:   (828) 357-4123





More information about the talk mailing list