在 XSL 中突出显示表数据
我需要一些代码来突出显示表中大于或小于用户定义数字的值(需要通过 html 下拉菜单设置),即如果用户说他们想要表中的所有数据条目大于 103(例如)要被标记,它会在表中用红色背景标记它们。
这是我的 XSL 代码(用于环境数据),它正确显示链接的 XML 表中的信息。但现在我需要向页面添加可定义的搜索参数。
<xsl:value-of select="Sample/Site"/>
<table border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<th>Date</th><th>E. coli by MPN (HRC)</th><th>Total Coliforms (HRC)</th><th>Flow</th>
</tr>
<tr>
<th></th><th></th><th></th><th></th>
</tr>
<tr>
<th></th>
<th class="pad"><xsl:value-of select="Sample/Measurement[@Name='E. coli by MPN (HRC)']/Units"/></th>
<th class="pad"><xsl:value-of select="Sample/Measurement[@Name='Total Coliforms (HRC)']/Units"/></th>
<th class="pad"><xsl:value-of select="Sample/Measurement[@Name='Flow']/Units"/></th>
</tr>
<xsl:for-each select="Sample[Measurement/@Name='E. coli by MPN (HRC)' or Measurement/@Name='Total Coliforms (HRC)']">
<tr>
<td><xsl:value-of select="Date"/></td>
<td class="value"><xsl:value-of select="Measurement[@Name='E. coli by MPN (HRC)']/Value"/></td>
<td class="value"><xsl:value-of select="Measurement[@Name='Total Coliforms (HRC)']/Value"/></td>
<td class="value"><xsl:value-of select="Measurement[@Name='Flow']/Value"/></td>
</tr>
</xsl:for-each>
</table>
这是 XML 数据
<?xml version="1.0"?>
<Sample>
<Site>Manawatu at Teachers College</Site>
<Date> 1-Jul-2010 13:43</Date>
<Measurement Name="E. coli by MPN (HRC)">
<Value>147</Value>
<Units>MPN/100mL</Units>
</Measurement>
<Measurement Name="Total Coliforms (HRC)">
<Value>2420</Value>
<Units>MPN</Units>
</Measurement>
<Measurement Name="Flow">
<Value>175723</Value>
<Units>l/s</Units>
</Measurement>
</Sample>
这是输出数据
Manawatu at Teachers College
Date E. coli by MPN (HRC) Total Coliforms (HRC) Flow
MPN/100mL MPN l/s
1/07/2010 13:43 147 2420 175723
2/07/2010 14:15 102 1553 138210
5/07/2010 13:41 74 1120 83026
.....
非常感谢您的帮助。
I need some code that will highlight values in a table that are greater or less than a user-defined number (which needs to be set by a html drop-down menu) i.e. if the user says they want all the data entries in the table greater than 103 (for example) to be flagged, it will mark them with a red background in the table.
This is my XSL code (for environmental data), it correctly displays the information in the linked XML sheet. But now I need to add definable search parameters to the page.
<xsl:value-of select="Sample/Site"/>
<table border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<th>Date</th><th>E. coli by MPN (HRC)</th><th>Total Coliforms (HRC)</th><th>Flow</th>
</tr>
<tr>
<th></th><th></th><th></th><th></th>
</tr>
<tr>
<th></th>
<th class="pad"><xsl:value-of select="Sample/Measurement[@Name='E. coli by MPN (HRC)']/Units"/></th>
<th class="pad"><xsl:value-of select="Sample/Measurement[@Name='Total Coliforms (HRC)']/Units"/></th>
<th class="pad"><xsl:value-of select="Sample/Measurement[@Name='Flow']/Units"/></th>
</tr>
<xsl:for-each select="Sample[Measurement/@Name='E. coli by MPN (HRC)' or Measurement/@Name='Total Coliforms (HRC)']">
<tr>
<td><xsl:value-of select="Date"/></td>
<td class="value"><xsl:value-of select="Measurement[@Name='E. coli by MPN (HRC)']/Value"/></td>
<td class="value"><xsl:value-of select="Measurement[@Name='Total Coliforms (HRC)']/Value"/></td>
<td class="value"><xsl:value-of select="Measurement[@Name='Flow']/Value"/></td>
</tr>
</xsl:for-each>
</table>
This is the XML data
<?xml version="1.0"?>
<Sample>
<Site>Manawatu at Teachers College</Site>
<Date> 1-Jul-2010 13:43</Date>
<Measurement Name="E. coli by MPN (HRC)">
<Value>147</Value>
<Units>MPN/100mL</Units>
</Measurement>
<Measurement Name="Total Coliforms (HRC)">
<Value>2420</Value>
<Units>MPN</Units>
</Measurement>
<Measurement Name="Flow">
<Value>175723</Value>
<Units>l/s</Units>
</Measurement>
</Sample>
This is the output data
Manawatu at Teachers College
Date E. coli by MPN (HRC) Total Coliforms (HRC) Flow
MPN/100mL MPN l/s
1/07/2010 13:43 147 2420 175723
2/07/2010 14:15 102 1553 138210
5/07/2010 13:41 74 1120 83026
.....
Help would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会使用 JavaScript 解决方案。我做了一个简单的例子:
在
*.xsl
文件中,在元素之后:
I'd use JavaScript solution. I made simple example:
In
*.xsl
file, after</table>
element: