Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two conditions using OR in XPATH

I have a textbox, 'txtSearch'. I am using it to search people by Last Name. this is my code.

var xmlTempResultSearch = xmlResidentListDisplay.selectNodes(     "//PeopleList/Row[contains(translate(@LastName, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '" +     txtSearch.value + "')]"); 

This code selects all last names in the XML like the text input in the txtSearch textbox.

This translates all uppercase letters to lowercase letters.

So if I am searching for 'Dorosan', if I type 'doro', it retrieves the correct person because it translated the 'D' to 'd'. But when I type 'Doro', it doesn't retrieve the correct person.

I'm wondering if I can have two conditions in an XPATH, and how? I want to be able to translate all uppercase to lowercase, OR translate all lowercase to uppercase.

like image 787
edsamiracle Avatar asked Sep 24 '12 09:09

edsamiracle


People also ask

How do I give two properties 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]

Can we use and condition in XPath?

Using OR & AND This means that any one condition should be true to find the element. In the below XPath expression, it identifies the elements whose single or both conditions are true.

How write multiple contains in XPath?

$xml->xpath("(//person)[firstname[contains(., 'Kerr')]]"); then it works fine.

How do you write conditional XPath expression?

To define an XPath expression that checks if a string element is empty, you must use the operator != . This example shows how to define an XPath expression that evaluates to true when a repeating element, which is referred to as a sequence, is empty. The effective Boolean value of an empty sequence is false.


2 Answers

and and or are allowed inside the condition: [here]. Or you may also use multiple paths in one XPath expression using the pipe sign.

//PeopleList/Row[c1] | //PeopleList/Row[c2]

like image 105
Jiri Kremser Avatar answered Sep 23 '22 00:09

Jiri Kremser


you can use or / and inside [....]

Example:

//*[contains('abc') or contains('def') or text()='abcdef'] 

More info about operators: http://www.w3schools.com/xpath/xpath_operators.asp

like image 34
CosminO Avatar answered Sep 21 '22 00:09

CosminO