2013-12-13 63 views
0
<authors> { 
for $a in fn:distinct-values(doc("data.xml")/books/book/author/text()) 
return <name> {$a} </name> 
{ 
    for $b in doc("data.xml")/books/book[author/text() = $a] 
    return <book> {$b/title/text()}</book> 
} 
} 
</authors> 

這是我的代碼,當我跑這個代碼,有語法錯誤:的Xquery語法錯誤

4,1: static error [err:XPST0003]: invalid expression: syntax error, unexpected expression (missing comma "," between expressions?) 

什麼是錯的代碼?

回答

4

從您的查詢中,您不清楚您希望以什麼格式返回輸出,但最接近的我可以想出哪些在語法上是正確的(請注意,大括號僅用於輸出內容XML語法):

<authors> { 
for $a in fn:distinct-values(doc("data.xml")/books/book/author/text()) 
return (<name> {$a} </name>, 
    for $b in doc("data.xml")/books/book[author/text() = $a] 
    return <book> {$b/title/text()}</book>) 
} 
</authors> 

更多的 '邏輯' 結構返回會是這樣,但:

<authors> { 
for $a in fn:distinct-values(doc("data.xml")/books/book/author/text()) 
return <author> 
      <name> {$a} </name> 
      { for $b in doc("data.xml")/books/book[author/text() = $a] 
       return <book> {$b/title/text()}</book> 
      } 
     </author> 
} 
</authors>