Eu tenho um documento xml do formulário
root
+- foo
+- bar
| +- @baz
Quero extrair o valor de /root/foo
e de /root/bar/@baz
de uma só vez na linha de comando.
eu posso fazer
cat file.xml | xmlstarlet sel -t -v "/root/foo" -n
e
cat file.xml | xmlstarlet sel -t -v "/root/bar/@baz" -n
separadamente.
E eu posso fazer
cat file.xml | xmlstarlet sel -t -v "/root/foo|bar/@baz" -n
o que me dá o valor de baz
if foo
does not exist .
tentei
cat file.xml | xmlstarlet sel -t -v "/root/[foo and bar/@baz]" -n
mas isso não funciona
compilation error: element with-param
XSLT-with-param: Failed to compile select expression '/root/[foo and bar/@baz]'
Como posso obter os dois?
Atualização: exemplo mÃnimo reproduzÃvel
Arquivo XML
<root>
<foo>Value F1</foo>
<bar baz="Value B1" />
<foo>Value F2</foo>
<bar baz="Value B2" />
</root>
O comando
cat file.xml | xmlstarlet sel -t -v "/root/foo" -n
Me dá
Value F1
Value F2
e
cat file.xml | xmlstarlet sel -t -v "/root/bar/@baz" -n
Me dá
Value B1
Value B2
e
cat file.xml | xmlstarlet sel -t -v "/root/foo|bar/@baz" -n
Também me dá
Value F1
Value F2
Meu resultado esperado é algo como
Value F1 Value B1
Value F2 Value B2
cada um em uma linha.
Estou usando xmlstarlet
, versão
1.6.1
compiled against libxml2 2.9.13, linked with 20913
compiled against libxslt 1.1.35, linked with 10135
Não me importa qual versão do XPath preciso usar para obter esse resultado.
Você estava quase lá com:
tente isto:
saÃda: