0
我想创建xslt,我需要根据XML节点值检查或取消选中复选框。如果descr节点包含或等于'Student',我想检查学生复选框,否则应该取消选中它。如果decr节点包含Faculty或等于Faculty,则应该检查Faculty复选框,否则应该取消选中该复选框。基于节点值的XSLT选择复选框
我的XML是
<WI>
<Wi>
<last_nam>CLARK </last_nam>
<first_nam>HUNTER </first_nam>
<wit_flag>1</wit_flag>
<descr>Faculty </descr>
</Wi>
</WI>
<WI>
<Wi>
<last_nam>MCMENAMIN </last_nam>
<first_nam>COLLIN </first_nam>
<wit_flag>1</wit_flag>
<descr>Student </descr>
</Wi>
</WI>
XSLT是
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
</head>
<body>
<div class="container">
<table border="1">
<tr>
<td colspan="2">
Person
<br />
<xsl:value-of select="WI/Wi/lat_nam" />
</td>
</tr>
<tr>
<td>
<input id="student_flag" name="student_flag" type="checkbox"
value="1">
<xsl:choose>
<xsl:when test="WI/Wi/descr[contains(text(),Student]">
<xsl:attribute name="value">1</xsl:attribute>
<xsl:attribute name="checked">true</xsl:attribute>
<xsl:value-of select="'Student'" />
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="value">0</xsl:attribute>
<xsl:value-of select="'Student'" />
</xsl:otherwise>
</xsl:choose>
</input>
</td>
<td>
<input id="Faculty_flag" name="Faculty_flag" type="checkbox"
value="1">
<xsl:choose>
<xsl:when test="WI/Wi/descr[contains(text(),Faculty]">
<xsl:attribute name="value">1</xsl:attribute>
<xsl:attribute name="checked">true</xsl:attribute>
<xsl:value-of select="'Faculty'" />
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="value">0</xsl:attribute>
<xsl:value-of select="'Faculty'" />
</xsl:otherwise>
</xsl:choose>
</input>
</td>
</tr>
</table>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
谢谢您的回复。它检查了所有的复选框。我想根据条件检查框,如果descr包含学生,那么只应检查复选框。但即使descr不包含Faculty,它也会检查这两个复选框。 – user2897967
我修改了 1 xsl:attribute> Checked xsl:attribute> 它通过在''中添加descr文本并将true替换为checked来工作。 –
user2897967