在HTML表格中交替行颜色的最简单方法是什么(a.ka.条带化).我的大多数表都是在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>
Run Code Online (Sandbox Code Playgroud)
我的偏好是在元素上使用交替的类.
我是XSLT的新手.我想在我的表行中实现替代颜色.应显示偶数行 - #EDF2F8和奇数行 - #A7BFDE.
我有一个xsl,看起来像:
<xsl:apply-templates select="records"/>
<xsl:template match="records">
<fo:table-row>
<fo:table-cell>
<xsl:value-of select="Firstname"/>
</fo:table-cell>
<fo:table-cell>
<xsl:value-of select="lastname"/>
</fo:table-cell>
<fo:table-cell>
<xsl:value-of select="Phone number"/>
</fo:table-cell>
</fo:table-row>
Run Code Online (Sandbox Code Playgroud)
我尝试使用下面的代码,但它不起作用:
<xsl:variable name="css-class">
<xsl:choose>
<xsl:when test="position() mod 2 = 0">
<xsl:attribute name="bgcolor">#EDF2F8</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="bgcolor">#A7BFDE</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<fo:table-row class="{$css-class}">
<fo:table-cell>
<xsl:value-of select="Firstname"/>
</fo:table-cell>
<fo:table-cell>
<xsl:value-of select="lastname"/>
</fo:table-cell>
<fo:table-cell>
<xsl:value-of select="Phone number"/>
</fo:table-cell>
</fo:table-row>
Run Code Online (Sandbox Code Playgroud)
我真的很感激任何帮助.
我编辑的代码的一部分,它也不起作用:
<xsl:template match="records">
<xsl:variable name="bgclr">
<xsl:choose>
<xsl:when test="position() mod 2 = 0">#A7BFDE</xsl:when>
<xsl:otherwise>#EDF2F8</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<fo:table-row bgcolor="{$bgclr}">
<fo:table-cell padding-top="0pt" …Run Code Online (Sandbox Code Playgroud)