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.
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.
<xsl:import href="tblLogins.xslt"/>
<xsl:import href="tblPay_OrderItems.xslt/>
<xsl:variable name="item" select="/Entities/Data/tblLogins"/>
<!-- Get the users orders -->
<xsl:variable name="_orders" >
<xsl:apply-templates select="$item" mode="GetOrders" />
</xsl:variable>
<xsl:variable name="orders" select="msxsl:node-set($_orders)/*" />
<!-- Get the order's items -->
<!-- This works and we now have all the orders -->
<xsl:variable name="_orderItems" >
<xsl:apply-templates select="$orders" mode="GetOrderItems" />
</xsl:variable>
<xsl:variable name="orderItems" select="msxsl:node-set($_orderItems)/*" />
<!-- will always be empty -->
tblLogins.xslt
<xsl:key name="ordersByUserId" match="tblPay_Orders" use="UserId" />
<xsl:template match="tblLogins" mode="GetOrders" >
<xsl:copy-of select="key('ordersByUserId',loginID)"/>
</xsl:template>
tblPay_Order.xslt
<xsl:key name="orderItemsByOrderId" match="tblPay_OrderItems" use="OrderId" />
<xsl:template match="tblPay_Orders" mode="GetOrderItems" >
<!-- "/" is now the tblPay_Orders and nothing else is available -->
<xsl:copy-of select="key('orderItemsByOrderId',Id)"/>
<!-- will return nothing -->
</xsl:template>
Without Templates
<!-- Works -->
<xsl:copy-of select="key('orderItemsByOrderId',key('ordersByUserId',loginID)/Id)"/>
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.
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.
I saw the question XSLT: Process an Xml node set in a template while still having access to the document root 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)
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?