我有一个XSL文档,其中插入了可变数量的文章.我需要文章的背景颜色交替 – “奇怪”然后“偶数”
@H_502_1@<xsl:for-each select="newsletter/section/article">
<tr class="odd" style="background-color: #efefef;">
<td valign="top">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="link" />
</xsl:attribute>
<img align="left" valign="top" width="110"
style="padding: 0 4px 4px 0; border:0;">
<xsl:attribute name="alt">
<xsl:value-of select="title" />
</xsl:attribute>
<xsl:attribute name="src">
<xsl:value-of select="img" />
</xsl:attribute>
</img>
</xsl:element>
</td>
<td valign="top" style="padding: 4px 4px 18px 0;">
<strong>
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="link" />
</xsl:attribute>
<xsl:value-of select="title"/>
</xsl:element>
</strong>
<br />
<xsl:value-of select="excerpt"/>
</td>
</tr>
</xsl:for-each>
我看过这篇文章:HTML table with alternating row colors via XSL
但我相信我的情况有所不同.我只需要在每次迭代时更改tr类.很抱歉奇怪的格式化,我似乎在浏览Chrome中的代码时遇到了问题.
使用:
@H_502_1@<xsl:for-each select="newsletter/section/article">
<xsl:variable name="vColor">
<xsl:choose>
<xsl:when test="position() mod 2 = 1">
<xsl:text>#efefef</xsl:text>
</xsl:when>
<xsl:otherwise>#ababab</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<tr class="odd" style="background-color: {$vColor};">