XPath contains one of multiple values

后端 未结 3 1965
自闭症患者
自闭症患者 2020-12-05 13:31

I have simple xpath

 /products/product[contains(categorie,\'Kinderwagens\')] 

It works but now how do I filter on multiple categorie values

相关标签:
3条回答
  • 2020-12-05 13:53

    You can pass the multiple text as like below

    //a[contains(text(),'JB-' | 'ABC')]
    
    0 讨论(0)
  • 2020-12-05 14:03

    Will this work?

    /products/product[contains(categorie,'Kinderwagens') or contains(categorie,'Wonderwagens')]
    

    There is a similar question here

    0 讨论(0)
  • 2020-12-05 14:07

    Do you really want contains()? Very often, people use contains() to test whether a node contains a value when they should be using "=". The difference is that if the categorie element has the string value 'Kinderwagens', then categorie = 'wagens' is false but contains(categorie, 'wagens') is true.

    If you actually intended '=', then in XPath 2.0 you can write [categorie = ('Kinderwagens', 'Wonderwagens')]. If you're still using XPath 1.0, you need two separate comparisons with an 'or'.

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