473,385 Members | 1,782 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to select parent?

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
Jul 20 '05 #1
5 1605
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?

Jul 20 '05 #2
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.

Jul 20 '05 #3
Timo Nentwig <tc*@spamgourmet.com> 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

Jul 20 '05 #4
In article <bv************@ID-18956.news.uni-berlin.de>,
Timo Nentwig <tc*@spamgourmet.com> 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
pt**@interlog.com
Jul 20 '05 #5

"Timo Nentwig" <tc*@spamgourmet.com> wrote in message
news:bv************@ID-18956.news.uni-berlin.de...
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

Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jtwright | last post by:
I've got a view that creates a parent child relationship, this view is used in Analysis Services to create a dimension in a datastore. This query tends to deadlock after about 10 days of running...
2
by: Joachim Bauer | last post by:
I'm using the code below to display a menu that opens when the mouse goes over the main menu item (try it in your browser to understand the behaviour). It uses "position:absolute" and a switch...
4
by: Bart van Deenen | last post by:
Hi all I have a script where I dynamically create multiple inputs and selects from a script. The inputs and selects must have an associated onchange handler. I have the script working fine on...
2
by: tomek.romanowski | last post by:
Hello everybody ! I'm looking for a while some way to select subnode element by its position within whole document rather then in its parent. Let's consider following xml: <root> <parent>...
5
by: Bubba | last post by:
I have a dynamic pulldown list (ASP with javascript) that when a user picks a state, the corresponding counties for that state appear in a dynamic second pulldown list. When I submit the form, the...
3
by: Pascal Ehlert | last post by:
Hi group! After my first post a few days ago and your advice not to use the Prototype Framework (which indeed was a good idea! ;-)) I rewrote my script for dynamic select lists. This is what it...
4
by: jmDesktop | last post by:
I have searched everywhere and tried several things. I have a treeview with and want to be able to only select a parent node. For example: root //don't want to drag this -parent1 //yes, drag...
0
by: Dave Mathew | last post by:
I'm in the process of building some navigation for a website. I would like to use the capabilities of the sitemap in asp.net but have ran into some styling/usability issues in the past using just...
3
by: imoddedu | last post by:
In this code, is it do-able to make a form that is a select and if one option is selected, then 2 more forms are displayed? <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.