小编the*_*tor的帖子

生成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 ×1