Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > how to select parent?

Reply
Thread Tools

how to select parent?

 
 
Timo Nentwig
Guest
Posts: n/a
 
      02-02-2004
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?

Regards,
Timo
 
Reply With Quote
 
 
 
 
DFN-CIS NetNews Service
Guest
Posts: n/a
 
      02-02-2004
On 02/02/2004, around 13:32, Timo Nentwig wrote:
TN> Hi!

TN> I want to select the parent of <span class="h2"> (which is <td>). The
TN> following does not work:

TN> //span[@class="h2"]/../td
Try

//td[child::span[@class='h2']]

--
Stuart
If love is blind, why is lingerie so popular?

 
Reply With Quote
 
 
 
 
Soren Kuula
Guest
Posts: n/a
 
      02-02-2004
Timo Nentwig wrote:
> Hi!
>
> I want to select the parent of <span class="h2"> (which is <td>). The
> following does not work:
>
> //span[@class="h2"]/../td


Is that XSL ?

I think it's because you are not allowed to select ancestor nodes
(creating loops) - on the other hand, it's OK to evaluate (value-of) them.

But as somebody else suggested, the fix is instead to specifially select
the parents whose children have the desired properties.

Soren
--
Fjern de 4 bogstaver i min mailadresse som er indsat for at hindre s...
Remove the 4 letter word meaning "junk mail" in my mail address.

 
Reply With Quote
 
C. M. Sperberg-McQueen
Guest
Posts: n/a
 
      02-02-2004
Timo Nentwig <> writes:

> Hi!
>
> I want to select the parent of <span class="h2"> (which is <td>). The
> following does not work:
>
> //span[@class="h2"]/../td


Because it selects each sibling of the span element which is
named td.

If you want the parent whatever it's name, try

//span[@class="h2"]/..

If you want the parent if and only if it's named 'td', try

//span[@class="h2"]/parent::td

I hope this helps.

-C. M. Sperberg-McQueen

 
Reply With Quote
 
Patrick TJ McPhee
Guest
Posts: n/a
 
      02-02-2004
In article <bvlj15$te09t$>,
Timo Nentwig <> wrote:

% I want to select the parent of <span class="h2"> (which is <td>). The
% following does not work:

% //span[@class="h2"]/../td

This is looking for siblings of the span called td. This should do what
you want:

//span[@class="h2"]/..

--

Patrick TJ McPhee
East York Canada

 
Reply With Quote
 
Dimitre Novatchev
Guest
Posts: n/a
 
      02-02-2004

"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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
select gridview row without using select button? =?Utf-8?B?RGFiYmxlcg==?= ASP .Net 5 02-27-2009 02:56 AM
select.select and socket.setblocking Laszlo Nagy Python 12 01-03-2009 09:25 PM
select.select() on windows jas Python 4 10-27-2005 11:10 AM
Selection from One SELECT changes selected option of another SELECT? J. Hall HTML 2 04-21-2004 05:36 PM
select of select box will select multiple in another box palmiere Javascript 1 02-09-2004 01:11 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57