我正在调用apply-templates,如下所示:
<xsl:apply-templates>
<xsl:with-param name="pWeight" select="@layoutWeight * $pContentWidth" />
</xsl:apply-templates>
我正在尝试访问apply-templates正在对其执行的子元素的layoutWeight
属性值。但是,计算始终评估为空,即使子项具有layoutWeight
的数值,pContentWidth
也是数值。
如何访问子元素apply-templates的layoutWeight
属性?
答案 0 :(得分:1)
select
上的with-param
属性是相对于周围上下文进行评估的,而不是相对于应用模板的每个节点。完成您要做的事情的一种方法是将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
并执行计算。