title: Copying an XSLT variable
body: <p>I'm working on an Umbraco XSL Stylesheet and I am pretty stuck.</p>
  
  <p>Basically, I have a parameter that I test and use it's value if it's present, otherwise I use the default parameter <code>$currentPage</code>.</p>
  
  <p><strong>Here are the parameters</strong></p>
  
  <pre><code>&lt;xsl:param name="source" select="/macro/sourceId" /&gt;
  &lt;xsl:param name="currentPage" /&gt;
  </code></pre>
  
  <p><strong>Here's the variable</strong></p>
  
  <pre><code>&lt;xsl:variable name="current"&gt;
      &lt;xsl:choose&gt;
          &lt;xsl:when test="$source &amp;gt; 0"&gt;
              &lt;xsl:copy-of select="umbraco.library:GetXmlNodeById($source)" /&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:otherwise&gt;
              &lt;xsl:copy-of select="$currentPage" /&gt;
          &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
  &lt;/xsl:variable&gt;
  </code></pre>
  
  <p><strong>And here's where I use it</strong></p>
  
  <pre><code>&lt;xsl:for-each select="msxml:node-set($source)/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']"&gt;
  ... code here ...
  &lt;/xsl:for-each&gt;
  </code></pre>
  
  <p><br />
  <em><h3>In a nutshell</h3></em></p>
  
  <p><strong>This works</strong></p>
  
  <pre><code>&lt;xsl:variable name="source" select="$currentPage" /&gt;
  </code></pre>
  
  <p><strong>This doesn't</strong></p>
  
  <pre><code>&lt;xsl:variable name="source"&gt;
    &lt;xsl:copy-of select="$currentPage" /&gt; &lt;!-- Have tried using &lt;xsl:value-of /&gt; as well --&gt;
  &lt;/xsl:variable&gt;
  </code></pre>
  
  <p>So how do you copy a variable without using the <code>select=""</code> attribute.</p>
  
  <blockquote>
    <p><strong>UPDATE:</strong> I've tried using another approach (see below) but I get a <em>variable out of scope</em> exception.</p>
  </blockquote>
  
  <pre><code>&lt;xsl:choose&gt;
      &lt;xsl:when test="$source &amp;gt; 0"&gt;
          &lt;xsl:variable name="current" select="umbraco.library:GetXmlNodeById($source)" /&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
          &lt;xsl:variable name="current" select="$currentPage" /&gt;
      &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
  </code></pre>