2015-09-04 71 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>") 
相關問題