title: Xslt 1.0 apply-templates on a variable node-set changes root node
body: <p>I have a xslt template and I was trying to segment all the logic for my items into different files and templates so everything would be nice and neat. I am using Microsofts xslt processor btw.</p>
  
  <p>Well, I ran into this problem where I call apply-template on a variable that is a node-set and the node-set becomes root xml node.</p>
  
  <pre><code>&lt;xsl:import href="tblLogins.xslt"/&gt;
  &lt;xsl:import href="tblPay_OrderItems.xslt/&gt;
  
  
  
              &lt;xsl:variable name="item" select="/Entities/Data/tblLogins"/&gt;
              &lt;!-- Get the users orders --&gt;
              &lt;xsl:variable name="_orders" &gt;
                  &lt;xsl:apply-templates select="$item" mode="GetOrders" /&gt;
              &lt;/xsl:variable&gt;
              &lt;xsl:variable name="orders" select="msxsl:node-set($_orders)/*" /&gt;
              &lt;!-- Get the order's items --&gt;
              &lt;!-- This works and we now have all the orders --&gt;
              &lt;xsl:variable name="_orderItems" &gt;
                  &lt;xsl:apply-templates select="$orders" mode="GetOrderItems" /&gt;
              &lt;/xsl:variable&gt;
              &lt;xsl:variable name="orderItems" select="msxsl:node-set($_orderItems)/*" /&gt;
              &lt;!-- will always be empty --&gt;
  </code></pre>
  
  <p>tblLogins.xslt</p>
  
  <pre><code>&lt;xsl:key name="ordersByUserId" match="tblPay_Orders" use="UserId" /&gt;
  
  &lt;xsl:template match="tblLogins" mode="GetOrders" &gt;
      &lt;xsl:copy-of select="key('ordersByUserId',loginID)"/&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>tblPay_Order.xslt</p>
  
  <pre><code>&lt;xsl:key name="orderItemsByOrderId" match="tblPay_OrderItems" use="OrderId" /&gt;
  
  &lt;xsl:template match="tblPay_Orders" mode="GetOrderItems" &gt;
      &lt;!-- "/" is now the tblPay_Orders and nothing else is available --&gt;
      &lt;xsl:copy-of select="key('orderItemsByOrderId',Id)"/&gt;
      &lt;!-- will return nothing --&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>Without Templates</p>
  
  <pre><code>&lt;!-- Works --&gt;
  &lt;xsl:copy-of select="key('orderItemsByOrderId',key('ordersByUserId',loginID)/Id)"/&gt;
  </code></pre>
  
  <p>EDIT: I have it set up in different files right now. I did take all of the files and copy paste them into the one xslt and this still happened.</p>
  
  <p>Now, If I undo the templates and just have a list of Key('',key('',key(''.....etc it will work because "/" contains everything still. But when I apply templates, this happens.</p>
  
  <p>I saw the question <a href="https://stackoverflow.com/questions/3109466/xslt-process-an-xml-node-set-in-a-template-while-still-having-access-to-the-doc">XSLT: Process an Xml node set in a template while still having access to the document root</a> which is a way to get around it. But my question is more of a why does this even happen and how is it handled in XSLT 2.0? (even though MS will never update to 2.0)</p>
  
  <p>I thought that in XSLT 2.0 the result tree fragment was done away with. Is there still a "Result Tree Fragment" like object, but it now supports "/" operations and such? or is everything a node-set?</p>