I saw something strange today and wanted to know why it occurs.

I have a sequence of elements: $seq:
<session startedOn="10/17/2011 14:45:01"/>
<session startedOn="10/20/2011 12:41:39"/>
<session startedOn="10/25/2011 13:32:08"/>
<session startedOn="10/26/2011 13:35:55"/>
<session startedOn="10/27/2011 12:37:53"/>

The above is what I get as output for
<xsl:for-each select="$seq>
<xsl:text>
</xsl:text>
<session startedOn="{@startedOn}"/>
</xsl:for-each>

I would expect that the expression $seq/@startedOn would, upon atomization, yield strings in an order corresponding to the elements in $seq.

That is to say that I expect $seq/@startedOn to give the same output as
for $i in 1 to 5 return $seq[$i]/@startedOn.

However, instead when I put $seq/@startedOn in an AVT, I get
10/25/2011 13:32:08
10/27/2011 12:37:53
10/17/2011 14:45:01
10/20/2011 12:41:39
10/26/2011 13:35:55

(newlines added for clarity.)

I noticed that I get what I expect if I atomize within the xpath expression: $seq/string(@startedOn)  gives the times in the order I expect:
10/17/2011 14:45:01
10/20/2011 12:41:39
10/25/2011 13:32:08
10/26/2011 13:35:55
10/27/2011 12:37:53

Can someone explain what is going on and when I have to watch out for this non-preservation or order?

-David


--

"A false conclusion, once arrived at and widely accepted is not dislodged easily, and the less it is understood, the more tenaciously it is held." - Cantor's Law of Preservation of Ignorance.