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

Re: position of non actual element

Subject: Re: position of non actual element
From: Oliver Becker <obecker@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 27 Feb 2002 09:30:25 +0100 (MET)
becker 27
Hi Rudolf,

> I'm having problem with position().
> I need position of node which is not tested now, eg.
> <data>
>   <value attr="first">...</value>
>   <value attr="second">...</value>
> </data>
> 
> <!--xsl:value-of select="position(data/value[@attr = 'second'])"/-->
> of course this cannot run :-))

position() returns always the position of the current node within the
context node list. There's nothing like a "global position".

For example: if you have
<xsl:template match="value[@attr='second']">
   <xsl:value-of select="position()" />
</xsl:template>
you might think to get always the same value. 

No, that's not the case. position depends, as I said, on the context
node list. I.e.
<xsl:apply-templates select="//*" />
<xsl:apply-templates select="/data/value" />
<xsl:apply-templates select="/data/value[@attr='second']" />
gives three different numbers.

So, what do you mean by "position"?
The position of the value element among its value siblings?
Then just count the preceding siblings and add 1:
<xsl:value-of
     select="count(data/value[@attr='second']/preceding-sibling::value)+1" />
     
Or alternatively you could use the power of <xsl:number />:
<xsl:for-each select="data/value[@attr='second']">  
<!-- this only changes the context node -->
   <xsl:number />
</xsl:for-each>

Cheers,
Oliver


/-------------------------------------------------------------------\
|  ob|do        Dipl.Inf. Oliver Becker                             |
|  --+--        E-Mail: obecker@xxxxxxxxxxxxxxxxxxxxxxx             |
|  op|qo        WWW:    http://www.informatik.hu-berlin.de/~obecker |
\-------------------------------------------------------------------/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.