我有一个使用过滤器进行搜索的页面。例如,我有这个代码,
xmlTempResultSearch = xmlResidentListDisplay.selectNodes("//PeopleList/Row[@LastName != '"+txtSearch.value+"']");
xmlTempResultSearch.removeAll();
这会选择不等于
txtSearch
文本框中输入的姓氏的数据,然后将其从结果集中删除,以便过滤后使其等于 txtSearch
文本框中输入的姓氏。
我对这段代码的问题是它应该等于(=)
txtSearch
.value,我想要的是我想要结果集LIKE txtSearch.value
。我的页面上发生的情况是,当我在 txtSearch 文本框中输入“santos
”时,其结果集是所有带有“santos
”的姓氏。但是当我输入“sant
”时,什么也没有出现。我想要与 'santos
' 相同的结果集,因为它都包含 'sant'
您可以使用所有 XPath (1.0) 字符串函数。如果您有可用的 XPath 2.0,那么您甚至可以使用 RegEx。
contains()
starts-with()
substring()
substring-before()
substring-after()
concat()
translate()
string-length()
ends-with()
,但可以很容易地用这个 XPath 1.0 表达式来表达:
substring($s, string-length($s) - string-length($t) +1) = $t
正是
true()
当字符串 $s
以字符串 $t
结尾时。
您可以使用 start-with 函数,也可以不使用函数。参考:
http://www.w3schools.com/xpath/xpath_functions.asp
xmlTempResultSearch = xmlResidentListDisplay.selectNodes("//PeopleList/Row[not(starts-with(@LastName,'"+ txtSearch.value +"'))]");
您可以使用 XPath 的 contains() 函数:
xmlTempResultSearch = xmlResidentListDisplay.selectNodes("//PeopleList/Row[not(contains(@LastName,'"+txtSearch.value+"'))]");