How can I select an element with multiple classes with Xpath?

前端 未结 3 985
甜味超标
甜味超标 2020-12-01 09:27

In the above xml sample I would like to select all the books that belong to class foo and not in class bar by using xpath.



        
3条回答
  •  庸人自扰
    2020-12-01 09:51

    By padding the @class value with leading and trailing spaces, you can test for the presence of " foo " and " bar " and not worry about whether it was first, middle, or last, and any false positive hits on "food" or "barren" @class values:

    /bookstore/book[contains(concat(' ',@class,' '),' foo ')
            and not(contains(concat(' ',@class,' '),' bar '))]
    

提交回复
热议问题