title: XSLT element selection based on Choose not working
body: <p>I have the following XML:</p>
  <pre><code>&lt;Document&gt;
    &lt;Row&gt;
      &lt;KEY&gt;NIKE|JB|APPAREL|MENS&lt;/KEY&gt;
      &lt;Period&gt;Nov-21&lt;/Period&gt;
    &lt;/Row&gt;
    &lt;Row&gt;
      &lt;KEY&gt;FASCINATE|JB|ACCESSORIES|LADIES&lt;/KEY&gt;
      &lt;Matches&gt;
        &lt;Row&gt;
          &lt;KEY&gt;FASCINATE|JB|ACCESSORIES|LADIES&lt;/KEY&gt;
          &lt;Period&gt;Nov-22&lt;/Period&gt;
        &lt;/Row&gt;
      &lt;/Matches&gt;
    &lt;/Row&gt;
  &lt;/Document&gt;
  </code></pre>
  <p>I want to use XSLT to return the nested <code>/Matches/Row/Period</code> when the <code>Document/Row/Period</code> is undefined (as it is in the second <code>Row</code> of the XML)</p>
  <p>So I have the following XSLT:</p>
  <pre><code>&lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;
  xmlns:ns=&quot;http://exampleincludednamespace.com/&quot;
  exclude-result-prefixes=&quot;ns&quot;&gt;
  &lt;xsl:output method=&quot;xml&quot; omit-xml-declaration=&quot;yes&quot; /&gt;
  &lt;xsl:template match=&quot;/&quot;&gt;
      &lt;Document&gt;
          &lt;xsl:for-each select=&quot;/Document/Row&quot;&gt;
              &lt;xsl:variable name=&quot;period&quot; select=&quot;/Period&quot; /&gt;
              &lt;xsl:choose&gt;
                  &lt;xsl:when test=&quot;$period = null&quot;&gt;
                      &lt;xsl:copy&gt;
                          &lt;xsl:copy-of select=&quot;KEY | /Matches/Row/Period&quot; /&gt;
                      &lt;/xsl:copy&gt;
                  &lt;/xsl:when&gt;
                  &lt;xsl:otherwise&gt;
                      &lt;xsl:copy&gt;
                          &lt;xsl:copy-of select=&quot;KEY | Period&quot; /&gt;
                      &lt;/xsl:copy&gt;
                  &lt;/xsl:otherwise&gt;
              &lt;/xsl:choose&gt;
          &lt;/xsl:for-each&gt;
      &lt;/Document&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  <p>&lt;/xsl:stylesheet&gt;</p>
  <p>But it returns the following output:</p>
  <pre><code>&lt;Document&gt;
     &lt;Row&gt;
        &lt;KEY&gt;NIKE|JB|APPAREL|MENS&lt;/KEY&gt;
        &lt;Period&gt;Nov-21&lt;/Period&gt;
     &lt;/Row&gt;
     &lt;Row&gt;
        &lt;KEY&gt;FASCINATE|JB|ACCESSORIES|LADIES&lt;/KEY&gt;
     &lt;/Row&gt;
  &lt;/Document&gt;
  </code></pre>
  <p>(Note how it is not returning the nested <code>/Matches/Row/Period</code> in the second <code>/Row</code>.</p>
  <p>I expect to get the following output:</p>
  <pre><code>&lt;Document&gt;
     &lt;Row&gt;
        &lt;KEY&gt;NIKE|JB|APPAREL|MENS&lt;/KEY&gt;
        &lt;Period&gt;Nov-21&lt;/Period&gt;
     &lt;/Row&gt;
     &lt;Row&gt;
        &lt;KEY&gt;FASCINATE|JB|ACCESSORIES|LADIES&lt;/KEY&gt;
        &lt;Period&gt;Nov-22&lt;/Period&gt;
     &lt;/Row&gt;
  &lt;/Document&gt;
  </code></pre>
  <p>What am I doing wrong?</p>