XQuery - 去除标签但保留其文本

mah*_*eng 4 xml text xquery strip-tags

如何在 XQuery 中删除一组标签但仍将其文本保留在那里?例如,如果我有:

<root>
    <childnode>This is <unwantedtag>some text</unwantedtag> that I need.</childnode>
</root>
Run Code Online (Sandbox Code Playgroud)

如何去除不需要的标签以获得:

<root>
    <childnode>This is some text that I need.</childnode>
</root>
Run Code Online (Sandbox Code Playgroud)

实际上,我真正想要结束的只是文本,例如:

This is some text that I need.
Run Code Online (Sandbox Code Playgroud)

当我执行以下操作时:

let $text := /root/childnode/text()
Run Code Online (Sandbox Code Playgroud)

我得到:

This is  that I need.
Run Code Online (Sandbox Code Playgroud)

它缺少它的some text一部分。

关于如何返回的任何想法This is some text that I need.

谢谢你。

Gun*_*her 5

它不是您感兴趣的 childnode 的字符串值(而不是文本节点序列或简化元素)?您可以从fn:string获取字符串值:

string(/root/childnode)
Run Code Online (Sandbox Code Playgroud)