0

I've got this partial XML

 <Events>
   <Properties>
     <Property Descriptor="1">VALUE1</Property>
     <Property Descriptor="2">FOO</Property>
     <Property Descriptor="3">BAR</Property>
     </Properties>
   <Properties>
     <Property Descriptor="1">VALUE2</Property>
     <Property Descriptor="2">NO</Property>
     <Property Descriptor="3">NOTHINGHERE</Property>
   </Properties>
 </Events>

Hi can I query the first occurrence of Property Descriptor="3" when Property Descriptor="2" = "FOO"? Result here should be BAR

I tried //Properties/Property[@Descriptor="3"][..//Property[@Descriptor="2"] = "FOO"] but it's now working.

D. Caan
  • 1,907
  • 6
  • 22
  • 36

1 Answers1

3

can I query the first occurrence of Property Descriptor="3" when Property Descriptor="2" = "FOO"?

/Events/Properties[Property[@Descriptor = '2'] = 'FOO']/Property[@Descriptor = '3'][1]

And in more detail:

/Events/Properties                    Look for a Properties element
[Property                             but only if it has a Property element
[@Descriptor = '2'] = 'FOO']          but only if its Descriptor attribute equals 2 and
                                      its textual content is "FOO"
/Property[@Descriptor = '3']          for that Properties element look for a child element
                                      called Property where the Descriptor attribute equals 3
[1]                                   thereof return the first occurrence
Mathias Müller
  • 22,203
  • 13
  • 58
  • 75