xml - How to join to predicates together to get an attribute from the parent element based on two attributes and values from child -
i need "date of birth" node value when attribute "benefit type id" equal "ben13" and attribute "dependant of benefit" equal "y".
xml
<component> <attributes name="flexdependants"> <attribute name="datainstance">11</attribute> <attribute name="rownumber">1</attribute> <attribute name="date of birth">nov 11 1978</attribute> <component name="allocation"> <attributes name="allocation"> <attribute name="datainstance">24</attribute> <attribute name="benefit type id">ben13</attribute> <attribute name="dependant of benefit">y</attribute> </attributes> </component> </attributes> <attributes name="flexdependants"> <attribute name="datainstance">10</attribute> <attribute name="rownumber">2</attribute> <attribute name="date of birth">oct 12 1984</attribute> <component name="allocation"> <attributes name="allocation"> <attribute name="datainstance">23</attribute> <attribute name="benefit type id">ben13</attribute> <attribute name="dependant of benefit">n</attribute> </attributes> </component> </attributes>
so need have 2 predicates in 1 statement, i'm not sure how that..
i've tried:
/component/attributes/component/attributes/ attribute[@name='benefit type id' , text()='ben13'][@name='dependant of benefit' , text()='y']/ ../../../attribute[@name='date of birth']
^ doesn't work.
the problem joining 2 predicates together... work fine individually not together. how can this?
you can try way (formatted readability) :
/component /attributes[ component /attributes[ attribute[@name='benefit type id' , .='ben13'] , attribute[@name='dependant of benefit' , .='y'] ] ]/attribute[@name='date of birth']
or 1 using less nested predicate maybe easier read :
/component /attributes[ component/attributes/attribute[@name='benefit type id' , .='ben13'] , component/attributes/attribute[@name='dependant of benefit' , .='y'] ]/attribute[@name='date of birth']
Comments
Post a Comment