简体   繁体   中英

Xpath condition get parent

Here's my xml:

<people>
<person id="0001">
    <firstname>Christopher</firstname>
    <lastname>Shaw</lastname>
    <birthdate>1975-02-23T21:24:46.000+02:00</birthdate>
    <healthprofile>
        <lastupdate>2014-09-30T10:38:07.000+02:00</lastupdate>
        <weight>84</weight>
        <height>2.13</height>
        <bmi>18.51</bmi>
    </healthprofile>
</person>
<person id="0002">
    <firstname>Brian</firstname>
    <lastname>Tooley</lastname>
    <birthdate>1987-10-19T08:18:59.000+02:00</birthdate>
    <healthprofile>
        <lastupdate>2014-09-30T10:38:07.000+02:00</lastupdate>
        <weight>98</weight>
        <height>2.17</height>
        <bmi>20.81</bmi>
    </healthprofile>
</person>
</people>

What I want to do using Xpath is to extract the firstname of those users which weight is equal to 80 for example. I can't get this to work.

You can try something like this :

/people/person[healthprofile/weight='80']/firstname

Basically above XPath look for <person> element having <weight> descendant equals 80 , then from that <person> get the <firstname> element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM