XQuery - 去掉标签但保留其文本
如何在 XQuery 中删除一组标签但仍保留其文本?例如,如果我有:
<root>
<childnode>This is <unwantedtag>some text</unwantedtag> that I need.</childnode>
</root>
如何去掉不需要的标签以获取:
<root>
<childnode>This is some text that I need.</childnode>
</root>
实际上,我真正想要得到的只是文本,例如:
This is some text that I need.
当我执行以下操作时:
let $text := /root/childnode/text()
我得到:
This is that I need.
它缺少 其中的一些文本
部分。
关于如何返回这是我需要的一些文本。
有什么想法吗?
谢谢。
How do I strip out a set of tags in XQuery but still leave its text there? For example, if I have:
<root>
<childnode>This is <unwantedtag>some text</unwantedtag> that I need.</childnode>
</root>
How do I strip out the unwanted tag to get:
<root>
<childnode>This is some text that I need.</childnode>
</root>
Actually, what I really want to end up with is just the text, like:
This is some text that I need.
When I do the following:
let $text := /root/childnode/text()
I get:
This is that I need.
It's missing the some text
part of it.
Any ideas on how to return This is some text that I need.
?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您感兴趣的不是子节点的字符串值(而不是文本节点序列或简化元素)?您可以从 fn:string 获取字符串值:
Isn't it the string-value of childnode, that you are interested in (as opposed to a sequence of text nodes, or a simplified element)? You can get the string-value from fn:string:
使用:
当在提供的 XML 文档上计算此 XQuery 时:
生成所需的正确结果:
Use:
When this XQuery is evaluated on the provided XML document:
the wanted, correct result is produced:
此 XQuery:
输出:
This XQuery:
Output: