The real Van Gogh
The real Van Gogh

Reputation: 39

Xquery get node with specific child element

I am using xquery 1.0 and have the following problem.

My input message:

<Body>
<album>
    <contents>
        <content>correct</content>
        <content>hardcore</content>
    </contents>
</album>
<album>
    <contents>
        <content>incorrect</content>
        <content>punk</content>
    </contents>
</album>
<album>
    <contents>
        <content>incorrect</content>
        <content>rock</content>
    </contents>
</album>
</Body>

Desired result:

I would like to search for the 'Album' node that contains the child element <content>correct</content> and when the node has been found I would like to pick/use the element <content>hardcore</content>. Note that the order of the album nodes is subject to change. So a first() or [1] will not be sufficient.

What I tried:

if (body/album/contents/content[text()='correct']) then ???

Upvotes: 1

Views: 184

Answers (1)

Jack Fleeting
Jack Fleeting

Reputation: 24930

If I understand you correctly, you probably don't need xquery for that.

//contents/content[.="correct"]/following-sibling::content

should be enough.

Upvotes: 2

Related Questions