English 中文(简体)
xpath 选择列内有几个特定值的 tr
原标题:xpath to select tr that has several specific values in the columns
  • 时间:2012-05-23 19:44:09
  •  标签:
  • xpath

我有一个有多个行的表格, 我正试图使用 xpath 来找到包含每列中具体值的一行。 例如, 我期望在第 1 栏、 第 2 栏中的“ 巴 ” 和 第 3 栏中的“ 巴 ” 中出现“ 发泡 ” 。

我可以用什么xpath来获得一个行,该行包含这些特定列中的这三个具体值?

例如,鉴于下表,我希望只返回一行,其预期列内有三个预期值。

<table>
  <tr><td>foo</td><td>bar</td><td>xxx</td></tr>
  <tr><td>xxx</td><td>bar</td><td>baz</td></tr>
  <tr><td>foo</td><td>bar</td><td>baz</td></tr>
  <tr><td>bar</td><td>baz</td><td>foo</td></tr>
  <tr><td>foo</td><td>xxx</td><td>baz</td></tr>
</table>
最佳回答

这样做可以(假设 able 元素是当前上下文节点) :

    tr[(td[1] =  foo ) and (td[2] =  bar ) and (td[3] =  baz )]

td[1] 选择第一个 td child, td[2] the second, etc.]。然后您将条件与 结合起来。

问题回答

我敢肯定有更快的方法 来得到你想要的东西, 通过不使用xpath。

/td[1][text()=fo]和td[2][text()=bar]和td[3][text()=baz]]

您可以在搜索时使用 directorypath[name="value"]...





相关问题
VTD XML inner XPath Expressions

I have a xml file for example like this <root> <test> <bla>test1</bla> </test> <test> <bla>test2</bla> </test> <test> </test&...

C# XML adding/copying

With the following XML I am trying to copy and add to another XML but I haven t used the C# XML document objects before. So here is the XML <config> <configXML> <Connections&...

Filter SQL queries on the XML column using XPath/XQuery

I m having a table with one XML column. I d like to filter out the rows where a specific attribute in the XML match a string, essentially doing a WHERE or HAVING. The table looks something like this ...

Python XPath Result displaying only []

Hey I have just started to use Python recently and I want to use it with a bit of xPath, the thing is when I print the result of the query I only get [] and I don t know why =S import libxml2, ...

热门标签