4

Viewing source, I have table data formatted exactly like this:

  <tr class="even">
    <td>apple</td>
    <td>pear</td>
    <td>orange</td>
    </tr>
    <tr class="odd">
    <td>apple</td>
    <td>pear</td>
    <td>&nbsp</TD>
    </tr>
  <tr class="even">
    <td>apple</td>
    <td>pear</td>
    <td>orange</td>
    </tr>

How would I go about not matching the <td> containing &nbsp in all rows where it occurs?

Zack
  • 43
  • 3

1 Answers1

5

The entity &nbsp; isn't something that XPath knows about -- it is best to use its equivalent (self-defining) character entity &#xA0;

To select all td s of a top element - table, that do not contain &nbsp; use:

 /table/tr/td[not(contains(., '&#xA0;'))]

To select all rows of this table such that none of their td children contains &nbsp; use:

 /table/tr[not(td[contains(., '&#xA0;')])]

To select all td children of all rows of this table such that none of their td children contains &nbsp; use:

 /table/tr[not(td[contains(., '&#xA0;')])]/td
Dimitre Novatchev
  • 230,371
  • 26
  • 281
  • 409