all groups > dotnet xml > august 2007 >
You're in the

dotnet xml

group:

How to select parent based on a child value via XPath?


How to select parent based on a child value via XPath? Art
8/29/2007 11:38:01 AM
dotnet xml:
Here is sample XML:

<Root>
<A>
<B>
<C>Yes</C>
</B>
</A>
:
<A>
<B>
<C>No</C>
</B>
</A>
</Root>

There can be any # of nested <A> with values of either Yes or No. I would
like to select <A> node(s) based on value of <C>. In pseudo code:

Give me all <A> where <C> = "Yes" (or "No). So far I was able to select all
"Yes" (or "No") but these are <C> nodes and need their grandparents.
Re: How to select parent based on a child value via XPath? Peter Flynn
8/29/2007 11:25:22 PM
[quoted text, click to view]

In XPath, //A[descendant::C='Yes'] or possibly //C[.='Yes']/ancestor::A

///Peter
--
XML FAQ: http://xml.silmaril.ie/
AddThis Social Bookmark Button