0

I am trying to extract the concatenated cells from a HTML table for each row using XPath. For example, if I have a table like

<table>
<tr><th>FirstName</th><th>LastName</th><th>Title</th></tr>
<tr><td>First1</td><td>Last1</td><td>Title1</td></tr>
<tr><td>First2</td><td>Last2</td><td>Title2</td></tr>
<tr><td>First3</td><td>Last3</td><td>Title3</td></tr>
</table>

I want to extract this data so that I get the full name of the person in each row

First1 Last1
First2 Last2
First3 Last3

I can get each column separately and then merge them in my code later, but prefer to get this done in a single XPath query. I have tried to use concat, but can't figure out where to use the concat.

Thanks in advance.

Rasika
  • 1,980
  • 13
  • 19
  • Can you post the code you tried? – Kuzgun Jan 29 '14 at 15:49
  • I tried concat(//tr/td[1]/text(),' ',//tr/td[2]/text()) and several other combinations. The above one gives me just the first row, but not all rows. None of the other combinations were syntactically correct. – Rasika Jan 29 '14 at 15:53

1 Answers1

0

The concatenation you tried only concats the xpath, not the nodes. If you want to select more than one nodes, you should use | between them.

//tr//td[1] | //tr//td[2]
Kuzgun
  • 4,649
  • 4
  • 34
  • 48