Search code examples
xmlxpathnodesjcr

Finding parent nodes based on double value of child node in XPath


I'm writing an XPath query to run against my JCR. I must retrieve all parent nodes of a certain type in a certain directory that also have a specific child node with a double property within a given range.

I've successfully filtered the directory and type of the parent but am having trouble adding a constraint to the child nodes. Additionally, the below code will return the child nodes but I want the parent nodes.

/jcr:root/content//element(*, parentnode:type)[parentnode:property = 'value']/element(*, childnode:type)[childnode:property > 0 and childnode:property < 5]

My current code gives me an empty set. I expect to receive the list of parentnode:type nodes that fit my constraints.


Solution

  • Add "/.." to select the node before the current one.

    /jcr:root/content//element(, parentnode:type)[parentnode:property = 'value']/element(, childnode:type)[childnode:property > 0 and childnode:property < 5]/..