在xslt中不执行多个条件

问题描述 投票:0回答:1

我希望标记符合要求的等级标准。我试过xsl:choose检查标记条件,但它没有检查它总是执行的条件,否则条件。有人可以分享解决方案吗?

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>
}
xslt
1个回答
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=". &lt; 60 and . &gt; 50">
                    <xsl:value-of select="'D'"/>
            </xsl:when>
            <xsl:when test=". &lt; 70 and . &gt; 60">
                <xsl:value-of select="'C'"/>
            </xsl:when>
        </xsl:choose>
        </CD>
    </xsl:template>

    <xsl:template match="AI">
        <AI>
        <xsl:choose>
            <xsl:when test=". &lt; 60 and . &gt; 50">
                <xsl:value-of select="'D'"/>
            </xsl:when>
            <xsl:when test=". &lt; 70 and . &gt; 60">
                <xsl:value-of select="'C'"/>
            </xsl:when>
            <xsl:when test=". &lt; 50 and . &gt; 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
© www.soinside.com 2019 - 2024. All rights reserved.