I write some XPath queries and focus on one. Below is an example of the document that I am using:
<dept-db>
<dept>
<name>HR</name>
<emp>
<name>John</name>
<country>USA</country>
</emp>
<emp>
<name>Chris</name>
<country>USA</country>
</emp>
</dept>
<dept>
<name>Technology</name>
<emp>
<name>Oliver</name>
<country>UK</country>
</emp>
<emp>
<name>Emily</name>
<country>USA</country>
</emp>
</dept>
</dept-db>
What I want to achieve is to get all the employees whose country appears more than twice in the document. I started with a simpler query, namely one that should find duplicates:
doc("emp.xml")//emp[preceding::emp/country=./country or following::emp/country=./country]
although it returns all employees (obviously, Oliver should not be listed among the results).
I am new to XPath and not quite sure if I will get the point concept. qualifier right. I expect that the above query will behave as follows: iterating over the set of emp nodes and for each check if there is an employee with the same country among the nodes that appear above and below the current one in the document.
( GROUP BY) ( ?). , eXide ( eXist-db 2.1) XQuery 3.0 .