How to create Conditional Xpath statement?

patel picture patel · Oct 11, 2011 · Viewed 15.9k times · Source

I want to select xml node with conditional Xpath like-

xmlnode.SelectSingleNode("if (ns:substanceAdministration/ns:consumable/@typeCode == UNK) then evaluateThisXpath else evaluateOtherXpath")

my concern is-

<drugID code="UNK">
    <sub code="2232" />
</drugID>

If @code of parent node is UNK then only it should take @code value of child node otherwise take parent @code value.

Answer

frisco picture frisco · Oct 11, 2011

This should do the trick:

(drugID[@code='UNK']/sub)|(drugID[@code<>'UNK')

It is Xpath pseudocode, change it to your library language