私は$ book、$ title、$ authorがFLWORのスコープ内にあることを理解していますが、なぜ$ titleと$ authorがシーケンス内で動作し、$ bookがそうでないのか分かりません。
(:
A note on variable scope.
Variables in a FLWOR expression are scoped only to the FLWOR expression.
Local variables declared in the prolog are scoped to the main module.
:)
(: start of prolog :)
xquery version "1.0-ml";
declare namespace bks = "http://www.marklogic.com/bookstore";
declare variable $scope-example := "2005";
(: end of prolog :)
(: start of query body :)
(
"remember an XQuery module returns a sequence -- this text is the first item, and then the results of the FLWOR",
for $book in /bks:bookstore/bks:book
let $title := $book/bks:title/string()
let $author := $book/bks:author/string()
let $year := $book/bks:year/string()
let $price := xs:double($book/bks:price/string())
where $year = $scope-example (: we can do this because my local variable is scoped to the module :)
order by $price descending
return
<summary>{($title, "by", $author)}</summary>
,
"and now another item, but I cant reference a variable from the FLWOR expression outside of the FLWOR, it will fail like this",
$book
)
(: end of query body :)
つまり、余分な括弧を使用して機能させる必要があります。例:返信用( {($タイトル、 "by"、$ author)} 、...、$ book) ' –
grtjn