【问题标题】:XQuery function to limit the number of records in the outputXQuery 函数限制输出中的记录数
【发布时间】:2015-11-23 00:57:38
【问题描述】:

我有一个 XQuery 文件,它在输出中返回大量数据。我只想在我的输出中显示前 5 条记录。这是xquery代码。

<html>
<body>
<table border='1'>
<tr><td>Target</td><td>Successor</td><td>Probability</td></tr>

{

let $target := "has"

let $occurrences := doc("KS0.xml")//u//s/w[lower-case(normalize-space()) = $target]

for $successor in distinct-values($occurrences/following-sibling::w[1])

let $frequency := $occurrences/following-sibling::w[1][. = $successor]

let $probability := count($frequency) div count(//u//s/w[lower-case(normalize-space()) = lower-case(normalize-space($successor))])

order by count($frequency) descending

return <tr>
           <td>{$target}</td>
           <td>{$successor}</td>
           <td>{$probability}</td>
       </tr>
}

</table>
</body>
</html>

【问题讨论】:

    标签: xml xslt xquery


    【解决方案1】:

    您的查询将返回一系列项目,因此您可以简单地使用谓词来限制从序列返回的项目数,方法是将您的查询包装在括号中:

    (
    let $target := "has"
    ... 
    </tr>
    )[position() le 5]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-14
      • 1970-01-01
      相关资源
      最近更新 更多