title: Using position() to select a specific node while in a for-each loop in xslt not returning expected results
body: <p>I realize this code isn't the cleanest, but properly refactoring it unfortunately isn't an option.</p>
  
  <p>The issue is that I would expect <code>position()</code> on the second iteration to return a true value. But when using <code>position()</code> it never returns true, as expected on the second iteration.</p>
  
  <p>But if I hard code the selection values, it returns the expected result. Here is an example:</p>
  
  <pre><code>&lt;root&gt;
    &lt;MainProducts&gt;
      &lt;MainProduct&gt;
        &lt;Published&gt;0&lt;/Published&gt;
      &lt;/MainProduct&gt;
      &lt;MainProduct&gt;
        &lt;Published&gt;1&lt;/Published&gt;
      &lt;/MainProduct&gt;
    &lt;/MainProducts&gt;
    &lt;SubProducts&gt;
      &lt;SubProduct&gt;
        &lt;IsDefault&gt;1&lt;/IsDefault&gt;
      &lt;/SubProduct&gt;
      &lt;SubProduct&gt;
        &lt;IsDefault&gt;0&lt;/IsDefault&gt;
      &lt;/SubProduct&gt;
    &lt;/SubProducts&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p><br />
  <br />
  XML content:</p>
  
  <pre><code>&lt;xsl:for-each select="/root/SubProducts/SubProduct"&gt;
    &lt;script type="text/javascript"&gt;
      // Always returns false
      console.log("Dynamic position " + &lt;xsl:value-of select="position()" /&gt; + " IsDefault: " + ( &lt;xsl:value-of select="/root/MainProducts/MainProduct[position()]/Published" /&gt; == 1 ? "true" : "false" ));
    &lt;/script&gt;
  &lt;/xsl:for-each&gt;
  
  &lt;script type="text/javascript"&gt;
    // Returns false, but expected to return true on second iteration.
    console.log("Hard coded position 1 IsDefault: " + ( &lt;xsl:value-of select="/root/MainProducts/MainProduct[1]/Published" /&gt; == 1 ? "true" : "false" ));
  
    // Returns true
    console.log("Hard coded position 2 IsDefault: " + ( &lt;xsl:value-of select="/root/MainProducts/MainProduct[2]/Published" /&gt; == 1 ? "true" : "false" ));
  &lt;/script&gt;
  </code></pre>
  
  <p><br/><br/>
  Here is the exact console output:</p>
  
  <pre><code>Dynamic position 1 IsDefault: false
  Dynamic position 2 IsDefault: false
  Hard coded position 1 IsDefault: false
  Hard coded position 2 IsDefault: true
  </code></pre>
  
  <p>What am I missing here that <code>position()</code> isn't selecting the node properly?</p>