這是我的 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" />
我已經搜索過,但沒有找到任何可以解決的問題。
uj5u.com熱心網友回復:
完全放棄程式回圈并在輸入上使用單個宣告性運算式:
<xsl:value-of select="count(/catalog/product[price > 100])"/>.
有關原理的進一步解釋,請參閱如何在 XSLT 中更改或重新分配變數?
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/334361.html
上一篇:在php中從xml中檢索密鑰
下一篇:xml檔案換行請求
