比方說,我想創建一個(POSIX兼容)的shell腳本的下一個XML文件:如何使用和處理重複的XML元素以使用shell腳本創建其他元素?
<xml>
<item>
<title>The Turning Point to a Cross Fade in a Carpark</title>
<slug>the-turning-point-to-a-cross-fade-in-a-carpark</slug>
</item>
<item>
<title>The Cycle Continues in One Direction</title>
<slug>the-cycle-continues-in-one-direction</slug>
</item>
</xml>
但我只有下一個:
<xml>
<item>
<title>The Turning Point to a Cross Fade in a Carpark</title>
</item>
<item>
<title>The Cycle Continues in One Direction</title>
</item>
</xml>
隨着XMLStarlet edit --update
(和僅與--update
)我可以使用XPath表達式而不是字符串值形式:
xml ed -u '/xml/item/slug' -x '../title/text()'
但XPath 2.0中字符串型F聯合會似乎不起作用(xmlXPathCompOpEval: function lower-case not found
)。那麼我怎麼能遍歷所有的塊,並使用<title>
元素的文本值來生成<slug>
元素?我怎樣才能用最少的xml
動作來做到這一點?
[translate()](http://www.w3.org/TR/xpath/#function-translate)? – npostavs