旋转 <TR>不使用 for-each 的背景颜色 [英] Rotate <TR> background color without using for-each

查看:20
本文介绍了旋转 <TR>不使用 for-each 的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置每个其他 <TR> 的背景颜色我没有使用 for-each 循环,因为我使用了一些模板来根据节点值过滤数据.

I am trying to set the background color of every other <TR> I am not using a for-each loop since I am using a few templates to filter data based on the nodes value.

<xsl:template match="NewDataSet">  
<html>
     <body>
    <table width="390" style="text-align:left;">
 <tr>
    <th style="text-align:left;"><span style="font:20px arial; font-weight:bold;">Agent Name</span></th>
    <th style="text-align:center;"><span style="font:20px arial; font-weight:bold;">State</span></th>
    <th style="text-align:center;" ><span style="font:20px arial; font-weight:bold;">Time</span></th>
  </tr>
        <xsl:apply-templates>
            <xsl:sort select="time" data-type="number" order="descending"/>
        </xsl:apply-templates>
    </table>

<xsl:template match="AgentSales[State=\'Talking Out\']">
    <tr>
       <xsl:apply-templates/>
    </tr>
</xsl:template>



<xsl:template match="AgentSales/AgentName">
    <td style="text-align:left;">
        <span style="font:14px arial; font-weight:bold;text-align:center;"> <xsl:value-of select="."/></span>
    </td>

</xsl:template>

<xsl:template match="AgentSales/State">
    <td style="text-align:center;">
        <span style="font:14px arial; font-weight:bold;text-align:center;"> <xsl:value-of select="."/></span>
    </td>

</xsl:template>

<xsl:template match="AgentSales/time">
    <td style="text-align:center;">
        <span style="font:14px arial; font-weight:bold;text-align:center;"> <xsl:value-of select="."/></span>
    </td>

</xsl:template>


   <xsl:template match="AgentSales/Reason | AgentSales"/>

这是我的 XML

<?xml version="1.0" encoding="ISO-8859-1"?>
<NewDataSet>
  <AgentSales>
    <AgentName>MCCALLISTER AARON</AgentName>
    <State>Talking Out</State>
    <Reason />
    <time>9</time>
  </AgentSales>
  <AgentSales>
    <AgentName>APPELHANS BARRY</AgentName>
    <State>Talking Out</State>
    <Reason />
    <time>1</time>
  </AgentSales>
  <AgentSales>
    <AgentName>ARREDONDO KARLA</AgentName>
    <State>Talking Out</State>
    <Reason />
    <time>0</time>
  </AgentSales>
</NewDataSet>

推荐答案

你可以在 CSS 中使用 :nth-child([even/odd]) :

You could do this in CSS by using :nth-child([even/odd]) :

tr:nth-child(even) td {
    background-color: #fff;
}
tr:nth-child(odd) td {
    background-color: #ccc;
}

但是,这不适用于较旧的浏览器.

However, this will not work on older browsers.

这篇关于旋转 &lt;TR&gt;不使用 for-each 的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆