2016-08-29 53 views
0

我打電話申請模板如下:如何獲取XSLT模板參數中的屬性值?

<xsl:apply-templates> 
    <xsl:with-param name="pWeight" select="@layoutWeight * $pContentWidth" /> 
</xsl:apply-templates> 

我試圖訪問子元素的layoutWeight屬性值適用模板的作用。但是,即使子項的數值爲layoutWeight,pContentWidth也是一個數值,計算總是評估爲空。

如何訪問子元素的layoutWeight屬性apply-templates正在執行的操作?

回答

1

with-param上的select屬性相對於周圍環境進行評估,而不是相對於應用模板的每個節點。完成你正在試圖做的方法之一是包裹在apply-templates一個for-each

<xsl:for-each select="node()"> 
    <xsl:apply-templates select="."> 
    <xsl:with-param name="pWeight" select="@layoutWeight * $pContentWidth" /> 
    </xsl:apply-templates> 
</xsl:for-each> 

另一種選擇是隻傳遞$pContentWidth參數到apply-templates並有範本自己訪問@layoutWidth並執行計算。