title: Xquery: nested ifs
body: <p>Basically I have several sequences that may be empty, if they are empty then I don't want to output it's parent node. If all of the sequences are empty then I don't want the containing node. Basically I have code similiar to this, which doesn't work:</p>
  
  <pre><code>let $a := //a
  let $b := //b
  
  return
  &lt;root&gt;
     {if (exists($a) or exists($b)) then
        &lt;div id="container"&gt;
           {if (exists($a)) then
              &lt;h2&gt;As&lt;/h2&gt;
              &lt;div&gt;
                 {for loop for $a sequence...}
              &lt;/div&gt;
            else()
            }
            {if (exists($b)) then
              &lt;h2&gt;Bs&lt;/h2&gt;
              &lt;div&gt;
                 {for loop for $b sequence...}
              &lt;/div&gt;
            else()
            }
        &lt;/div&gt;
      else()
      }
  &lt;/root&gt;
  </code></pre>