I have a document in Marklogic database and would like to retain product node where rating code is either "Agree" or "Strongly Agree" using XQuery, other nodes need to be removed.
I have tried few options to find node with appropriate attribute and delete others but no luck something like
let $rating5Exists := fn:exists($doc//rating[@code eq "Strongly Agree"])
let $rating4Exists := fn:exists($doc//rating[@code eq "Agree"])
<products>
<product>
<product-id>9039034</product-id>
<status>
<rating code="Strongly Agree">
<count>5</count>
</rating>
</status>
</product>
<product>
<product-id>9039034</product-id>
<status>
<rating code="Agree">
<count>4</count>
</rating>
</status>
</product>
<product>
<product-id>9039034</product-id>
<status>
<rating code="Neither Agree nor Disagree">
<count>3</count>
</rating>
</status>
</product>
<product>
<product-id>9039034</product-id>
<status>
<rating code="Disagree">
<count>2</count>
</rating>
</status>
</product>
<product>
<product-id>9039034</product-id>
<status>
<rating code="Strongly Disagree">
<count>1</count>
</rating>
</status>
</product>
</products>
Expected output:
<products>
<product>
<product-id>9039034</product-id>
<status>
<rating code="Strongly Agree">
<count>5</count>
</rating>
</status>
</product>
<product>
<product-id>9039034</product-id>
<status>
<rating code="Agree">
<count>4</count>
</rating>
</status>
</product>
</products>