我有以下学生xml文档。是否可以在输出中用值 DELETED 替换值 true ?
xml doc code
<Student>
<Deleted>true</Deleted>
</Student>
xslt代码
<Student>
<xsl:choose>
<xsl:when test="Deleted='true'">
<xsl:value-of select="Deleted"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="PRESENT"/>
</xsl:otherwise>
</xsl:choose>
</Student>
我希望输出
<Student>
<StudentDeleted>DELETED</StudentDeleted>
</Student>
以下是我得到的输出,而不是我想要的
<Student>
<StudentDeleted>true</StudentDeleted>
</Student>
答案 0 :(得分:1)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:template match="Student">
<Student>
<xsl:choose>
<xsl:when test="child::Deleted/text()='true'">
<StudentDeleted>
<xsl:value-of select="'Deleted'"/>
</StudentDeleted>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="PRESENT"/>
</xsl:otherwise>
</xsl:choose>
</Student>
</xsl:template>