[英]How to get an attributes value within a XSLT template parameter?
我正在調用apply-templates,如下所示:
<xsl:apply-templates>
<xsl:with-param name="pWeight" select="@layoutWeight * $pContentWidth" />
</xsl:apply-templates>
我正在嘗試訪問apply-templates作用於其上的子元素的layoutWeight
屬性值。 但是,即使子項具有layoutWeight
的數值,並且pContentWidth
也是數值,該計算也總是評估為空。
如何訪問子元素apply-template正在作用的layoutWeight
屬性?
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
並執行計算。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.