Subject: Re: [xsl] ATTRIBUTE ORDER
From: "M. David Peterson" <m.david@xxxxxxxxxx>
Date: Sat, 27 May 2006 22:26:39 -0600
If I could throw some thoughts in on this one,

On Sat, 27 May 2006 08:53:45 -0600, Michael Kay <mike@xxxxxxxxxxxx> wrote:

You can, however, always sort your attributes: if they're
always in alphabetical order they'll always be in the same order.

<xsl:for-each select="@*">
   <xsl:sort select="name()"/>

Since collating sequences for xsl:sort aren't defined in the spec, you've no guarantee that this will give the same attribute order in different implementations; for example the handling of hyphens within sort keys is known to vary from one XSLT processor to another.

Both Dimitre and Dr. Kay bring out an important point to understand. The only counter argument I would make is "How many people actually use more than one XSLT processor on the same code base in production?"

While the cross-platform differences are important to understand, it would
seem the fact that the code will run cross-platform is the most important
piece to all of this.  The fact that theres a chance the results might be
different under certain conditions would allow nicely for a simple comment
to be added in this section of the code that states something like:

<!-- WARNING: Different XSLT processors can produce different output
results "Since collating sequences for xsl:sort aren't defined in the
spec" -->

Obviosuly you could leave out the quotes -- just making sure I pulled out
the fact that I was quoting from Dr. Kay's email in this response.

Of course, this kind of information can't be overlooked, as you simply
have no idea who might be running your code and with what processor at any
point in the future.  As such, a comment similar to the above should be
inserted into your code base.  If you use XDoc or another similar
documentation system, then using the proper comment syntax will ensure
this can be properly pulled out into the docs.

Is there anything I'm missing that would make the above dangerous in any
way?  I can't think of anything right off hand to add to this to ensure
any future problems can be properly handled, but I'll leave plenty of room
for someone who feels there more to add.

Current Thread