xml ファイルに対して xquery を実行しようとしています。これは私の入力xmlファイルです:
<?xml version="1.0" ?>
<authors>
<author><name> Steven</name>
<title>advanced</title>
<title>TCPIP</title>
</author>
<author><name> George</name>
<title>DataMining</title>
<title>Economic</title>
</author>
<author><name> Den</name>
<title>TCPIP</title>
<title>Economic</title>
</author>
</authors>
各タイトルをグループ化し、各タイトルの著者数を数えようとしています。書籍は、著者の数が多い順に並べてください。各本について、そのタイトル、著者の数、すべての著者の名前をアルファベット順に出力します。最終的に、出力は次のようになります。
<bib>
<book authors="1">
<title>Advanced</title>
<author>Steven</authhor>
</book>
<book authors="1">
<title>DataMining</title>
<author>George</author>
</book>
<book authors="2">
<title>TCPIP</title>
<author>Den</author>
<author>Steven</author>
</book>
<book authors="2">
<title>Economic</title>
<author>Den</author>
<author>George</author>
</book>
</bib>
これは機能しない私のコードです:(。何か助けはありますか。可能であれば、新しいコードを書く代わりにコードを修正してください。答えを私の答えのようにしたいからです。
<bib>
{for $a in doc('test')//authors
let $T:={for $c in doc ('test')//authors/author[title=$a/author/title]
order by count($T)
return <book authors="{count($T)}">
{<title> {distinct-values($T/title)}
for $x in $T
order by $x/name()
return <author>{$x/name()}</author>}
</book>}
</bib>
コマンドを使おうとする部分に問題があると思いますlet
。私が知っているように、 let コマンドでデータをグループ化できます。XML ファイルのタイトルごとにすべての著者を取得し、その後、著者の数を数えて名前で並べ替えようとしました。http://basex.org/products/live-demo/のリンクを使用して、回答をテストします。