39

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.

Martijn Pieters
  • 963,270
  • 265
  • 3,804
  • 3,187
edsamiracle
  • 713
  • 2
  • 12
  • 26

4 Answers4

54

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]

Jiri Kremser
  • 11,859
  • 5
  • 42
  • 70
  • 1
    for Ms SQL Server using .exist("xpath") - it shows error XQuery [dvEd.EnrichmentData.exist()]: The XQuery syntax 'union' is not supported. – Philipp Munin Jul 13 '16 at 20:02
42

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

toniedzwiedz
  • 16,953
  • 8
  • 83
  • 122
CosminO
  • 4,802
  • 6
  • 26
  • 48
4

I don't think you need an "or" here. You just need to translate both operands to lower-case, rather than only translating one of them.

Michael Kay
  • 147,186
  • 10
  • 83
  • 148
3

As noted by Michael Kay, no or is necessary.

Simply use:

PeopleList/Row
  [contains(translate(@LastName, 
                     'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
                     'abcdefghijklmnopqrstuvwxyz'), '" 
+
           translate(txtSearch.value,
                     'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
                     'abcdefghijklmnopqrstuvwxyz')'" 

+ "')]");
Dimitre Novatchev
  • 235,605
  • 26
  • 291
  • 421