[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xsl:sort descending causes attribute nodes to be

Subject: Re: xsl:sort descending causes attribute nodes to be created after children, causing an error
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Tue, 16 Jan 2007 14:47:59 +0100
Re:  xsl:sort descending causes attribute nodes to be
Michael Kay wrote:
For attribute nodes the value of the sort key (child::text()) will always be
an empty sequence. An empty sequence sorts before any other value, so in
descending order it sorts last, and since the template with match="@*"
creates attribute nodes, you will be adding attributes to the parent after
the children, which is an error.

Indeed, I was wondering two things: why xsl:sort could mess up with the attributes and why the text() did not work for the attribute. But I forgot that the attribute axis never has any children....


This behaviour is certainly correct, and I'm not sure which part of it you
are questioning.

Well, somehow I hoped that sorting attribute nodes would be a no-op, causing them to appear in the input node's order. It makes sense, I think, considering that ordering attribute nodes does not makes sense: the order of attributes is undefined.


But thinking of this again, makes me realize that this is of course a very wrong way of looking at it. I am sorting the nodes and manipulate them after sorting. Surely, sorting attribute nodes makes sense, esp. when you do something else with them then mere copying, where the order can be important (i.e. for attributes-to-xml-elements for instance, or to text output).

Incidentally, if any of your child elements contains an embedded comment,
the sort will fail because text() selects more than one node, and it's an
error in 2.0 for the sort key to be a sequence longer than one (in 1.0 all
but the first are ignored).

Just checked the original project. I appear to do it correctly there (selecting a single node). I just oversimplified a bit ;-)


Cheers,
-- Abel

Current Thread

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-2013 All Rights Reserved.