如何在 XQuery 中使用 FLOWR 从这家书店退回第三本书? [英] how to return the third book from this bookstore using FLOWR in XQuery?
问题描述
如何退还这家书店的第三本书?
How can I return the third book from this bookstore?
declare context item := document{
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="web" cover="paperback">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
};
let $date := current-date()
for $ctx in context
return $ctx/bookstore/book[3]
到目前为止,我只是得到一个空白结果:
so far I'm just getting a blank result:
PS C:\Users\thufir\Desktop\basex>PS C:\Users\thufir\Desktop\basex> basex contextDoc.xqPS C:\Users\thufir\Desktop\basex>
PS C:\Users\thufir\Desktop\basex> PS C:\Users\thufir\Desktop\basex> basex contextDoc.xq PS C:\Users\thufir\Desktop\basex>
推荐答案
您的问题标题说使用 FLWOR 表达式",但 FLWOR 表达式对于这样一个简单的查询来说太过分了.
Your question title says "using a FLWOR expression", but FLWOR expressions are overkill for such a simple query.
@YitzhakKhabinsky 提供了正确答案:
@YitzhakKhabinsky has provided a correct answer:
for $ctx in ./bookstore/book[3] return $ctx
但是表达式 for $X in Y return $X
只是一种表示 Y
的冗长方式,所以这简化为
but the expression for $X in Y return $X
is just a verbose way of saying Y
, so this simplifies to
./bookstore/book[3]
或者更简单
bookstore/book[3]
这篇关于如何在 XQuery 中使用 FLOWR 从这家书店退回第三本书?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!