用xmlstarlet替换XML中的部分URL
我想用XMLStarlet替换URL的一部分用xmlstarlet替换XML中的部分URL,xml,xslt,xmlstarlet,Xml,Xslt,Xmlstarlet,我想用XMLStarlet替换URL的一部分 http://example.com:8081至http://example2.com XML: <SHOP> <SHOPITEMS> <SHOPITEM> <IMGURL>http://example.com:8081/image.jpg</IMGURL> <IMAGES>
http://example.com:8081
至http://example2.com
XML:
<SHOP>
<SHOPITEMS>
<SHOPITEM>
<IMGURL>http://example.com:8081/image.jpg</IMGURL>
<IMAGES>
<IMGURL>http://example.com:8081/image2.jpg</IMGURL>
<IMGURL>http://example.com:8081/image3.jpg</IMGURL>
</IMAGES>
</SHOPITEM>
</SHOPITEMS>
</SHOP>
没有工作。。。以及:
xmlstarlet ed -u "//SHOP/SHOPITEMS/SHOPITEM/IMGURL/text()" -x "str:replace(., 'http://example.com:8081', 'http://example2.com')" input.xml
xmlXPathCompOpEval: function replace not found
Unregistered function
Segmentation fault
感谢您的帮助。这不是真正的替代,而是子字符串技巧。至少它是有效的:
xmlstarlet ed -u "//*[starts-with(text(),'http://example.com:8081/')]" -x "concat('http://example2.com/',substring(text(),25))" input.xml
XMLStarlet使用libxslt,并且自从EXSLT函数
str:replace()
was以来,它一直不可用。也许你可以考虑做一些事情,比如“代码> SED”//S/\(示例\).com:8081/12。COM/[输入.xml < /代码>或AWK选项,如<代码> AWK '//{Sub(“示例:com:8081”,“ExpRe2.com”)} 1’输入。XML 。为什么这被标记为<代码> XSLT < /代码>?
xmlstarlet ed -u "//*[starts-with(text(),'http://example.com:8081/')]" -x "concat('http://example2.com/',substring(text(),25))" input.xml