我正在嘗試洗掉<absent>表中包含該元素的任何結果。
XML:
<classTest>
<testDetails>
<description>Class Test</description>
<totalMarks>40</totalMarks>
</testDetails>
<results>
<student num="1008"><result>1</result><absent/></student>
<student num="1009"><result>23</result></student>
<student num="1007"><result>3</result></student>
<student num="1028"><result>0</result><absent/></student>
...
</results>
</classTest>
XSL:
<xsl:template match="classTest">
<html>
<body>
<table border="1">
<tr>
<td><xsl:text>Total number of students</xsl:text></td>
<td><xsl:value-of select="count(/classTest/results/student)"/></td>
</tr>
<tr>
<td><xsl:text>Total number of students absent</xsl:text></td>
<td><xsl:value-of select="count(/classTest/results/student/absent)"/></td>
</tr>
<tr>
<th style="width: 300px; text-align:center">Student number</th>
<th style="width: 150px; text-align:center">Mark</th>
</tr>
<xsl:for-each select="results/student">
<xsl:sort select="@num" order="descending"/>
<tr>
<td><xsl:value-of select="@num"/></td>
<xsl:choose>
<xsl:when test="result < 20">
<td style="color:rgb(255, 0, 0);"><xsl:number value="result"/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:number value="result"/></td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
我嘗試使用 not contains check、when 和 if 陳述句,但我似乎無法洗掉缺席學生的任何結果。我需要<absent>在我的表中包含該元素,因為我需要將缺勤學生的總數作為總和,但是在我將它們加在一起之后,我不需要將它們包含在我的表中。我需要做什么來解決這個問題?
完成后應該是這樣的: 結果
uj5u.com熱心網友回復:
代替:
<xsl:for-each select="results/student">
嘗試:
<xsl:for-each select="results/student[not(absent)]">
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/481324.html
上一篇:最終模式匹配后將字串添加到新行
下一篇:xslt中區域區域值的總和
