Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过XSL使用交替行颜色的HTML表格_Html_Xslt_Html Table - Fatal编程技术网

通过XSL使用交替行颜色的HTML表格

通过XSL使用交替行颜色的HTML表格,html,xslt,html-table,Html,Xslt,Html Table,在HTML表格中交替行颜色的最简单方法是什么(a.ka.striping)。我的大多数表都是在XSL模板中创建的,如下所示,带有表、thead等。。在另一个模板中定义 <xsl:template match="typ:info"> <tr> <td> <xsl:value-of select="typ:dateAccessed" /> </td> <td> <xsl:

在HTML表格中交替行颜色的最简单方法是什么(a.ka.striping)。我的大多数表都是在XSL模板中创建的,如下所示,带有表、thead等。。在另一个模板中定义

<xsl:template match="typ:info">
  <tr>
    <td>
      <xsl:value-of select="typ:dateAccessed" />
    </td>
    <td>
      <xsl:value-of select="typ:loginId" />
    </td>
  </tr>
</xsl:template>


我倾向于在元素上使用交替类。

如果必须在HTML中生成硬编码颜色:

<xsl:template match="typ:info">
  <xsl:variable name="css-class">
    <xsl:choose>
      <xsl:when test="position() mod 2 = 0">even</xsl:when>
      <xsl:otherwise>odd</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <tr class="{$css-class}">
    <td>
      <xsl:value-of select="typ:dateAccessed" />
    </td>
    <td>
      <xsl:value-of select="typ:loginId" />
    </td>
  </tr>
</xsl:template>

即使
古怪的
在今天的浏览器中,您最好使用CSS和
tr:nth child(odd)


这减少了XSLT方面的麻烦,更干净的HTML标记,并且与客户端表排序和筛选兼容。

使用XSL:When和compare position mod 2获得奇数行或偶数行,以便在需要时更改类,如:

<xsl:choose>
    <xsl:when test="position() mod 2 = 1">
        <td class="odds">blah</td>
    </xsl:when>
    <xsl:otherwise>
        <td class="even">blah</td>
    </xsl:otherwise>
</xsl:choose>

废话
废话

编辑:正确处理奇数/偶数问题

我们可能只想更改类名,而可以在变量内部选择以启用更改其内部值。大概是这样的:

<xsl:variable name="myDemoClass" >
   <xsl:choose>
     <xsl:when test="position() mod 2 = 0">
       <xsl:text>myDemoClass</xsl:text>
     </xsl:when>
     <xsl:otherwise>
       <xsl:text>myDemoClass otherClass</xsl:text>
     </xsl:otherwise>
   </xsl:choose>
</xsl:variable>

myDemoClass
myDemoClass其他类
有了它,我们可以更改变量名,然后可以更改例如div类的内容

<div class="{$myDemoClass}">


问候

您也可以使用css3

tr:nth-child(odd) { background: #ff0000; }

在相当长的一段时间内,IE9AN受到了所有其他浏览器的支持。

在我的代码中,我试图修改xsl变量值,我做了类似的事情。最后我想我也可以用来解决这种“奇偶”迭代。我知道这是男人的问题,但这是一种稍微不同的烹饪方法。比如说我想多合作,你说呢?