RE: last attribute ?

Subject: RE: last attribute ?
From: "John E. Simpson" <simpson@xxxxxxxxxxx>
Date: Tue, 26 Sep 2000 17:47:18 -0400
At 03:03 PM 09/26/2000 -0400, Brian Young wrote:
Why would the attributes not be processed in document order?

Short answer is: Because the XPath/XSLT specs explicitly *say* that the order in which attributes are retained in the processor's internal tree cannot be counted on.


The longer answer is that attributes (as opposed to elements) do not function as "structured content." Basically, you (or whoever's designed the XML vocabulary you're using) have opted to put certain information into attributes, for one reason or another, but you'd like them under some cases to function like elements. That's not possible, to my knowledge.

I've never written an XSLT processor, but I imagine that internally, attribute name/value pairs are kept in some kind of indexed structure, e.g. alphabetically by attribute name, to speed access to them when/if needed. To the extent that this is true, you *might* be able to use a particular processor to spit them out in the same order they came in by ordering the attributes in each element instance in the same order as the processor will store them, e.g.
<elem
attrib_a="something"
attrib_b="something_b" [...etc...]
attrib_z="something_z"/>
I think I tested Saxon once, months ago, to see how it handled this sitation and (at least at that time, with that document, etc.) it did indeed seem to be ordering attributes alphabetically. So no matter what order attrib_a, _b, etc. appeared in in the source document, they always seemed to come out of the processor in alphabetical order.


But again, the processor might under certain circumstances re-order them some other way, or a new version of the processor might use some other indexing scheme, or you yourself might later opt to use a different processor, e.g. for cross-platform testing if nothing else. Under any of those conditions, you're back to Square One.

If they are not, how can this be forced?

It can't, to my knowledge.



==========================================================
John E. Simpson | "If you were going to
http://www.flixml.org | shoot a mime, would you use
XML Q&A: http://www.xml.com | a silencer?" (Steven Wright)



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread