{"id":194852,"date":"2020-07-09T08:18:05","date_gmt":"2020-07-09T00:18:05","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=194852"},"modified":"2020-06-27T11:19:44","modified_gmt":"2020-06-27T03:19:44","slug":"xquery-selection-filtering","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/xquery-selection-filtering.html","title":{"rendered":"XQuery\u9009\u62e9\u548c\u8fc7\u6ee4"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u89e3\u91ca XQuery \u6700\u4f73\u65b9\u5f0f\u662f\u8fd9\u6837\u8bb2\uff1aXQuery \u76f8\u5bf9\u4e8e XML \u7684\u5173\u7cfb\uff0c\u7b49\u540c\u4e8e SQL \u76f8\u5bf9\u4e8e\u6570\u636e\u5e93\u8868\u7684\u5173\u7cfb\u3002XQuery \u88ab\u8bbe\u8ba1\u7528\u6765\u67e5\u8be2 XML \u6570\u636e - \u4e0d\u4ec5\u4ec5\u9650\u4e8e XML \u6587\u4ef6\uff0c\u8fd8\u5305\u62ec\u4efb\u4f55\u53ef\u4ee5 XML \u5f62\u6001\u5448\u73b0\u7684\u6570\u636e\uff0c\u5305\u62ec\u6570\u636e\u5e93\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u9009\u62e9\u548c\u8fc7\u6ee4\u5143\u7d20<\/strong><\/div>\n

\u6b63\u5982\u5728\u524d\u9762\u7684\u7ae0\u8282\u6240\u770b\u5230\u7684\uff0c\u6211\u4eec\u4f7f\u7528\u8def\u5f84\u8868\u8fbe\u5f0f\u6216 FLWOR \u8868\u8fbe\u5f0f\u6765\u9009\u53d6\u548c\u8fc7\u6ee4\u5143\u7d20\u3002
\n\u8bf7\u770b\u4e0b\u9762\u7684 FLWOR \u8868\u8fbe\u5f0f\uff1a<\/p>\n

\r\nfor $x in doc(\"books.xml\")\/bookstore\/book\r\nwhere $x\/price>30\r\norder by $x\/title\r\nreturn $x\/title<\/pre>\n

\u2022\tfor - \uff08\u53ef\u9009\uff09 \u5411\u6bcf\u4e2a\u7531 in \u8868\u8fbe\u5f0f\u8fd4\u56de\u7684\u9879\u76ee\u6346\u7ed1\u4e00\u4e2a\u53d8\u91cf
\n\u2022\tlet - \uff08\u53ef\u9009\uff09
\n\u2022\twhere - \uff08\u53ef\u9009\uff09 \u8bbe\u5b9a\u4e00\u4e2a\u6761\u4ef6
\n\u2022\torder by - \uff08\u53ef\u9009\uff09 \u8bbe\u5b9a\u7ed3\u679c\u7684\u6392\u5217\u987a\u5e8f
\n\u2022\treturn - \u89c4\u5b9a\u5728\u7ed3\u679c\u4e2d\u8fd4\u56de\u7684\u5185\u5bb9<\/p>\n

for \u8bed\u53e5<\/strong><\/div>\n

for \u8bed\u53e5\u53ef\u5c06\u53d8\u91cf\u6346\u7ed1\u5230\u7531 in \u8868\u8fbe\u5f0f\u8fd4\u56de\u7684\u6bcf\u4e2a\u9879\u76ee\u3002for \u8bed\u53e5\u53ef\u4ea7\u751f\u8fed\u4ee3\u3002\u5728\u540c\u4e00\u4e2a FLWOR \u8868\u8fbe\u5f0f\u4e2d\u53ef\u5b58\u5728\u591a\u91cd for \u8bed\u53e5\u3002
\n\u5982\u9700\u5728\u4e00\u4e2a for \u8bed\u53e5\u4e2d\u8fdb\u884c\u6307\u5b9a\u6b21\u6570\u5730\u5faa\u73af\uff0c\u60a8\u53ef\u4f7f\u7528\u5173\u952e\u8bcd to \uff1a<\/p>\n

\r\nfor $x in (1 to 5)\r\nreturn <test>{$x}<\/test><\/pre>\n

\u7ed3\u679c\uff1a<\/p>\n

<test>1<\/test>\r\n<test>2<\/test>\r\n<test>3<\/test>\r\n<test>4<\/test>\r\n<test>5<\/test><\/pre>\n

\u5173\u952e\u8bcd at \u53ef\u7528\u4e8e\u8ba1\u7b97\u8fed\u4ee3\uff1a<\/p>\n

for $x at $i in doc(\"books.xml\")\/bookstore\/book\/title\r\nreturn <book>{$i}. {data($x)}<\/book><\/pre>\n

\u7ed3\u679c\uff1a<\/p>\n

<book>1. Everyday Italian<\/book>\r\n<book>2. Harry Potter<\/book>\r\n<book>3. XQuery Kick Start<\/book>\r\n<book>4. Learning XML<\/book><\/pre>\n

\u5728 for \u8bed\u53e5\u4e2d\u540c\u6837\u5141\u8bb8\u591a\u4e2a in \u8868\u8fbe\u5f0f\u3002\u8bf7\u4f7f\u7528\u9017\u53f7\u6765\u5206\u5272\u6bcf\u4e00\u4e2a in \u8868\u8fbe\u5f0f\uff1a<\/p>\n

for $x in (10,20), $y in (100,200)\r\nreturn <test>x={$x} and y={$y}<\/test><\/pre>\n

\u7ed3\u679c\uff1a<\/p>\n

<test>x=10 and y=100<\/test>\r\n<test>x=10 and y=200<\/test>\r\n<test>x=20 and y=100<\/test>\r\n<test>x=20 and y=200<\/test><\/pre>\n
let \u8bed\u53e5<\/strong><\/div>\n

let \u8bed\u53e5\u53ef\u5b8c\u6210\u53d8\u91cf\u5206\u914d\uff0c\u5e76\u53ef\u907f\u514d\u591a\u6b21\u91cd\u590d\u76f8\u540c\u7684\u8868\u8fbe\u5f0f\u3002let \u8bed\u53e5\u4e0d\u4f1a\u5bfc\u81f4\u8fed\u4ee3\u3002<\/p>\n

let $x := (1 to 5)\r\nreturn <test>{$x}<\/test><\/pre>\n

\u7ed3\u679c\uff1a<\/p>\n

<test>1 2 3 4 5<\/test><\/pre>\n
where \u8bed\u53e5<\/strong><\/div>\n

where \u8bed\u53e5\u7528\u4e8e\u4e3a\u7ed3\u679c\u8bbe\u5b9a\u4e00\u4e2a\u6216\u591a\u4e2a\u6761\u4ef6\uff08criteria\uff09\u3002<\/p>\n

where $x\/price>30 and $x\/price<100<\/pre>\n
order by \u8bed\u53e5<\/strong><\/div>\n

order by \u8bed\u53e5\u7528\u4e8e\u89c4\u5b9a\u7ed3\u679c\u7684\u6392\u5e8f\u6b21\u5e8f\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u8981\u6839\u636e category \u548c title \u6765\u5bf9\u7ed3\u679c\u8fdb\u884c\u6392\u5e8f\uff1a<\/p>\n

for $x in doc(\"books.xml\")\/bookstore\/book\r\norder by $x\/@category, $x\/title\r\nreturn $x\/title<\/pre>\n

\u7ed3\u679c\uff1a<\/p>\n

<title lang=\"en\">Harry Potter<\/title>\r\n<title lang=\"en\">Everyday Italian<\/title>\r\n<title lang=\"en\">Learning XML<\/title>\r\n<title lang=\"en\">XQuery Kick Start<\/title><\/pre>\n
return \u8bed\u53e5\uff1a<\/strong><\/div>\n

return \u8bed\u53e5\u89c4\u5b9a\u8981\u8fd4\u56de\u7684\u5185\u5bb9\u3002<\/p>\n

for $x in doc(\"books.xml\")\/bookstore\/book\r\nreturn $x\/title<\/pre>\n

\u7ed3\u679c\uff1a<\/p>\n

<title lang=\"en\">Everyday Italian<\/title>\r\n<title lang=\"en\">Harry Potter<\/title>\r\n<title lang=\"en\">XQuery Kick Start<\/title>\r\n<title lang=\"en\">Learning XML<\/title><\/pre>\n","protected":false},"excerpt":{"rendered":"

\u6b63\u5982\u5728\u524d\u9762\u7684\u7ae0\u8282\u6240\u770b\u5230\u7684\uff0c\u6211\u4eec\u4f7f\u7528\u8def\u5f84\u8868\u8fbe\u5f0f\u6216 FLWOR \u8868\u8fbe\u5f0f\u6765\u9009\u53d6\u548c\u8fc7\u6ee4\u5143\u7d20\u3002 \u8bf7\u770b\u4e0b\u9762\u7684 FLWOR […]<\/p>\n","protected":false},"author":321,"featured_media":194844,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-194852","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/194852","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/321"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=194852"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/194852\/revisions"}],"predecessor-version":[{"id":194857,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/194852\/revisions\/194857"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/194844"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=194852"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=194852"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=194852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}