end-user
end-user

Reputation: 2947

How can I return a specific node when there are different selection criteria/depths with xpath?

Given the following XML,

<root>
    <property>
        <programs>
            <program>1</program>
            <program>5</program>
        </programs>
        <tool>
        </tool>
    </property>
    <property>
        <tool>
            <programs>
                <program>1</program>
                <program>2</program>
            </programs>
        </tool>
    </property>
</root>

how would I write an XPath expression to return a collection containing the "property" nodes when program=1? I think I want to write something like "give me all the property nodes when self or a descendant contains programs[program=1]", but can't get it to just give me the "property" nodes...

Upvotes: 1

Views: 108

Answers (1)

Mads Hansen
Mads Hansen

Reputation: 66783

property[.//programs/program=1]

Selects the property elements that contain descendant programs elements that contain a child program element who's value is 1.

Upvotes: 1

Related Questions