2015-09-04 76 views
0

考虑以下XQuery代码:的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

我希望这是你在寻找:

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>") 
相关问题