xml – 使用XSL在tr类中交替显示行颜色
发布时间:2020-12-16 23:49:03 所属栏目:百科 来源:网络整理
导读:我有一个XSL文档,其中插入了可变数量的文章.我需要文章的背景颜色交替 – “奇怪”然后“偶数” xsl:for-each select="newsletter/section/article" tr class="odd" style="background-color: #efefef;" td valign="top" xsl:element name="a" xsl:attribute
我有一个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};"> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |