"Timo Nentwig" <> wrote in message
news:bvlj15$te09t$...
> Hi!
>
> I want to select the parent of <span class="h2"> (which is <td>). The
> following does not work:
>
> //span[@class="h2"]/../td
>
> <blah>
> <td>
> <span class="h2" />
> </td>
> </blah>
>
> Why not?
Michael already explained why -- this expression is selecting all siblings
"td" of all "span" elements, whose "class" attribute is "h2".
On the other side the seemingly correct XPath expression:
//span[@class="h2"]/..
does not select *the* parent of "span" -- it selects *all* parents of all
"span" elements, whose "class" attribute is "h2".
If you want the (one and only) parent of a specific single "span" element,
you shouldn't be using the "//" abbreviation.
Cheers,
Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,
http://fxsl.sourceforge.net/ -- the home of FXSL
Resume:
http://fxsl.sf.net/DNovatchev/Resume/Res.html