【发布时间】:2011-05-30 23:16:12
【问题描述】:
我有一个父变量和两个子变量用于累积
我想用这两个子变量来选择两个不同的值
我只能对其进行硬编码以使其像所有其他教程一样工作 例如:$parent[1]/Price 和 $parent[1]/Quantity
但我想要以下内容:
$parent[1]/$child1 where $parent[1] = orders[1]/order and $child1 = price
$parent[1]/$child2 where $parent[1] = orders[1]/order and $child2 = quantity
<xsl:call-template name="total">
<xsl:with-param name="pList" select="$parent"/>
<xsl:with-param name="price" select="Price"/>
<xsl:with-param name="quantity" select="Quantity"/>
</xsl:call-template>
<xsl:template name="total">
<xsl:param name="pListItem"/>
<xsl:param name="pAccum" select="0"/>
<xsl:param name="price"/>
<xsl:param name="quantity"/>
<xsl:choose>
<xsl:when test="$pListItem">
<xsl:call-template name="total">
<xsl:with-param name="pListItem" select="$pListItem[position() > 1]"/>
<xsl:with-param name="pAccum"
select="$pAccum + $vHead/$price * $vHead/$quantity"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$pAccum"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
【问题讨论】:
-
虽然不清楚你的问题是什么(根本没有指定问题),但我尝试尽可能多地猜测,并在我的回答中提供了一个完整、简短、通用且简单的解决方案我相信是你的问题。 +1 艰难的开始。一开始一切都很困难:)
标签: xml xslt accumulate