考虑以下XQuery代码:
let $foo := <root>This is a <tag>test</tag>. This is <tag>only</tag> a <tag>test</tag>.</root>
for $s in tokenize($foo, "\. ")
return <sentence>{$s}</sentence>
它将$foo
分裂(非常天真)返回到句子中 - 但它也删除了$foo
中包含的标记:
<sentence>this is a test.</sentence>
<sentence>this is only a test.</sentence>
假设我想在保留嵌入式标签时将$foo
拆分成句子,输出如下所示:
<sentence>this is a <tag>test</tag>.</sentence>
<sentence>this is <tag>only</tag> a <tag>test</tag>.</sentence>
我该如何解决这个问题?
答案 0 :(得分:0)
我希望你在找什么:
let $foo := <root>This is a <tag>test</tag>. This is <tag>only</tag> a <tag>test</tag>.</root>
for $s in tokenize(xdmp:quote($foo/node()), "\. ")
return xdmp:unquote("<sentence>"||$s||"</sentence>")