gpt4 book ai didi

xml - XSLT 无法根据元素值为行着色?

转载 作者:数据小太阳 更新时间:2023-10-29 02:39:08 26 4
gpt4 key购买 nike

我需要根据数据值为行着色。如果部门是“CIT”,该行必须是青色;如果是“COMP”,黄色;如果是“IS”,粉红色;其他任何东西,灰色。我拥有所需的一切,但我只是变灰了。这是我唯一遇到的问题。

XML 代码:

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<semester name="Fall 2016">
<class>
<dept> CIT </dept>
<number>270/L</number>
<title>Integrative Programming</title>
<prereq>CIT 160/L, COMP 182/L; MATH 103, 150A OR 255A</prereq>
</class>

<class>
<dept> SOC </dept>
<number>340</number>
<title>Sociology Of Work</title>
<prereq>SOC 150</prereq>
</class>
</semester>
<semester name="Spring 2017">
<class>
<dept> CIT </dept>
<number>360</number>
<title>System Management</title>
<prereq>CIT 210/L, 270/L</prereq>
</class>
</semester>
<semester name="Fall 2017">
<class>
<dept> CIT </dept>
<number>480/L</number>
<title> CIT System Design And Implementation1 </title>
<prereq>COMP 484/L, IS 451</prereq>
</class>
<class>
<dept> COMP </dept>
<number>424</number>
<title>Computer System Security</title>
<prereq>CIT 360, IS 435</prereq>
</class>
<class>
<dept> COMP </dept>
<number>484/L</number>
<title> Web Engineering I </title>
<prereq>CIT 360</prereq>
</class>
<class>
<dept> COMP </dept>
<number>485</number>
<title>Human Computer Interaction</title>
<prereq>CIT 360, IS 451</prereq>
</class>
</semester>
<semester name="Spring 2018">
<class>
<dept> CIT </dept>
<number>481/L</number>
<title>CIT System Design And Implementation II</title>
<prereq>CIT 480/L</prereq>
</class>

XSLT 代码:

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Path to Graduation</h2>
<xsl:for-each select="catalog/semester">
<h2><xsl:value-of select="@name"/></h2>
<table border="1">
<tr bgcolor="lightgreen">
<th style="align:center;width:120px;">Catalog Number</th>
<th style="align:center;width:350px;">Title</th>
<th style="align:center;width:300px;">Prerequisites</th>
</tr>
<xsl:for-each select="class">
<xsl:choose>
<xsl:when test="dept='CIT'">
<tr bgcolor="cyan">
<td align="center"><xsl:value-of select="dept"/>
<xsl:value-of select="number"/></td>
<td align="center"><xsl:value-of select="title"/></td>
<td align="center"><xsl:value-of select="prereq"/></td>
</tr>
</xsl:when>
<xsl:when test="dept='IS'">
<tr bgcolor="pink">
<td align="center"><xsl:value-of select="dept"/>
<xsl:value-of select="number"/></td>
<td align="center"><xsl:value-of select="title"/></td>
<td align="center"><xsl:value-of select="prereq"/></td>
</tr>
</xsl:when>

<xsl:when test="dept='COMP'">
<tr bgcolor="yellow">
<td align="center"><xsl:value-of select="dept"/>
<xsl:value-of select="number"/></td>
<td align="center"><xsl:value-of select="title"/></td>
<td align="center"><xsl:value-of select="prereq"/></td>
</tr>

</xsl:when>
<xsl:otherwise>
<tr bgcolor="grey">
<td align="center"><xsl:value-of select="dept"/>
<xsl:value-of select="number"/></td>
<td align="center"><xsl:value-of select="title"/></td>
<td align="center"><xsl:value-of select="prereq"/></td>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</table>
</xsl:for-each>
</body>
</html>
</xsl:template>

最佳答案

您针对 deptxsl:when 测试因前导空格和尾随空格而失败。

针对 normalize-space(dept) 而不是 dept 进行测试以消除问题。

关于xml - XSLT 无法根据元素值为行着色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41007874/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com