<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>
这是我的代码,当我运行此代码时,出现语法错误:
4,1: static error [err:XPST0003]: invalid expression: syntax error, unexpected expression (missing comma "," between expressions?)
此代码有什么问题?
答案 0 :(得分: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>