<!-- flowchart 箭头图标 勿删 -->
<svg style="display: none;">
<path d="M5,0 0,2.5 5,5z" id="raphael-marker-block" stroke-linecap="round" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path>
</svg>
<p>1.一个完整的FLWOR语法</p>
<pre class="blockcode"><code class="language-xquery hljs lasso">for <span class="hljs-variable">$prod</span> <span class="hljs-keyword">in</span> doc(<span class="hljs-string">"/product/catalog.xml"</span>)<span class="hljs-comment">//product</span>
<span class="hljs-keyword">let</span> <span class="hljs-variable">$prodDept</span> <span class="hljs-subst">:=</span> <span class="hljs-variable">$prod</span><span class="hljs-subst">/</span>@dept
<span class="hljs-keyword">where</span> <span class="hljs-variable">$prodDept</span> <span class="hljs-subst">=</span> <span class="hljs-string">"南极人"</span> <span class="hljs-literal">or</span> <span class="hljs-variable">$prodDept</span> <span class="hljs-subst">=</span> <span class="hljs-string">"果国际"</span>
<span class="hljs-keyword">return</span> <span class="hljs-variable">$prod</span>/name</code></pre>
<p>返回:</p>
<pre class="blockcode"><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-title">name</span> <span class="hljs-attribute">language</span>=<span class="hljs-value">"cn"</span>></span>毛呢外套<span class="hljs-tag"></<span class="hljs-title">name</span>></span>
<span class="hljs-tag"><<span class="hljs-title">name</span> <span class="hljs-attribute">language</span>=<span class="hljs-value">"cn"</span>></span>牛仔裤<span class="hljs-tag"></<span class="hljs-title">name</span>></span></code></pre>
<p>2.范围表达式</p>
<pre class="blockcode"><code class="language-xquery hljs bash"><span class="hljs-keyword">for</span> <span class="hljs-variable">$i</span> <span class="hljs-keyword">in</span> <span class="hljs-number">1</span> to <span class="hljs-number">3</span>
<span class="hljs-keyword">return</span> <ele>{<span class="hljs-variable">$i</span>}</ele></code></pre>
<p>返回:</p>
<pre class="blockcode"><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-title">ele</span>></span>1<span class="hljs-tag"></<span class="hljs-title">ele</span>></span>
<span class="hljs-tag"><<span class="hljs-title">ele</span>></span>2<span class="hljs-tag"></<span class="hljs-title">ele</span>></span>
<span class="hljs-tag"><<span class="hljs-title">ele</span>></span>3<span class="hljs-tag"></<span class="hljs-title">ele</span>></span></code></pre>
<p>3.多个for语句叠加</p>
<pre class="blockcode"><code class="hljs ruby"><span class="hljs-keyword">for</span> <span class="hljs-variable">$i</span> <span class="hljs-keyword">in</span> (<span class="hljs-number">1</span>, <span class="hljs-number">2</span>)
<span class="hljs-keyword">for</span> <span class="hljs-variable">$j</span> <span class="hljs-keyword">in</span> (<span class="hljs-string">"a"</span>, <span class="hljs-string">"b"</span>)
<span class="hljs-keyword">return</span><ele>i is {<span class="hljs-variable">$i</span>} <span class="hljs-keyword">and</span> j is {<span class="hljs-variable">$j</span>}<<span class="hljs-regexp">/ele></span></code></pre>
<p>返回:</p>
<pre class="blockcode"><code class="hljs vbnet"><ele>i <span class="hljs-keyword">is</span> <span class="hljs-number">1</span> <span class="hljs-keyword">and</span> j <span class="hljs-keyword">is</span> a</ele>
<ele>i <span class="hljs-keyword">is</span> <span class="hljs-number">1</span> <span class="hljs-keyword">and</span> j <span class="hljs-keyword">is</span> b</ele>
<ele>i <span class="hljs-keyword">is</span> <span class="hljs-number">2</span> <span class="hljs-keyword">and</span> j <span class="hljs-keyword">is</span> a</ele>
<ele>i <span class="hljs-keyword">is</span> <span class="hljs-number">2</span> <span class="hljs-keyword">and</span> j <span class="hljs-keyword">is</span> b</ele></code></pre>
<p>4.一个for语句绑定多个变量</p>
<pre class="blockcode"><code class="hljs ruby"><span class="hljs-keyword">for</span> <span class="hljs-variable">$i</span> <span class="hljs-keyword">in</span> (<span class="hljs-number">1</span>, <span class="hljs-number">2</span>), <span class="hljs-variable">$j</span> <span class="hljs-keyword">in</span> (<span class="hljs-string">"a"</span>, <span class="hljs-string">"b"</span>)
<span class="hljs-keyword">return</span> <ele>i is {<span class="hljs-variable">$i</span>} <span class="hljs-keyword">and</span> j is {<span class="hljs-variable">$j</span>}<<span class="hljs-regexp">/ele></span></code></pre>
<p>返回:</p>
<pre class="blockcode"><code class="hljs vbnet"><ele>i <span class="hljs-keyword">is</span> <span class="hljs-number">1</span> <span class="hljs-keyword">and</span> j <span class="hljs-keyword">is</span> a</ele>
<ele>i <span class="hljs-keyword">is</span> <span class="hljs-number">1</span> <span class="hljs-keyword">and</span> j <span class="hljs-keyword">is</span> b</ele>
<ele>i <span class="hljs-keyword">is</span> <span class="hljs-number">2</span> <span class="hljs-keyword">and</span> j <span class="hljs-keyword">is</span> a</ele>
<ele>i <span class=" |
|