XPath Param Value Is Not Evaluating In Expression

Viewed 19

The @Value='1' Does not seem to be evaluating in this expression below as it returns both nodes of SEventData instead of only one that has a @Value of '1'. What am I missing?

Source:

<CData>
<SData SKey="006" >

<SEventData SEventOID="UNS" SEventRepeatKey="2">
<FData FOID="REQUIRED" FRepeatKey="1">
<ItemGroupData ItemGroupOID="REQUIRED" ItemGroupRepeatKey="0" 
TransactionType="Upsert">
<ItemData ItemOID="REQ" Value="0"  />
</ItemGroupData>
</FData>
</SEventData>

<SEventData SEventOID="UNS" SEventRepeatKey="3">
<FData FOID="REQUIRED" FRepeatKey="1">
<ItemGroupData ItemGroupOID="REQUIRED" ItemGroupRepeatKey="0" 
TransactionType="Upsert">
<ItemData ItemOID="REQ" Value="1"  />
</ItemGroupData>
</FData>
</SEventData>

</SData>
</CData>

with expression

//CData[.//SData[@SKey='006']/SEventData/FData/ItemGroupData/ItemData[@ItemOID='REQ' and @Value='1']]//SEventData    

returns both instead of one

Element='<SEventData SEventOID="UNS" SEventRepeatKey="2">
  <FData FOID="REQUIRED" FRepeatKey="1">
     <ItemGroupData ItemGroupOID="REQUIRED"
                 ItemGroupRepeatKey="0"
                 TransactionType="Upsert">
        <ItemData ItemOID="REQ" Value="0"/>
     </ItemGroupData>
  </FData>
</SEventData>'
Element='<SEventData SEventOID="UNS" SEventRepeatKey="3">
  <FData FOID="REQUIRED" FRepeatKey="1">
     <ItemGroupData ItemGroupOID="REQUIRED"
                 ItemGroupRepeatKey="0"
                 TransactionType="Upsert">
        <ItemData ItemOID="REQ" Value="1"/>
     </ItemGroupData>
  </FData>
</SEventData>'
1 Answers

You can use this XPath in order to locate what you are looking for:

//SEventData[.//FData/ItemGroupData/ItemData[@ItemOID='REQ' and @Value='1']]

Your current XPath expression returns the root node //CData containing in it the following condition: .//SData[@SKey='006']/SEventData/FData/ItemGroupData/ItemData[@ItemOID='REQ' and @Value='1'].
So yes, //CData has inside it the condition as above and when you trying to locate //SEventData inside that //CData it returns you both //SEventData nodes.
What you should do here is to locate //SEventData node itself based on your condition as I wrote at the beginning:

//SEventData[.//FData/ItemGroupData/ItemData[@ItemOID='REQ' and @Value='1']]
Related