Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Conditional Xpath statement?

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.

like image 746
patel Avatar asked Oct 11 '11 11:10

patel


2 Answers

This should do the trick:

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

It is Xpath pseudocode, change it to your library language

like image 75
frisco Avatar answered Nov 07 '22 11:11

frisco


Use:

drugId[@code = 'UNK']/sub/@code | drugId/@code[not(. = 'UNK')]

which could be "abbreviated":

(drugId[@code = 'UNK']/sub | drugId[not(@code = 'UNK')])/@code
like image 23
Dimitre Novatchev Avatar answered Nov 07 '22 12:11

Dimitre Novatchev