求解在XQuery用distinct-values()去处重复的数据

Rickey_lee09 2016-11-04 05:55:22
从现有的xml中提取“has”节点和它之后的那个节点,然后如果一样的数据就只显示一个出来,可是用distinct-values折腾了半天也没弄出来,求大神们赐教

xml数据文件:

<xml version="1.0" encoding="UTF-8"?>
<bncDoc>
<stext>
<div>
<u who="PS6H7">
<s n="3">
<w c5="AV0" hw="well" pos="ADV">Has</w>
<c c5="PUN">, </c>
<w c5="AJ0" hw="good" pos="ADJ">Well </w>
<w c5="NN1" hw="afternoon" pos="SUBST">afternoon</w>
<c c5="PUN">.</c>
</s>
</u>

<u who="asdfgg">
<s n="4">
<w c5="PNP" hw="we" pos="PRON">has </w>
<w c5="VVD" hw="look" pos="VERB">Well </w>
<w c5="AT0" hw="the" pos="ART">the </w>
<w c5="NN1" hw="ground" pos="SUBST">ground</w>
<c c5="PUN">, </c>
<w c5="PNP" hw="i" pos="PRON">I </w>
<w c5="VVD" hw="think" pos="VERB">thought </w>
<c c5="PUN">.</c>
</s>

</u>
</div>
</stext>
</bncDoc>


我的XQuery代码:
  <html>
<body>
<h2>Extract Table</h2>
<table border="1">
<tr bgcolor="#FFF">
<th>Target</th>
<th>Successor</th>
<th>Frequence</th>
</tr>
{
for $w in doc("test.xml")/bncDoc/stext/div/u/s/w

return if (lower-case($w)="has" or normalize-space($w)="has" )
then
<tr>
<td>{data($w)}</td>

<td>{
for $y in $w/following-sibling::w[1]
return distinct-values(data($y))
}</td>

<td>
</td>
</tr>
else()
}
</table>
</body>
</html>


正常情况下输出应该是这样:


可是它一直都是长这样:



看了半天也不知道为啥删不掉。。。
...全文
600 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

2,209

社区成员

发帖
与我相关
我的任务
社区描述
其他数据库开发 其他数据库
社区管理员
  • 其他数据库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧