【发布时间】:2016-12-07 05:24:24
【问题描述】:
问题:如何使用 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 元素显示为绿色或红色?
【问题讨论】:
-
没关系...重读你的大部分内容。
-
xsl fo 中没有跨度这样的元素。也许您打算将其更改为 fo:inline 并且您缺少 xsl fo 命名空间