如何在XPath中使用like? [英] How to use like in XPath?

查看:512
本文介绍了如何在XPath中使用like?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a page that searches with filters. I have this code for example,

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

这将选择不等于在txtSearch文本框中输入的姓氏的数据,然后将其从结果集中删除,以便对其进行过滤以使其等于txtSearch文本框中的姓氏.

This selects the data that is not equal to the LastName inputted on the txtSearch textbox and then removes them from the result set so that its filtered to equal the last name on the txtSearch textbox.

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

My problem with this code is that it should be equal (=) to the txtSearch.value, what I want is that I want the result set LIKE the txtSearch.value. What happens on my page is that when I type 'santos' on the txtSearch textbox, its result set is all those last names with 'santos'. But when I type 'sant', nothing appears. I want the same result set with 'santos' because it all contains '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表达式轻松表示它**:

There is no **ends-with() in XPath 1.0, but it can easily be expressed with this XPath 1.0 expression**:

substring($s, string-length($s) - string-length($t) +1) = $t

恰好在字符串$s以字符串$t结尾时,

true().

is true() exactly when the string $s ends with the string $t.

这篇关于如何在XPath中使用like?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆