可以在xpath中使用xpath吗?

可以在xpath中使用xpath吗?,xpath,html-table,Xpath,Html Table,我有一张这样的桌子: <table> <thead> <tr> <th data-th-key="col1"> <span> Foo </span> </th> <th data-th-key="col2"> <span> Bar </span> </th> </tr

我有一张这样的桌子:

<table>     
    <thead>
        <tr>
          <th data-th-key="col1"> <span> Foo </span>  </th>
          <th data-th-key="col2"> <span> Bar </span>  </th>
        </tr>
    </thead>
        <tbody>
            <tr>   
        <td>
                <div>
              <input data-model-key="col1">    
            </div>
        </td>
        <td>
            <div>
              <input data-model-key="col2">    
            </div>
        </td>
      </tr>
        </tbody>
</table>    
Xpath二:

//table//tbody//tr//td//div//input[@data-model-key='col1']

因此,我想用Xpath值替换第二个表达式中的col1值。

您可以编写如下表达式

//table//tbody//tr//td//div//input[@data-model-key = //table//thead//span[translate(normalize-space(.),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='foo']/parent::th/@data-th-key]

是的,这是可能的和有意义的,并选择其
数据模型键
等于该
数据th键
属性的输入(或输入)。

查看此页上的第一个、最后一个和索引是否也有帮助:?
//table//tbody//tr//td//div//input[@data-model-key = //table//thead//span[translate(normalize-space(.),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='foo']/parent::th/@data-th-key]