MyException - 我的异常网
当前位置:我的异常网» XML/SOAP » xquery生手求教

xquery生手求教

www.myexceptions.net  网友分享于:2013-04-10  浏览:4次
xquery新手求教
请问如何使用xquery来统计一个xml文件中<section/>的个数?xquery中是否有跟sql中的groupby类似的语句?

------解决方案--------------------
count($doc//section)

group by
<books>
    <book bookid="1">
        <title>Java Web Services</title>
        <subject>XML</subject>
    </book>
    <book bookid="2">
        <title>XML Applications</title>
        <subject>XML</subject>
    </book>
    <book bookid="4">
        <title>Beginning Visual C++ 6 Database Programming</title>
        <subject>Database</subject>
    </book>
    <book bookid="5">
        <title>Beginner&apos;s Guide to Access 2.0</title>
        <subject>Database</subject>
    </book>
</books>

<subjects> {
    for $subject in distinct-values(/books/book/subject)
    let $books-in-group := /books/book[subject=$subject]
    return
        <subject name="{$subject}"> {
            for $book in $books-in-group
            return
                <book-title>{$book/title/text()}</book-title>
        } </subject>
} </subjects>

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有