Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XPath problem

Status
Not open for further replies.

npongar

Programmer
Oct 3, 2003
12
CA
Hi, I have just recently started using XPath and have run into a problem I can't solve.

I am trying to get the row that some inputted text is in. The Xpath expression and the code I am testing it on are shown below. The first part of the expression returns the td element that contains "identifying text", but when I add the ancestor::tr part it returns nothing. Any help would be appreciated.


xpath=//*[contains(text(),'identifying text')]/ancestor::tr


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"
<html xmlns=" >
<head><title>
Untitled Page
</title></head>
<body>
<form name="form1" method="post" action="page1.aspx" id="form1">
<div>
<table id="table1" cols="3">
<tr>
<td style="width: 140px">
identifying text</td>
<td style="width: 122px">
<input name="TextBox2" type="text" id="TextBox2" /></td>
<td style="width: 154px">
</td>
</tr>
</table>
</div>

<div>
</div></form>
</body>
</html>
 
>xpath=//*[contains(text(),'identifying text')]/ancestor::tr
[tt]//*[contains(text(),'identifying text')]/ancestor::[red]*[local-name()='tr'][/red][/tt]
 
Thanks for the reply tsuji. When I try to use the function it says it isn't implemented. Is this an Xpath 1.0 vs 2.0 problem?
 
[1] There could be minor complication in xslt 2 with that exact form. You can change it to this and it would be cross-version applicable.
>[self]//*[contains(text(),'identifying text')]/ancestor::*[local-name()='tr']
[tt]//*[contains([blue].[/blue],'identifying text')]/ancestor::*[local-name()='tr'][/tt]

[2] >When I try to use the function it says it isn't implemented.
It is not the error that I know of for the path, both versions support contains() xpath function. The error should be provoked by something else.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top