问题:如何使用xsl:fo?
为span元素添加颜色假设我有一个带有段落块的文档,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<diffreport><css/><diff>
<p>One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked.
<span style="background-color:rgb(255, 255, 255); color:rgb(102, 102, 102)"><span class="diff-html-added" id="added-diff-0" previous="first-diff" changeId="added-diff-0" next="added-diff-1">Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts.</span></span>
</p>
</diff></diffreport>
我创建了一个xsl:fo模板文件,看起来像这样。
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:s="http://www.stylusstudio.com/xquery">
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="default-page" page-height="11in" page-width="8.5in" margin-left="0.6in" margin-right="0.6in" margin-top="0.79in" margin-bottom="0.79in">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="default-page">
<fo:flow flow-name="xsl-region-body">
<fo:block>
<fo:block text-align="center">
<fo:block>
<xsl:text>Report</xsl:text>
</fo:block>
</fo:block>
<fo:table width="100%" border-style="outset" border-width="2pt" background-repeat="repeat">
<fo:table-column/>
<fo:table-body>
<fo:table-row>
<fo:table-cell border-style="inset" border-width="2pt" padding="2pt" background-repeat="repeat" display-align="center">
<fo:block>
<xsl:text>Document</xsl:text>
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell border-style="inset" border-width="2pt" padding="2pt" background-repeat="repeat" display-align="center">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="span[@class='diff-html-added']">
<span style="color:green; background-color: #ccffcc;">
<xsl:value-of select="."/></span>
</xsl:template>
<xsl:template match="span[@class='diff-html-removed']">
<span style="color:red; text-decoration: line-through; background-color: #fdc6c6;">
<xsl:value-of select="."/></span>
</xsl:template>
<xsl:template match="span[@class='diff-html-added']" mode="clean"/>
<xsl:template match="span[@class='diff-html-removed']" mode="clean"/>
该报告正在运行,但由于某些原因,我添加的xsl模板在元素中包含红色和绿色不适合我,因为它没有显示。
<xsl:template match="span[@class='diff-html-added']">
<span style="color:green; background-color: #ccffcc;">
<xsl:value-of select="."/></span>
</xsl:template>
我需要做些什么来修复我的xsl模板,以便span元素显示为绿色或红色?