如何在XPath中使用?

eds*_*cle 12 xpath operator-keyword

我有一个用过滤器搜索的页面.我有这个代码,例如,

xmlTempResultSearch = xmlResidentListDisplay.selectNodes("//PeopleList/Row[@LastName != '"+txtSearch.value+"']");
xmlTempResultSearch.removeAll();
Run Code Online (Sandbox Code Playgroud)

这将选择与txtSearch文本框中输入的LastName不相等的数据,然后将其从结果集中删除,以使其过滤为等于txtSearch文本框上的姓氏.

我这段代码的问题是,它应该是等号(=)到txtSearch.value的,我想是我想要的结果集LIKEtxtSearch.value.在我的页面上发生的事情是,当我santos在txtSearch文本框中键入' '时,其结果集是所有带有' santos'的姓氏.但是当我输入' sant'时,什么都没有出现.我想要与' santos' 相同的结果集,因为它包含'sant'

Dim*_*hev 15

您可以使用所有XPath(1.0)字符串函数.如果您有XPath 2.0,那么您甚至可以使用RegEx.

contains()

starts-with()

substring()

substring-before()

substring-after()

concat()

translate()

string-length()

ends-with()XPath 1.0中没有**,但可以使用此XPath 1.0表达式轻松表达**:

substring($s, string-length($s) - string-length($t) +1) = $t
Run Code Online (Sandbox Code Playgroud)

true()什么时候的字符串$s与字符串结尾$t.


swe*_*mon 5

您可以使用 start-with 函数而不是函数。参考:

http://www.w3schools.com/xpath/xpath_functions.asp

xmlTempResultSearch = xmlResidentListDisplay.selectNodes("//PeopleList/Row[not(starts-with(@LastName,'"+ txtSearch.value +"'))]");
Run Code Online (Sandbox Code Playgroud)


Khu*_* Vu 4

您可以使用 XPath 的 contains() 函数:

xmlTempResultSearch = xmlResidentListDisplay.selectNodes("//PeopleList/Row[not(contains(@LastName,'"+txtSearch.value+"'))]");
Run Code Online (Sandbox Code Playgroud)