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

RE: Determining the position of a specific node in the

Subject: RE: Determining the position of a specific node in the context
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 20 Oct 2006 10:33:56 +0100
RE:  Determining the position of a specific node in the
> The task: I want to determine if in the current context, a 
> node with certain properties comes before another.
> 
> Example:
> 
> <root>
>   <A/>
>   <B/>
>   <C/>
> </root>
> 
> I want to know whether <B/> comes before <C/>. 

I think you actually want to know whether <B/> comes before <C/> in the
source tree, not in the current context. You can construct a context in
which <C/> precedes <B/>, for example

<xsl:for-each select="*">
  <xsl:sort select="name()" order="descending"/>

but I don't think that's the question you are asking (if it is, you've got
problems).

So forget about the position of the nodes in the context, and think about
the position of the nodes in the source tree. You've only given one example
input, and it's hard to infer the general problem from one example, but you
can do

test="B/following-sibling::C"

or in 2.0 you can do

test="$C >> $B".


> 
> [Side note: Testing the above in Saxon 8 (XSLT2, XPath2) does 
> not give an error or warning, but the test simply evaluates 
> to false. So, "node() [self::B]/position()" must be a legal 
> XPath 2 expression - what does it actually do?]

X/position() says "for each node in X, return its position in the list". So
it means the same as the expression

1 to count(X)

For some reason "1 to count(X)" is a much more common idiom, but since
X/position() is fewer characters, I expect David Carlisle will change
that...

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.