0

We are trying to get all the nodes containing a property value starting from below string "/content/retail/mx/mexico/es/" . For this we have written a AEM XPath query:

/jcr:root/content/retail/mx/mexico//* 
[
jcr:contains(., '/content/retail/mx/mexico/es/' ) 
] 

We are getting the results but problem is we are getting results of those nodes also who contains property value "/content/retail/mx/mexico/es_mexico". It seems XPath doesn't consider the last "/" in path.

Is there anyway to escape so that we don't get the results of nodes having es_mexico?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
user2142786
  • 1,484
  • 9
  • 41
  • 74
  • I think this is a duplicate question. I think you also better go with jcr:like. See my answer at https://stackoverflow.com/questions/49694248/jcr-sql-contains-function-doesnt-escape-special-characters/49798681#49798681 – Alexander Berndt Jun 06 '18 at 18:59
  • Possible duplicate of [JCR-SQL - contains function doesn't escape special characters?](https://stackoverflow.com/questions/49694248/jcr-sql-contains-function-doesnt-escape-special-characters) – Alexander Berndt Jun 06 '18 at 18:59

1 Answers1

1

Normally in XPath, contains() tests for substring containment.

If you want string equality instead, use the = equality operator with the strings as arguments.

Furthermore, your XPath,

/jcr:root/content/retail/mx/mexico//* 
[
jcr:contains(., '/content/retail/mx/mexico/es/' ) 
] 

has a number of notable aspects:

  1. You're using a special jcr:contains() function rather than the XPath contains(). Why?
  2. You're testing the string value . of all elements //* beneath /jcr:root/content/retail/mx/mexico/. This will likely result in several selections of ancestor elements in addition to child elements – perhaps not what you expect.
  3. You're testing string content against an XPath-like literal string. Why?
kjhughes
  • 106,133
  • 27
  • 181
  • 240