Two conditions using OR in XPATH

前端 未结 4 730
没有蜡笔的小新
没有蜡笔的小新 2020-12-01 13:42

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

var xmlTempResultSearch = xmlResidentListDisplay.selectNodes(
         


        
相关标签:
4条回答
  • 2020-12-01 14:30

    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

    0 讨论(0)
  • 2020-12-01 14:37

    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]

    0 讨论(0)
  • 2020-12-01 14:41

    As noted by Michael Kay, no or is necessary.

    Simply use:

    PeopleList/Row
      [contains(translate(@LastName, 
                         'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
                         'abcdefghijklmnopqrstuvwxyz'), '" 
    +
               translate(txtSearch.value,
                         'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
                         'abcdefghijklmnopqrstuvwxyz')'" 
    
    + "')]");
    
    0 讨论(0)
  • 2020-12-01 14:42

    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.

    0 讨论(0)
提交回复
热议问题