【发布时间】:2014-01-09 09:36:53
【问题描述】:
我正在尝试为我的 XSLT 样式表中的每一列应用不同的颜色,但我找不到令人满意的解决方案。
这是我的 xsl 代码:
<xsl:output encoding="iso-8859-1" />
<xsl:template match ="records">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="list">
<fo:region-body></fo:region-body>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="list">
<fo:flow flow-name="xsl-region-body">
<fo:block>
<fo:table>
<fo:table-body>
<xsl:for-each select="./list">
<fo:table-row background-color="rgb(192,192,192)">
<xsl:for-each select="./item">
<fo:table-cell text-align="center">
<fo:block font-family="monospace"
font-size="12pt" color="green"
wrap-option="no-wrap" padding="5pt"
space-before="5pt" space-after="5pt">
<xsl:value-of select="val" /></fo:block>
</fo:table-cell>
</xsl:for-each>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
我来自xml的数据如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<records>
<list>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>Column 1</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>Column 2</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>Column 3</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>Column 4</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>Column 5</val>
</item>
</list>
<list>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>Value 1</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>Value 2</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>Value 3</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>Value 4</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>Value 5</val>
</item>
</list>
</records>
现在,在输出中 value1 和 column1 的表格单元格应该是相同的颜色,value2 和 column 2 应该是相同的颜色等等。但是每一列都应该有不同的颜色。
任何人都可以帮助我对我的 xsl 代码进行更改吗?提前谢谢你。
【问题讨论】: