使用 XQuery 设置常量值

发布于 2024-10-06 17:07:06 字数 249 浏览 0 评论 0原文

我一直在尝试使用 xquery 为传入 xml(来自队列)的元素分配值。传入的 xml 格式为

我需要为目标系统设置它们的常量值:

123< /header>

有什么想法吗?

I have been trying to assign values to the elements of an incoming xml(from a queue) using xquery. The in coming xml is of the form

<header><a></a><b></b><c></c></header>

i need to set them with constant values for the target system:

<header><a>1</a><b>2</b><c>3</c></header>

Any ideas?

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

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

发布评论

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

评论(1

心房的律动 2024-10-13 17:07:06

我不确定我是否完全理解您的问题,但我假设您想要复制输入并修改某些元素。使用 XSLT 可以最轻松地完成此操作。

要在 XQuery 中执行此操作,您需要一个递归函数来查看每个节点,在适当的情况下对其进行修改,然后复制输出。根据您的描述,我假设您的输入仅由元素节点组成,因此这是我考虑过的唯一情况:

declare function local:apply($node as element())
{
  typeswitch ($node)
  case element(a) return <a>1</a>
  case element(b) return <b>2</b>
  case element(c) return <c>3</c>
  default return element {name($node)} {local:apply($node/*)}
}

I'm not sure if I understand your question fully, but I assume you are wanting to copy the input and modify certain elements. This would be most easily done with XSLT.

To do this in XQuery you want a recursive function that looks at each node, modifies it if appropriate, and the copies the output. From your description, I assume your input consists only of element nodes, and so this is the only case I have considered:

declare function local:apply($node as element())
{
  typeswitch ($node)
  case element(a) return <a>1</a>
  case element(b) return <b>2</b>
  case element(c) return <c>3</c>
  default return element {name($node)} {local:apply($node/*)}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文