Process two for each in xsl
<p>I want to process two separate nodes in for each in xsl. This is the question <a href="https://stackoverflow.com/questions/453258/how-do-i-access-elements-from-the-outer-loop-from-within-nested-loops">How do I access elements from the outer loop from within nested loops?</a> which looked similar. I tried but didnt worked even after using variable. Don't know what I'm doing wrong.</p>

<p>Here's the xml: </p>

<pre><code>&lt;root&gt;
    &lt;demomain&gt;
        &lt;demo&gt;
            &lt;name&gt;A&lt;/name&gt;
            &lt;price&gt;10&lt;/price&gt;

        &lt;/demo&gt;
        &lt;demo&gt;
            &lt;name&gt;B&lt;/name&gt;
            &lt;price&gt;15&lt;/price&gt;

        &lt;/demo&gt;
    &lt;demomain&gt;
    &lt;demomainOrig&gt;
        &lt;demoOrig&gt;
            &lt;name&gt;A&lt;/name&gt;
            &lt;price&gt;20&lt;/price&gt;           
        &lt;/demoOrig&gt;
        &lt;demoOrig&gt;
            &lt;name&gt;&lt;/name&gt;
            &lt;price&gt;25&lt;/price&gt;           
        &lt;/demoOrig&gt;
    &lt;/demomainOrig&gt;
&lt;/root&gt;
</code></pre>

<p>And the xsl I have made so far is </p>

<pre><code>&lt;xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:output method="xml" indent="yes"/&gt;
    &lt;xsl:template match="/"&gt;
&lt;demos&gt;
     &lt;xsl:for-each select="root/demomain/demo"&gt;
    &lt;xsl:variable name="newNode" select="."/&gt;
         &lt;Demo&gt;
            &lt;productID id="{$newNode/name}"/&gt;
&lt;xsl:for-each select="root/demomainOrig/demoOrig"&gt;
            &lt;price newVal="{$newNode/price}" origVal="{price}" /&gt;
    &lt;/xsl:for-each&gt;
        &lt;/Demo&gt;
    &lt;/xsl:for-each&gt;
&lt;/demos&gt;

&lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt; 
</code></pre>

<p>Following is the output that I want:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;demos&gt;
   &lt;Demo&gt;
      &lt;productID id="A"/&gt;
      &lt;price newVal="10" origVal="20"/&gt;
   &lt;/Demo&gt;
   &lt;Demo&gt;
      &lt;productID id="B"/&gt;
      &lt;price newVal="15" origVal="25"/&gt;
   &lt;/Demo&gt;
&lt;/demos&gt;
</code></pre>

<p>The problem is in the inner for each. If I remove the inner for each i get the price tag in output else it is not even displayed. And so I'm not able to get the original price for the particular item. Please Help.</p>

<p>Thanks in Advance</p>