I am trying to write a Xquery to search an xml from the database which has any Abc node having R="3" and it should have any corresponding XYZ node which has attr="106"
<Abc ID="X" Src="D" R="1">
<XYZ ID="4101847" attr="106">
</XYZ>
<XYZ ID="Y" attr="105">
</XYZ>
</Abc>
<Abc ID="Z" Src="G" R="73">
</Abc>
<Abc ID="P" Src="B" R="3">
<XYZ ID="Q" attr="106">
</XYZ>
<XYZ ID="R" attr="101">
</XYZ>
<XYZ ID="" attr="100">
</XYZ>
</Abc>
I tried below query
cts:element-query(
fn:QName("namespace","Parent"), cts:and-query(
(
cts:element-attribute-value-
query(fn:QName("namespace","Abc"),xs:QName("R"),"3"),
cts:element-attribute-value-
query(fn:QName("namespace","XYZ"),xs:QName("attr"),"106")
)
)
)
It gives me result even if any other Abc has an XYZ node matching attr as 106