Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用xmlstarlet替换XML中的部分URL_Xml_Xslt_Xmlstarlet - Fatal编程技术网

用xmlstarlet替换XML中的部分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>

我想用XMLStarlet替换URL的一部分

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