How to create Conditional Xpath statement?
Asked Answered
S

2

8

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.

Superman answered 11/10, 2011 at 11:27 Comment(0)
G
9

This should do the trick:

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

It is Xpath pseudocode, change it to your library language

Gerenuk answered 11/10, 2011 at 11:35 Comment(0)
G
6

Use:

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

which could be "abbreviated":

(drugId[@code = 'UNK']/sub | drugId[not(@code = 'UNK')])/@code
Gene answered 11/10, 2011 at 14:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.