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

Re: position() from the attribute axis for getting the

Subject: Re: position() from the attribute axis for getting the position of the parent in respect to its siblings
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 18 Jan 2007 13:54:09 GMT
Re:  position() from the attribute axis for getting the
> for $elem in ../../day return position()
> 
> Or should I read this as the "position of the current element in the 
> current context, which is the same as current()/position and not the 
> position that $elem takes in the set of nodes ../../day".


No, current() selects a single item, (or is an error if there is no
current item) so current()/position() is 1 if it's not an error
(which it will be if there is no current item or if it is not a node)

on the other hand position() (on its own) returns the current position
in the current sequence, compare

FLWOR expressions don't change the current item or position() so if you
evaluate position() at teh top level of a FLWOR it gives the same value
each iteration of teh loop, the value it would have given if evaluated
outside the loop.



<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
<xsl:variable name="x">
<x>A</x>
<x>B</x>
<x>C</x>
</xsl:variable>

<xsl:template name="main">
  <xsl:for-each select="$x/*">
====
<xsl:value-of select="."/>
position: <xsl:value-of select="position()"/>
current()/position(): <xsl:value-of select="current()/position()"/>
for: <xsl:value-of select="for $e in 1 to 3 return position()"/>
===
  </xsl:for-each>
</xsl:template>
</xsl:stylesheet>


$ saxon8 -it main posn.xsl
<?xml version="1.0" encoding="UTF-8"?>
====
A
position: 1
current()/position(): 1
for: 1 1 1
===
  
====
B
position: 2
current()/position(): 1
for: 2 2 2
===
  
====
C
position: 3
current()/position(): 1
for: 3 3 3
===
  


see, 
position() gives 1,2,3 
 current()/position() always gives 1
for $e in 1 to 3 return position() just does position() 3 times.

David

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-2011 All Rights Reserved.