使用Xpath,找到包含id =“userid”的输入框的最左边的表节点

时间:2011-03-29 22:19:47

标签: html xml xhtml xpath

我尝试了几种不同的变体,但我似乎无法做到这一点。鉴于html:

<html>
<body>
<table>
   <tr>
       <td>
           <table>                               <-- I want this table
              <tr>
                  <td><input type="text" id="foo"/></td>
              </tr>
           </table>
       </td>
   </tr>
</table>
</body>
</html>

我想找到内表。

我尝试过// table / * / input [@ id ='foo']但是我找不到正确的东西 - 没有人能快速解决这个问题吗? : - )

非常感谢!

2 个答案:

答案 0 :(得分:3)

其他方法:

//table[not(.//table)][.//input[@id='foo']]

答案 1 :(得分:2)

未测试:

//input[@id='foo']/ancestor::table[1]