【问题标题】:more than one condition in for each loop in xsl filexsl 文件中的每个循环都有多个条件
【发布时间】:2017-05-28 17:37:13
【问题描述】:

我是新来的,所以如果我犯了一些错误,请不要对我太生气。所以我在 xml 中有一个小的 sn-p 代码和一个 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>

【问题讨论】:

  • 请具体说明您希望我们以何种方式提供帮助?您是否在语法、逻辑等方面苦苦挣扎……?在问题中提及它。
  • 当我在 Firefox 中启动 xml 时,我为每个循环编写的语法显然不起作用,所以任何人都可以帮助我:)

标签: xml xslt


【解决方案1】:

这应该可以工作

<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>

【讨论】:

  • 仍然无法正常工作,但感谢您的帮助,我会继续朝这个方向寻找
  • 啊我的错 :) 我忘记了一个字母 :) 谢谢 man.i 接受你的回答
猜你喜欢
  • 2018-10-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-28
  • 1970-01-01
  • 2023-01-29
  • 1970-01-01
相关资源
最近更新 更多