开发者

Set constant value with XQuery

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

开发者_StackOverflow社区<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?


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/*)}
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜