I am trying to select values from an XML by XPath. I wonder whyxmlstarlet sel -t -m //data -v "." /tmp/test.xml does work and xmlstarlet sel -t -m //data /tmp/test.xml does not.
I know that option -v means view. However xmlstarlet sel -t -m //data -v /tmp/test.xml is getting stuck.
So, my question is how to use option view properly.
Actually,
-vmeans value-of and-mmeans for-each. These refer to the XSLT definitions*, since the sel subcommand simply generates an XSLT document and runs it on the input.This is a loop without a body, so there is no output.
Here
/tmp/test.xmlis interpreted as the XPath expression to-vso this means: for-each data node, output the value-of nodes namedtest.xmlbeneath thetmproot node. And it expects the input XML to come from standard input so it will appear to be stuck.You can always get the meaning of any
selcommand line as XSLT by using the-Coption.* In recent versions of xmlstarlet (1.3+)
-vwill output the value-of each node in a nodelist separated by a newline, rather than the XSLT definition where value-of only outputs the string value of the first node.