Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

operator keyword - How to use like in XPath?

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

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

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.

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'

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use all of the XPath (1.0) string functions. If you have XPath 2.0 available, then you can even use RegEx.

contains()

starts-with()

substring()

substring-before()

substring-after()

concat()

translate()

string-length()

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[4] html - How to create even cell spacing within a

1.4m articles

1.4m replys

5 comments

57.0k users

...