[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
> 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/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|