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

Re: Reverse axis, reverse document order, xsl:for-each

Subject: Re: Reverse axis, reverse document order, xsl:for-each
From: Michael Ludwig <mlu@xxxxxxxxxxxxx>
Date: Thu, 28 Feb 2008 11:40:22 +0100
Re:  Reverse axis
David Carlisle schrieb:
 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

That's an important distinction I wasn't making.

(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.

Thanks a lot, David!


Current Thread


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.
First Name
Last Name
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.