通过 xquery 更改元素的值 [英] change value of element by xquery

查看:34
本文介绍了通过 xquery 更改元素的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<category>
     <catid>1</catid>
     <cattext> sport </cattext>
</category>

我想使用 xquery 将元素 <cattext> 的文本更改为另一个类似艺术"而不是运动的文本

I want change text of element <cattext> into another like "art" instead of sport by using xquery

推荐答案

如果您的引擎支持更新和脚本:

if your engine supports updates and scripting:

declare variable $x := 
   <category>
     <catid>1</catid>
     <cattext> sport </cattext>
   </category>;

replace value of node $x/cattext with "art";
$x;

或者如果您不想保留更改,您可以转换它的副本:

or if you don't want to persist the changes you can transform a copy of it:

let $x := 
   <category>
     <catid>1</catid>
     <cattext> sport </cattext>
   </category>
return
   copy $changedx := $x
   modify (replace value of node $changedx/cattext with "art")
   return $changedx 

这些代码片段在 http://try.zorba.io/

如果您的 XQuery 处理器不支持更新,Alejandro 的解决方案是最佳选择.

If your XQuery processor doesn't support updates Alejandro's solution is top.

这篇关于通过 xquery 更改元素的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆