Skip to main content
added 279 characters in body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

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 
xmlstarlet sel -t \ -v '//Key[Key/Value[@name="rsv-login-name" and @data="name3"]]/Value[@name="rsv-group-name"]/@data' -nl file.xml 

Or, with a query value taken from the command line:

xmlstarlet sel -t --var data="'name3'" \ -v '//Key[Key/Value[@name="rsv-login-name" and @data=$data]]/Value[@name="rsv-group-name"]/@data' -nl file.xml 

Alternatively,

xmlstarlet sel -t --var data="'name3'" \ -m '//Key/Key/Value[@name="rsv-login-name" and @data=$data]' \ -v '../../Value[@name="rsv-group-name"]/@data' -nl file.xml 

The XPATHoutput from either of these will be 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, just to make it a well-formed XML document.

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, just to make it a well-formed XML document.

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 

Or, with a query value taken from the command line:

xmlstarlet sel -t --var data="'name3'" \ -v '//Key[Key/Value[@name="rsv-login-name" and @data=$data]]/Value[@name="rsv-group-name"]/@data' -nl file.xml 

Alternatively,

xmlstarlet sel -t --var data="'name3'" \ -m '//Key/Key/Value[@name="rsv-login-name" and @data=$data]' \ -v '../../Value[@name="rsv-group-name"]/@data' -nl file.xml 

The output from either of these will be 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, just to make it a well-formed XML document.

added 44 characters in body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

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, just to make it a well-formed XML document.

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.

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, just to make it a well-formed XML document.

Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

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.