我发现替换给定元素的值,这个现有的职位,但我需要用我在需求量的,我需要用另一个替换的第一个字符走得更远。 这是我找到的帖子: 通过XQuery的元素的变化值
来源XML:
<?xml version="1.0" encoding="UTF-8"?>
<category>
<catid>1</catid>
<cattext>sport</cattext>
</category>
使用此的Xquery:
declare namespace local = "http://example.org";
declare function local:copy-replace($element as element()) {
if ($element/self::cattext)
then <cattext>art</cattext>
else element {node-name($element)}
{$element/@*,
for $child in $element/node()
return if ($child instance of element())
then local:copy-replace($child)
else $child
}
};
local:copy-replace(/*)
给出了这样的输出:
<?xml version="1.0" encoding="UTF-8"?>
<category>
<catid>1</catid>
<cattext>art</cattext>
</category>
我的XQuery知识只是刚刚开始成长。 如何更改XQuery的上方,使得我得到以下输出仅改变第一个字符:
<?xml version="1.0" encoding="UTF-8"?>
<category>
<catid>1</catid>
<cattext>9port</cattext>
</category>