在XSL-FO中使用外部CSS



我正在使用XSL文档创建PDF。有一些样式被定义为内联。我想在一个外部CSS文件中移动它们,但我遇到了死胡同。

这是我的代码:

<fo:table border-bottom="solid 2pt #409C94" border-top="solid 2pt #409C94" margin-bottom=".1in" background-color="#E9E9E9" text-align="center"  table-layout="fixed" width="100%" font-size="9pt">
    <fo:table-column column-width="proportional-column-width(100)"/>
    <fo:table-body width="100%" table-layout="fixed">
        <fo:table-row>
            <fo:table-cell text-align="center" padding-top=".5mm" padding-bottom=".5mm">
                <fo:block>Some text is placed here.</fo:block>
            </fo:table-cell>
        </fo:table-row>
    </fo:table-body>
</fo:table>

我想从这个文档中删除的是所有的样式标签,即:

border-bottom="solid 2pt #409C94"
border-top="solid 2pt #409C94"
margin-bottom=".1in"
background-color="#E9E9E9"
text-align="center"
table-layout="fixed"
width="100%" font-size="9pt"

我正在考虑将它们移动到CSS文件中,但任何更好的方法都会受到欢迎。

谢谢。

在Danial Haley提供的宝贵建议下,我做了一些研究并找到了解决方案。它在下面供任何人参考。

带有样式的文件(例如styles.xsl)

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:attribute-set name="CustomStyles">
    <xsl:attribute name="background-color">#BB5588</xsl:attribute>
    <xsl:attribute name="border-bottom">solid 2pt #409C94</xsl:attribute>
    <xsl:attribute name="border-top">solid 2pt #409C94</xsl:attribute>
    <xsl:attribute name="font-size">9pt</xsl:attribute>
</xsl:attribute-set>

导入样式的主文件(例如main.xsl)

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="Styles.xsl"/>
<fo:table xsl:use-attribute-sets="CustomStyles" margin-bottom=".1in" text-align="center" table-layout="fixed" width="100%">
    <fo:table-column column-width="proportional-column-width(100)"/>
    <fo:table-body width="100%" table-layout="fixed">
        <fo:table-row>
            <fo:table-cell text-align="center" padding-top=".5mm" padding-bottom=".5mm">
                <fo:block>Some text is placed here.</fo:block>
            </fo:table-cell>
        </fo:table-row>
    </fo:table-body>
</fo:table>

您可以在Main.xsl中看到,我导入了(也可以使用xsl:include)"stylesheet"Styles.xsl。在标记fo:table中,我添加了xsl:use-attribute-sets,它在VS2010中为Styles..xsl中定义的所有xsl:attribute-set提供了intellisense。

我不知道如何从文档中完全删除它们,但可以使用xsl:attribute-set将它们从fo:table中删除。

您可以将它们放在一个单独的xsl文件中,然后使用xsl:include/xsl:importxsl:call-template的组合(您的xsl:attribute-set可以放在命名模板中)。

  <xsl:attribute-set name="table">
    <xsl:attribute name="border-bottom">solid 2pt #409C94</xsl:attribute>
    <xsl:attribute name="border-top">solid 2pt #409C94</xsl:attribute>
    <xsl:attribute name="margin-bottom">.1in</xsl:attribute>
    <!-- etc... -->
  </xsl:attribute-set>

要使用它们,请将属性xsl:use-attribute-sets="table"添加到fo:table

最新更新