XQuery 如果某件事为真则更新,否则返回错误

发布于 2024-09-06 06:36:35 字数 405 浏览 3 评论 0原文

我正在尝试创建一个 xquery 表达式,仅当条件为真时才插入一些新节点,如果条件为假则返回错误。我的状态的简单版本是:

let $a := [...]

return 
  if($a/@something != "true") then (
     insert node (
            element {'Foobar'} { }
        ) into $a/somenode
  ) else ( 

  )

我的问题:每当将 之类的内容放入 else 中时,我都会收到错误“[XUST0001] 此上下文中不允许更新表达式”。

/e:好吧...如果我理解正确,我就无法更新表达式和返回值...所以我必须找到另一种方法。

I'm trying to create a xquery expressions that inserts some new nodes only if a condition is true and returns an error if the condition is false. A simplyfied version of my state is:

let $a := [...]

return 
  if($a/@something != "true") then (
     insert node (
            element {'Foobar'} { }
        ) into $a/somenode
  ) else ( 

  )

My problem: whenever if put something like <Error/> into the else i get an error "[XUST0001] No updating expression allowed in this context".

/e: Okay...if I understand this correctly i can't have updateing expressions AND a return value....so I have to find another way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

药祭#氼 2024-09-13 06:36:35

您可以使用 fn:error() 引发错误,或使用 () 不执行任何操作。不幸的是,XQuery Update 不允许您执行您想要的操作 - 也许它将在未来版本中修复。

You can use fn:error() to raise the error, or use () to do nothing. Unfortunately XQuery Update doesn't allow you to do what you want - maybe it will be fixed in a future version.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文