我知道XSLT本身有属性集,但这迫使我使用
<xsl:element name="fo:something">
每次我想输出一个
<fo:something>
标签.XSL-FO规范中是否有任何内容允许我为FO输出中的所有表指定(假设)一组默认属性(边距,填充等)?
基本上我正在寻找CSS的功能,但对于FO输出而不是HTML.
小智 11
不,您不需要使用xsl:element,如果将它放在XSLT命名空间中,则use-attribute-sets属性可以出现在文字结果元素中,因此您可以使用以下内容:
<fo:something xsl:use-attribute-sets="myAttributeSet">
如果您想要接近CSS功能,那么您可以在处理结束时添加另一个XSLT转换,以添加所需的属性.您可以从递归身份转换开始,然后添加与要更改的元素匹配的模板,请参阅下面的小示例
<?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>