【发布时间】:2018-02-23 11:53:03
【问题描述】:
我有一个像这样的.xsl 文件:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:exslt="http://exslt.org/common">
<xsl:template match="/>
<fo:root>
<fo:block>...</fo:block>
</fo:root>
</xsl:template>
</xsl:stylesheet>
如何使用模板匹配生成的fo 元素并为其设置样式?例如,如果我想给我的fo:table-cells 提供红色背景,我希望能够做到
<xsl:template match="fo:table-cell">
<xsl:attribute name="background-color">red</xsl:attribute>
</xsl:template>
我找到了this,然后尝试了类似
<xsl:template match="/>
<xsl:variable name="foRoot">
<fo:root>
<fo:block>...</fo:block>
</fo:root>
</xsl:variable>
<xsl:apply-templates select="exslt:node-set($foRoot)" />
</xsl:template>
但是由于无限递归,这会导致堆栈溢出。当我试图避免这种情况时,例如通过做
<xsl:apply-templates select="exslt:node-set($foRoot)/*" />
我得到一个空文件。当试图通过添加来修复那个时
<xsl:copy-of select="$foRoot" />
之后,我没有收到任何错误,但表格单元格仍然具有默认的白色背景。
【问题讨论】: