我有一個xslt模板,我試圖將我的項目的所有邏輯分割成不同的文件和模板,所以一切都會很好,很整齊。我使用微軟xslt處理器btw。Xslt 1.0在變量節點集上應用模板更改根節點
嗯,我遇到了這個問題,我調用apply-template作爲節點集的變量,節點集成爲根節點xml節點。
<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>
沒有模板
<!-- Works -->
<xsl:copy-of select="key('orderItemsByOrderId',key('ordersByUserId',loginID)/Id)"/>
編輯:我有它在不同的文件中設置了現在。我確實將所有文件都複製並粘貼到一個xslt中,但這仍然發生。現在,如果我撤消模板,只是有一個鍵列表('',鍵('',鍵(''.....等),它將工作,因爲「/」包含所有東西,但是當我應用模板,發生這種情況
我看到了XSLT: Process an Xml node set in a template while still having access to the document root這個問題,但我的問題更多的是爲什麼會發生這種情況,它是如何在XSLT 2.0中處理的?(即使MS將永遠不會更新到2.0)
我認爲,在XSLT 2.0結果樹片段已被廢除。是否仍然有一個「結果樹片段」像對象,但它現在支持「/」操作等?所有節點集?
Arg。這是有道理的,但它仍然很糟糕,我不能按我想要的方式組織它。 – Buttink