XQuery:在保留标签的同时标记文本

时间:2015-09-04 12:32:04

标签: xquery tokenize

考虑以下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>

我该如何解决这个问题?

1 个答案:

答案 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>")