在 XSL 中突出显示表数据

发布于 2024-11-15 00:39:46 字数 2761 浏览 1 评论 0原文

我需要一些代码来突出显示表中大于或小于用户定义数字的值(需要通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里的微风 2024-11-22 00:39:46

我会使用 JavaScript 解决方案。我做了一个简单的例子:

*.xsl 文件中,在 元素之后:

<script>
<![CDATA[

var td_elements=document.getElementsByTagName("td");
var td_elements_with_values=[];

for(var i=0; i<td_elements.length; ++i)
{
   if(td_elements[i].className=="value")
      td_elements_with_values.push(td_elements[i]);
}

var td_elements_with_values_length = td_elements_with_values.length;

function highlight()
{
   var number = parseFloat(document.getElementById("number").value);
   var find_greater = document.getElementById("greater").checked;

   for (var i=0; i<td_elements_with_values_length; ++i)
   {
      var value=parseFloat(td_elements_with_values[i].firstChild.nodeValue);
      if(find_greater)
      {
         if(number<value)td_elements_with_values[i].style.color="red";
         else td_elements_with_values[i].style.color="black";
      }
      else if(number>value)td_elements_with_values[i].style.color="red";
      else td_elements_with_values[i].style.color="black";
}
]]>
</script>
<form>
   <label for="number">Define number</label><br/>
   <input type="text" id="number"/><br/>
   <input type="radio" id="greater" name="greater_or_less" checked="checked"/>
   <label for="greater">greater</label><br/>
   <input type="radio" id="less" name="greater_or_less"/>
   <label for="less">less</label><br/>
   <input type="button" value="highlight" onclick="highlight()"/>
</form>

I'd use JavaScript solution. I made simple example:

In *.xsl file, after </table> element:

<script>
<![CDATA[

var td_elements=document.getElementsByTagName("td");
var td_elements_with_values=[];

for(var i=0; i<td_elements.length; ++i)
{
   if(td_elements[i].className=="value")
      td_elements_with_values.push(td_elements[i]);
}

var td_elements_with_values_length = td_elements_with_values.length;

function highlight()
{
   var number = parseFloat(document.getElementById("number").value);
   var find_greater = document.getElementById("greater").checked;

   for (var i=0; i<td_elements_with_values_length; ++i)
   {
      var value=parseFloat(td_elements_with_values[i].firstChild.nodeValue);
      if(find_greater)
      {
         if(number<value)td_elements_with_values[i].style.color="red";
         else td_elements_with_values[i].style.color="black";
      }
      else if(number>value)td_elements_with_values[i].style.color="red";
      else td_elements_with_values[i].style.color="black";
}
]]>
</script>
<form>
   <label for="number">Define number</label><br/>
   <input type="text" id="number"/><br/>
   <input type="radio" id="greater" name="greater_or_less" checked="checked"/>
   <label for="greater">greater</label><br/>
   <input type="radio" id="less" name="greater_or_less"/>
   <label for="less">less</label><br/>
   <input type="button" value="highlight" onclick="highlight()"/>
</form>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文