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

Re: Unexpected Context Node at Points in XPath Express

Subject: Re: Unexpected Context Node at Points in XPath Expression
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Wed, 05 Sep 2007 01:59:57 +0200
Re:  Unexpected Context Node at Points in XPath Express
Michael Terry wrote:
I think I misunderstood what becomes the context node. Take the first
one I mentioned:

id('bodyContent')/h2[1]/following-sibling::*[position()<count(following::p[1]/preceding-sibling::*)
- count(preceding-sibling::*)]

I thought that while the position() filter was running, 'h2[1]' would
be the context node. Instead, it seems the result of
'following-sibling::*' is the context node? What, does it change the
context node to each item in that set as it applies the filter? I
don't suppose there's a way to refer to the previous context node in a
relative way, is there?

In XSLT 2.0 there are a couple of provisions that make it a bit easier to create an XPath. But in 1.0, it is just about what you say: the context node at any given point is the one that is selected. How would you know whether it needs the position() of first element, the second, the third? You can use, however, a predicate, which translates freely like "having" in SQL. In this case, the contextnode is the one that the predicate is making a selection about.


following has context node * for position()
a/b/c/*[position() = 2]

following has context node c for position()
a/b/c[position() = 2]/*

following has context node a for position(), but beware, it is in the third predicate, so it counts only the subset selected by the earlier predicates.
a[count(b/c/*) = '12'][b[@x = 'rr']][position() = 2]



HTH,


-- Abel Braaksma

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

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