通过 xpath 选择多个索引的更好方法


Better way to Select Multiple indexes via xpath

我尝试在复杂的表格结构中选择"tr"内的多个"td"。

$name = $sxml->xpath("
                //table[@cellspacing=0 and @cellpadding=2 and @class='mn2']
                    /tr[not(contains(@class, 'mn'))]/td[2] 
                | 
                //table[@cellspacing=0 and @cellpadding=2 and @class='mn2']
                        /tr[not(contains(@class, 'mn'))]/td[5]
                |
                //table[@cellspacing=0 and @cellpadding=2 and @class='mn2']
                        /tr[not(contains(@class, 'mn'))]/td[7]
                ");

一切都很好,我得到了我想要的,但这似乎有点矫枉过正。如何选择多个"td",例如"td[2,5,7]"而不是使用联合表达式"|"?

它可以在

or的帮助下完成:

//table[@cellspacing=0 and @cellpadding=2 and @class='mn2']
    /tr[not(contains(@class, 'mn'))]/td[position()=2 or position()=5 or position()=7]