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

RE: sorted for-each: preceding::sibling is not in sort

Subject: RE: sorted for-each: preceding::sibling is not in sort order
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 13 Nov 2005 16:11:14 -0000
preceding sequence of nodes
> Working on a grouping problem I was trying to use preceding::sibling
> on a selection of nodes that I had assembled with for-each and sorted.
> 
> It took me a long time to find out that while for-each will 
> present the
> nodes in sort order, preceding::sibling will give me the
> results for a totally different node (probably document order).
> 
> Is this intended behaviour 

Yes. A node has a fixed position in a tree. A tree is immutable: you cannot
change the parent, children, or siblings of an existing node. The axes all
relate to the relationship of the node to other nodes in the same tree.

xsl:sort affects the processing order of the nodes (or in XSLT 2.0, the
ordering of a sequence of nodes) but it does not affect the node's axis
relationships.

> And if 
> so, what is
> the best way around this. The only way I found was to do a first
> for-each copy-of all the nodes into a variable, then work with the
> content of the variable in a second for-each using that variable.
> 
> One big disadvantage being that I'm cutting off all the parent
> relationships when copying my node.

Yes, in 1.0 that's a problem. XSLT 2.0 allows you to use xsl:sequence
instead of xsl:copy-of, so you can construct a variable whose value is a
sequence of nodes (node references) without making copies of the nodes.

Michael Kay
http://www.saxonica.com/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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