I find it very worrying that either of your expressions select anything.
I tried the page you mentioned and tried to visually follow your path,
but couldn't find any match. Then I thought that maybe the tool was
smarter than I, so I downloaded/installed it. Tried your queries again:
nothing.
Next I cut n pasted the source HTML so I could process it normally
without the fuzz and noise of other tools (not knowing what they do,
where they rely on, etc). I quickly found that:
1. There is no <h2> element anywhere that document
2. There is a <h3> element, but that does not have any siblings of
type <ul>
3. In the expression you don't select <ul>, but any elements
4. I tried to understand your English description of what you are
trying to achieve, but there are no <ul> elements that are siblings to <h3>
But you say "following". So maybe I misunderstood. In your code you use
following-sibling with some counting back and forth. Not along the
following::* axis (there are much deeper nested <ul> elements).
Your question was about the difference in your XPaths. You use the id()
function (note that it only works when there is actually a DOCTYPE
present that declares an attribute as type ID; often this is not the
case, so in practice I don't see id() used that often), which selects
all elements (like the DOM getElementsById()) with the selected ID. This
means that in your second expression you are basically searching from
the root (bodyContent) on each step. In your first, you are using the
child axis to start from.
Because I can't see a document that possibly matches your XPath
expression, I can't see where it goes wrong.
Sorry I couldn't be of any more help.
Cheers,
-- Abel Braaksma
Michael Terry wrote:
Unexpected to me, at least.
I've been familiarizing myself with XPath for a project by browsing
around the Internet with the Firefox extension XPath Checker.
On this page:
http://en.wikiquote.org/wiki/A.I.
... I tried the following:
id('bodyContent')/h2/following-sibling::*[position()<count(following-sibling::p[1]/preceding-sibling::*)
- count(preceding-sibling::*)]
... which I expected to select the 7 ul elements following the
specified h2. The next query DOES do that:
id('bodyContent')/h2[1]/following-sibling::*[position()<count(id('bodyContent')/h2[1]/following-sibling::p[1]/preceding-sibling::*)
- count(id('bodyContent')/h2[1]/preceding-sibling::*)]
The stuff I had to add in I had expected was already present as the
context node. Why was I wrong?
- mt
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--