XSL-FO中是否内置了"喜欢"的CSS?

Jay*_*ens 10 css xslt xsl-fo

我知道XSLT本身有属性集,但这迫使我使用

<xsl:element name="fo:something">
Run Code Online (Sandbox Code Playgroud)

每次我想输出一个

<fo:something>
Run Code Online (Sandbox Code Playgroud)

标签.XSL-FO规范中是否有任何内容允许我为FO输出中的所有表指定(假设)一组默认属性(边距,填充等)?

基本上我正在寻找CSS的功能,但对于FO输出而不是HTML.

小智 11

不,您不需要使用xsl:element,如果将它放在XSLT命名空间中,则use-attribute-sets属性可以出现在文字结果元素中,因此您可以使用以下内容:

<fo:something xsl:use-attribute-sets="myAttributeSet">
Run Code Online (Sandbox Code Playgroud)

如果您想要接近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>
Run Code Online (Sandbox Code Playgroud)