我希望成绩应符合要求的成绩标准。我尝试了xsl:choose
来检查标记条件,但是它没有检查when条件,而是始终执行else条件。谁能分享解决方案?
XML:
{
<marklist>
<student>
<reg_no>100</reg_no>
<name>aaa</name>
<marks>
<CD>55</CD>
<AI>44</AI>
</marks>
</student>
<student>
<reg_no>101</reg_no>
<name>bbb</name>
<marks>
<CD>65</CD>
<AI>46</AI>
</marks>
</student>
</marklist>
}
所需的XML格式:
{
<marklist>
<student>
<reg_no>100</reg_no>
<name>aaa</name>
<grade>
<CD>D</CD>
<AI>E</AI>
</grade>
</student>
<student>
<reg_no>101</reg_no>
<name>bbb</name>
<grade>
<CD>C</CD>
<AI>E</AI>
</grade>
</student>
</marklist>
}
答案 0 :(得分:0)
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="CD">
<CD>
<xsl:choose>
<xsl:when test=". < 60 and . > 50">
<xsl:value-of select="'D'"/>
</xsl:when>
<xsl:when test=". < 70 and . > 60">
<xsl:value-of select="'C'"/>
</xsl:when>
</xsl:choose>
</CD>
</xsl:template>
<xsl:template match="AI">
<AI>
<xsl:choose>
<xsl:when test=". < 60 and . > 50">
<xsl:value-of select="'D'"/>
</xsl:when>
<xsl:when test=". < 70 and . > 60">
<xsl:value-of select="'C'"/>
</xsl:when>
<xsl:when test=". < 50 and . > 30">
<xsl:value-of select="'E'"/>
</xsl:when>
</xsl:choose>
</AI>
</xsl:template>
You may check value of CD and AI and apply Grade according to that