2017-03-20 1 views
0

Ich habe diese XML-Datei:vorgehen conditionals in xmlstarlet

$ cat conditional.xml 
<a> 
    <b></b> 
    <c></c> 
</a> 

$ xmlstarlet sel -t -m '/a/*' -v 'concat("hello ",name())' -n conditional.xml 
hello b 
hello c 

Ich möchte einige bedingten Dinge zu tun. Ich möchte "Hallo" zu Element 'a' sagen und ich möchte "Howdy" zu Element 'b' sagen. Dies basiert auf dem Namen des Elements, das im Voraus bekannt ist.

Antwort

0

können Sie verwenden --if --else --break (oder -i --else -b) Konstrukt (siehe the docs):

$ xmlstarlet sel -t -m '/a/*' \ 
    --if 'name()="b"' -o "hello " --else -o 'howdy ' --break \ 
    -v 'name()' -n conditional.xml 
hello b 
howdy c