如何合并(分组)xpath结果

时间:2017-07-22 16:17:41

标签: xpath xpath-1.0

我有下表

<table>
<tbody>
    <tr>
        <td>First Row | First Column</td>
        <td>First Row | Second Column</td>
    </tr>
    <tr>
        <td>Second Row | First Column</td>
        <td>Second Row | Second Column</td>
    </tr>
    <tr>
        <td>Third Row | First Column</td>
        <td>Third Row | Second Column</td>
    </tr>
    <tr>
        <td>Forth Row | First Column</td>
        <td>Forth Row | Second Column</td>
    </tr>
    <tr>
        <td>Fifth Row | First Column</td>
        <td>Fifth Row | Second Column</td>
    </tr>
    <tr>
        <td>Sixth Row | First Column</td>
        <td>Sixth Row | Second Column</td>
    </tr>
</tbody>

我需要使用xpath expresion来接收分组的3条记录:

  1. 第一行|第二列,第二行|第二栏
  2. 第三排|第二栏,Forth Row |第二栏
  3. 第五行|第二列,第六行|第二栏
  4. 如何仅使用xpath 1.0来实现这一目标?

1 个答案:

答案 0 :(得分:0)

在这里, xpath 表达式:

concat(//tr[1]/td[2], ' , ', //tr[2]/td[2], codepoints-to-string(10), //tr[3]/td[2], ' , ', //tr[4]/td[2], codepoints-to-string(10), //tr[5]/td[2], ' , ', //tr[6]/td[2])

以上将返回以下字符串:

First Row | Second Column , Second Row | Second Column
Third Row | Second Column , Forth Row | Second Column
Fifth Row | Second Column , Sixth Row | Second Column