The group is `group 2`, not `group 3`: $ xmlstarlet sel -t -v '//Key[Key/Value[@name="rsv-login-name" and @data="name3"]]/Value[@name="rsv-group-name"]/@data' -nl file.xml group 2 The XPATH query looks for a `Key/Key/Value` node that has `name="rsv-login-name"` and `data="name3"`, and for the `Key` that this node is a `Key/Value` node of, it returns the `data` attribute for the `Value` node that has `name="rsv-group-name"`. The XML I've used here is a slightly modified document that adds a `<root>` tag at the start and a `</root>` end tag at the end.