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

Re: simulating for with foreach

Subject: Re: simulating for with foreach
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 5 Jul 2006 13:11:43 +0100
Re:  simulating for with foreach
  Thank you very much. That fully solved my problem, but just for my
  curiosity, why position() (and also last()) do return sequential
  numbers instead of real positions. I mean position() returns 1, 2, 3
  instead of 1, 4, 9...

position() has no relation to the position of the node in the input
document, it is the position of the node in the current node list (ie
the nodes just selected). Similarly last() is defined to be the length
of the current node list. The same node will have different position()
depending on how it is selected

If you go
<xsl:for-each select=".">

then position()=last()=1 whetever node is selected as . selects a list
of length one and the current node is the first (and only) item of that

In many (most) cases the sequential node ordering in the input document
is fairly irrelevant and it's position() that you want.


 <! an example -->
  <!-- <c/> -->

then if you say select="*" you get a b and c with positions 1,2,3 which
you may use to number the output or whatever.

Child nodes of x thoughhave fairly arbitrary positions affected by
indentation and comments,  if you select="node() you will see whet you
call "real position" 
 1 (white space text)
 2 comment
 3 (white space text)
 4 <a/>
 5 (white space text)
 6 <b/>
 7 (white space text)
 8 comment
 9 (white space text)
 8 <d/>
10 (white space text)

so the three elements you are really interested in have positions 4,6
and 8.


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.