title: Using conditions in XSLT/XPath to avoid a calculation
body: <p>Suppose I have two functions, one simple and one complex, which I bind to global variables:</p>
  
  <pre><code>&lt;xsl:variable name="a" select="eg:quick-func()"/&gt;
  &lt;xsl:variable name="b" select="e.g.:very-long-func()"/&gt;
  </code></pre>
  
  <p>I want to avoid calculating $b if $a is true, to avoid a lot of processing time. In testing the three options below (Saxon 9) I find that $b is calculated even when $a is true.</p>
  
  <pre><code>&lt;xsl:copy-of select="if ($a) then $a else $b"/&gt;
  
  &lt;xsl:copy-of select="($a,$b)[1]"/&gt;
  
  &lt;xsl:choose&gt;
    &lt;xsl:when test="$a"&gt;
      &lt;xsl:copy-of select="$a"/&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:otherwise&gt;
      &lt;xsl:copy-of select="$b"/&gt;
    &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
  </code></pre>
  
  <p>Is there a work-around?</p>