我是新来的,所以如果我犯了一些错误,请不要对我太生气。我在xml中有一小段代码和一个xsl文件应该从我的xml文件中创建一个小表。但我有我的每个循环中不止一个条件,更有趣的是这两个条件不属于同一级别的节点或“父级”,一个级别在层次结构的较高级别,而且在较低级别,所以请你帮助我接着就,随即。这是xml的代码:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="DZ07.xsl"?>
<students>
<student>
<name> John </name>
<surname> Piterson </surname>
<age> 21 </age>
<exam>
<subject>
<grade> 5 </grade>
<code> IT210 </code>
</subject>
<subject>
<grade> 7 </grade>
<code> IT101 </code>
</subject>
</exam>
</student>
<student>
<name> Peter </name>
<surname> Max </surname>
<age> 26 </age>
<exam>
<subject>
<grade> 9 </grade>
<code> IT210 </code>
</subject>
<subject>
<grade> 10 </grade>
<code> IT101 </code>
</subject>
</exam>
</student>
</students>
和xsl代码:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
</head>
<body>
<h2>Students that passed the exam:</h2>
<table border="1">
<tr bgcolor="red">
<th align="left">Name</th>
<th align="left">Surname</th>
<th align="left">Age</th>
<th align="left">Grade</th>
<th align="left">Code</th>
</tr>
<xsl:for-each select="students/student[age>=22 or
students/student/exam/subject[grade>=6 and code=' IT210 ']]">
<tr bgcolor="yellow">
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="surname"/></td>
<td><xsl:value-of select="age"/></td>
<td><xsl:value-of select="grade"/></td>
<td><xsl:value-of select="code"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:0)
这应该有效
<xsl:for-each select="students/student[age>=22 or exam/subject[grade>=7 and code=' IT210 ']]">
<tr bgcolor="yellow">
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="surname"/></td>
<td><xsl:value-of select="age"/></td>
<td><xsl:value-of select="exam/subject/grade"/></td>
<td><xsl:value-of select="exam/subject/code"/></td>
</tr>
</xsl:for-each>