没有在文档中看到它。这是我正在尝试做的事情:
echo "<foo><bar t='A' /><bar t='B' /></foo>" | xmlstarlet ed -u "//bar/@t" -v "1_[//bar/@t]"
我想将前缀 1_ 预先附加到 t。
预期输出:
<?xml version="1.0"?>
<foo>
<bar t="1_A"/>
<bar t="1_B"/>
</foo>
实际输出:
<?xml version="1.0"?>
<foo>
<bar t="1_[//bar/@t]"/>
<bar t="1_[//bar/@t]"/>
</foo>
最佳答案
试试这个:
echo "<foo><bar t='A' /><bar t='B' /></foo>" | \
xmlstarlet ed -u "//bar/@t" -x 'concat("1_", .)'
-v
用于固定值,-x
用于 xpath 表达式。
关于xml - 如何使用 xmlstarlet 或类似工具附加或前置到 xml 文件中的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37714378/