Search code examples
xpathaemquery-builderjcr

How to fetch multiple cq pages using Xpath based on page's property


I have two cq page and I want to retrive these two using jcr:title property using XPATH. The below query is working fine for single.

/jcr:root/content/test//element(*, cq:Page)[((jcr:like(jcr:content/@jcr:title, dell)))]

But I want to excuate it for multiple items. I have tried with following option but it is not working

/jcr:root/content/test//element(*, cq:Page)[((jcr:like(jcr:content/@jcr:title, [dell,samusng])))]

Could anyone help me to write xpath query?


Solution

  • As rakhi4110 already mentioned in the comment, you can combine multiple where clauses with an or just like in SQL. Though I think you either want exact matches or use jcr:containts instead of jcr:like.

    Exact match:

    /jcr:root/content/test//element(*, cq:Page) [jcr:content/@jcr:title='dell' or jcr:content/@jcr:title='samsung']
    

    Contains:

    /jcr:root/content/test//element(*, cq:Page) [jcr:contains(jcr:content/@jcr:title, 'dell') or jcr:contains(jcr:content/@jcr:title, 'samsung')]
    

    Or if you really want to use jcr:like which, as in SQL, uses % for wildcard:

    /jcr:root/content/test//element(*, cq:Page) [jcr:like(jcr:content/@jcr:title, '%dell%') or jcr:like(jcr:content/@jcr:title, '%samsung%')]