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

前端 未结 3 981
甜味超标
甜味超标 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条回答
  •  -上瘾入骨i
    2020-12-01 09:54

    Although I like Mads solution: Here is another approach for XPath 2.0:

    /bookstore/book[
                     tokenize(@class," ")="foo" 
                     and not(tokenize(@class," ")="bar")
                   ]
    

    Please note that the following expressions are both true:

    ("foo","bar")="foo" -> true
    ("foo","bar")="bar" -> true
    

提交回复
热议问题