0

I'm trying to figure out how to selected all of the Suppliers who do not have TV as a product. I'd also like an explanation on the differences of your answer and what I have. I have the following query written:

SELECT XMLColumn.query('/SuppliersList/Supplier/Product[not(@name="TV")]/..')
FROM Tb_XPathQueryTable

This is my table, plus a bunch of other Suppliers.

<SuppliersList>
  <Supplier name="Joe">
    <City>Paris</City>
    <Product name="Airplane"/>
    <Product name="Milk"/>
    <Product name="TV"/>
    <Product name="Orange"/>
 </Supplier>

1 Answer 1

2

On your xpath you are selecting first the Product and then going to its parent, so it will match the specified example (because the TV Product has siblings that match the same parent).

This xpath should work:

/SuppliersList/Supplier[not(Product[@name="TV"])]

As you can see, we are selecting Supplier which doesn't contain a Product child with name="TV"

Sign up to request clarification or add additional context in comments.

1 Comment

It does work, thanks! Also thank you for explaining it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.