xsl-list
[Top] [All Lists]

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

2008-02-28 03:40:56
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
xsl:sort.

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!

Michael

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--