考慮一個案例,我必須得到通過的學生人數,如果他通過了所有考試,他會被認爲通過。如何在xslt中將變量加1?
<testResults version="1.2">
<student test="1" pass="true" name="A"></student>
<student test="2" pass="true" name="A"></student>
<student test="1" pass="false" name="B"></student>
<student test="2" pass="true" name="B"></student>
<student test="1" pass="false" name="C"></student>
<student test="2" pass="false" name="C"></student>
<student test="1" pass="true" name="D"></student>
<student test="2" pass="true" name="D"></student>
</testResults>
我想獲得通過所有科目的學生人數。我怎麼做? 我得到了一種方法,我遍歷所有的學生,並顯示誰通過了所有,但我如何得到所有學生的人數。
我使用,
<xsl:for-each select="/testResults/student/[not(@name = preceding::*/@name)]">
<xsl:variable name="allFailureCount" select="count(/testResults/*[attribute::pass='false'][@tn = current()/@name])" />
<xsl:choose>
<xsl:when test="$allFailureCount > 0"></xsl:when>
<xsl:otherwise><xsl:value-of select="@name" /></xsl:otherwise>
</xsl:choose>
</xsl:for-each>
你可以編輯你的問題,顯示你的當前方法,讓學生誰通過?謝謝 –
簡單的答案是,你沒有。在XSLT中,您無法更改變量的值,您可以將其設置爲一次,就是這樣。 (是的,我知道這聽起來很奇怪。)如果你想計算一些東西,你只需調用'count()'XPath函數。 – biziclop
嗨@biziclop您如何使用XPath計數函數? –