Search code examples
xmlxpathxpath-1.0

Xpath: Select property depending on other property's value


I have this [partial] XML:

   <Events>
     <Properties>
       <Property Descriptor=100>1378314024</Property>
       <Property Descriptor=200>ABC1234</Property>
     </Properties>
     <Properties>
       <Property Descriptor=100>1378314022</Property>
       <Property Descriptor=200>123456</Property>
     </Properties>
     <Properties>
       <Property Descriptor=100>1378314023</Property>
       <Property Descriptor=200>123456</Property>
     </Properties>
    </Events>

How can I select @Property Descriptor="100" for the FIRST occurrence of 123456 on @Property Descriptor="200"?


Solution

  • You can do this way :

    (//Properties[Property[@Descriptor='200'][.='123456']]/Property[@Descriptor='100'])[1]