简体   繁体   中英

XQuery/XPath - Joining two sets of elements on attributes with values in common

basis XML:

<people>
    <person uname="mark">Mark</person>
    <person uname="ryan">Ryan</person>
    <person uname="anna">Anna</person>
</people>
<dogs>
    <canine owner="mark">Lucy</canine>
    <canine owner="anna">Joey</canine>
</dogs>

Desired result:

Mark
Anna

I've just begun learning XPath and XQuery. Can this be done using XPath only, or do I need XQuery?

Yes, this can be done with XPath alone. The thing to remember is that = effectively does a join:

//person[@uname=//dogs/canine/@owner]/text()

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