我知道XSLT本身具有属性集,但那会强制我使用
<xsl:element name="fo:something">
每次我想要输出一个<fo:something>
在XSL-FO规范中是否有任何内容可以允许我为所有表格指定(例如)默认的属性集(边距,填充等)?
本质上,我正在寻找类似于CSS的功能,但用于FO输出而不是HTML。
我知道XSLT本身具有属性集,但那会强制我使用
<xsl:element name="fo:something">
每次我想要输出一个<fo:something>
在XSL-FO规范中是否有任何内容可以允许我为所有表格指定(例如)默认的属性集(边距,填充等)?
本质上,我正在寻找类似于CSS的功能,但用于FO输出而不是HTML。
<fo:something xsl:use-attribute-sets="myAttributeSet">
如果您想要类似于CSS的功能,那么可以在处理结束时添加另一个XSLT转换,以添加所需的属性。您可以从递归的identity转换开始,然后添加匹配您想更改的元素的模板,下面是一个简单的示例。<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:attribute-set name="commonAttributes">
<xsl:attribute name="common">value</xsl:attribute>
</xsl:attribute-set>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="someElement">
<xsl:copy use-attribute-sets="commonAttributes">
<xsl:attribute name="someAttribute">someValue</xsl:attribute>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
<xsl:transform
version="2.0"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/" priority="1000">
<!-- Store generated xsl-fo document in variable-->
<xsl:variable name="xsl-fo-document">
<xsl:next-match/>
</xsl:variable>
<!-- Copy everything to result document and apply "css" -->
<xsl:apply-templates select="$xsl-fo-document" mode="css"/>
</xsl:template>
<xsl:template match="@*|node()" priority="1000" mode="css">
<xsl:param name="copy" select="true()" tunnel="yes"/>
<xsl:if test="$copy">
<xsl:copy>
<xsl:next-match>
<xsl:with-param name="copy" select="false()" tunnel="yes"/>
</xsl:next-match>
<xsl:apply-templates select="@*|node()" mode="css"/>
</xsl:copy>
</xsl:if>
</xsl:template>
<!-- **************************** -->
<!-- CSS Examples (e.g. fo:table) -->
<!-- **************************** -->
<xsl:template match="fo:table-cell[not(@padding)]" mode="css">
<xsl:attribute name="padding" select="'2pt'"/>
<xsl:next-match/>
</xsl:template>
<xsl:template match="fo:table-header/fo:table-row/fo:table-cell" mode="css">
<xsl:attribute name="color" select="'black'"/>
<xsl:attribute name="font-style" select="'bold'"/>
<xsl:next-match/>
</xsl:template>
</xsl:transform>