相关疑难解决方法(0)

通过XSL交替行颜色的HTML表

在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)

我的偏好是在元素上使用交替的类.

html xslt html-table

15
推荐指数
1
解决办法
3万
查看次数

生成pdf时通过XSL替换表格行颜色

我是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)

xslt

4
推荐指数
1
解决办法
5075
查看次数

标签 统计

xslt ×2

html ×1

html-table ×1