为什么我的XSLT计数器变量没有更新?



这是我的XML:

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<product id="V123049">
<name>Bendable Sunglasses</name>
<price>30</price>
<quantity>1030</quantity>
</product>
<product id="C039890">
<name>Sports Wrist Watch</name>
<price>60</price>
<quantity>1430</quantity>
</product>
<product id="M392829">
<name>AutoPilot Road Navigator</name>
<price>19</price>
<quantity>129</quantity>
</product>
<product id="D190315">
<name>StealthFinder GPS for Laptop</name>
<price>100</price>
<quantity>45</quantity>
</product>
<product id="E938393">
<name>Frye Folding Leather Shopper</name>
<price>89</price>
<quantity>230</quantity>
</product>
<product id="V392839">
<name>Pachislo Slot Machine</name>
<price>595</price>
<quantity>95</quantity>
</product>
<product id="K928379">
<name>Sterling Cross Necklace</name>
<price>100</price>
<quantity>329</quantity>
</product>
<product id="I303920">
<name>World Time Calculator</name>
<price>30</price>
<quantity>698</quantity>
</product>
</catalog>

我想显示价格超过100的数量。

下面是我写的代码:
<xsl:for-each select="//product"> 
<xsl:variable name="pr" select="//price" />
<xsl:variable name="counter" >0</xsl:variable>
<xsl:variable name="var" >100</xsl:variable>
<xsl:if test="$pr>=$var">
<xsl:variable name="counter" select="$counter +1" />
</xsl:if>
</xsl:for-each>
<span class="text"> Total Products(price>=100):<xsl:value-of select="$counter"/>  </span>
</p>

不仅没有显示数字,XSLT也不能工作,只显示普通代码,而不是输出。

我检查了大部分代码,似乎主要问题是这一行:

<xsl:variable name="counter" select="$counter +1" />

我已经找过了,但没有找到解决这个问题的办法。

完全放弃过程循环,对输入使用单个声明式表达式:

<xsl:value-of select="count(/catalog/product[price > 100])"/>.

有关基本原理的进一步解释,请参见如何在XSLT中更改或重新分配变量?