我有一个XSL文档,其中插入了可变数量的文章.我需要文章的背景颜色交替 – “奇怪”然后“偶数”
<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中的代码时遇到了问题.
使用:
<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};">
原文地址:https://www.jb51.cc/xml/292049.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。