Subject: Re: [xsl] Reverse axis, reverse document order, xsl:for-each From: Michael Ludwig <mlu@xxxxxxxxxxxxx> Date: Thu, 28 Feb 2008 11:40:22 +0100 |
Why is this so? Why does xsl:for-each obliterate the direction offered by the axis?
It does not. You are using XSLt 1.0 and Xpath 1.0 has no datatype fr storing ordered sequences. A node set is a _set_ and sets are intrinsically unordered constructs. the sets {1,2,3} {3,2,1} {1,1,3,3,2,2} are all identical.
The axis order specifies the direction to go while collecting nodes, but once they are collected they just go into the set and operations on them work with this unordered collection, perhaps (as in the case of xsl:for-each) sorting the nodes into document order before processing them. If you need a different order, then you can use xsl:sort.
(1) The axis imposes an order while the expression collects nodes, which may be either document order or reverse document order. (2) The result is a node set, unordered by definition. (3) The xsl:for-each re-imposes an order, which by default happens to be document order.
Failing to make this distinction may result in confusion on behalf of the user, who may never have _seen_ the absence of order since a default order - document order - governs the functioning of xsl:for-each.
If you use xslt 2 then the underlying datatype changes from sets to ordered sequences and then variables can hold sequences in specific order (and xsl:for-each will also iterate over the sequence in order)
So if I want to retain a certain order in a structure I have to use XSLT 2.0. In XSLT 1.0, I have to use xsl:sort every time I want something different from document order in an xsl:for-each.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Reverse axis, reverse doc, David Carlisle | Thread | RE: [xsl] Reverse axis, reverse doc, Michael Kay |
Re: [xsl] Using values from one nod, David Carlisle | Date | RE: [xsl] XSLT 2.0 XML Schema defin, Michael Kay |
Month |