1

What is the xpath to use if I want to get the nodes that have a certain number of child nodes of a tag type?

<table>
  <tr>
     <td></td>
     <td></td>
     <td></td>
  </tr>
  <tr>
     <td></td>
  </tr>
  <tr>
     <td></td>
     <td></td>
     <td></td>
     <p></p>
   </tr>
  <tr>
     <td></td>
     <p></p>
  </tr>
</table>

For example, in the markup above, I want to get <tr> tags that have 3 <td> children. The xpath should return the 1st and 3rd <tr>.

4

1 に答える 1

2

たとえば、count ステートメントに基づいて条件を試すことができます。

/table/tr[count(td)=3]
于 2013-05-28T08:51:49.897 に答える