简体   繁体   中英

Xpath element with common parent

I am trying to find the 'comment' node where the 'name' node == 'package 3'. Previously I was using rpc-reply/blah/blah-blah/information/package-information[3] , but I'm looking for a more robust method which filters on the 'name' and returns the associated 'comment'.

I did some googleing and found the 'Kaysian method' might be what I was looking for, however I could not apply/understand it.

To phrase my question in another way, the below might clarify what I am after:

SELECT comment WHERE name = 'package 3' FROM rpc-reply//package-information

<rpc-reply>
<blah>
    <blah-blah>
        <information>
            <package-information>
                <name>package 1</name>
                <comment>44565545</comment>
            </package-information>
            <package-information>
                <name>package-2</name>
                <comment>6859887</comment>
            </package-information>
            <package-information>
                <name>package 3</name>
                <comment>5548845</comment>
            </package-information>
            <package-information>
                <name>package 4</name>
                <comment>548878</comment>
            </package-information>
        </information>
    </blah-blah>
</blah>
</rpc-reply>

选择名称为package 3package-information元素,然后转到注释:

/rpc-reply/blah/blah-blah/information/package-information[name='package 3']/comment

另一个可能的解决方案:

 //name[contains(text(), 'package 3')]/following-sibling::comment 

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