Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'

like image 253
edsamiracle Avatar asked Sep 19 '12 03:09

edsamiracle


People also ask

What does /* mean in XPath?

/* selects the root element, regardless of name. ./* or * selects all child elements of the context node, regardless of name.

How do I combine two attributes in XPath?

The syntax for locating elements through XPath- Multiple Attribute can be written as: //<HTML tag>[@attribute_name1='attribute_value1'][@attribute_name2='attribute_value2]

What is the difference between '/' and in XPath?

Difference between “/” and “//” in XPathSingle slash is used to create absolute XPath whereas Double slash is used to create relative XPath. 2. Single slash selects an element from the root node. For example, /html will select the root HTML element.


2 Answers

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.

like image 168
Dimitre Novatchev Avatar answered Oct 13 '22 11:10

Dimitre Novatchev


You can use start-with function and not function. Reference:

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

xmlTempResultSearch = xmlResidentListDisplay.selectNodes("//PeopleList/Row[not(starts-with(@LastName,'"+ txtSearch.value +"'))]");
like image 29
swemon Avatar answered Oct 13 '22 10:10

swemon