简体   繁体   English

在XSL-FO中使用外部CSS

[英]Using external CSS in XSL-FO

I am using an XSL document to create a PDF. 我正在使用XSL文档来创建PDF。 There are some styles defined as inline. 有些样式定义为内联。 I want to move them in an external CSS file, but I am hitting a dead end. 我想在外部CSS文件中移动它们,但我正在走向死胡同。

Here is my code: 这是我的代码:

<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>

What I want is to remove from this document are all the styling tags, ie: 我想要的是从本文档中删除所有样式标记,即:

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"

I am thinking to move them in a CSS file but any better method will be welcomed. 我想在CSS文件中移动它们,但欢迎任何更好的方法。

Thanks. 谢谢。

With the valuable suggestion provided by Danial Haley, I did some research and found the solution. 根据Danial Haley提供的宝贵建议,我做了一些研究并找到了解决方案。 It is below for anyone's reference. 以下是任何人的参考。

File with styles (eg Styles.xsl) 带样式的文件(例如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>

My main file where I am importing styles (eg Main.xsl) 我导入样式的主文件(例如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>

Here you can see in Main.xsl, that I have a imported (could also have used xsl:include ) the "stylesheet" Styles.xsl. 在这里你可以看到Main.xsl,我有一个导入(也可以使用xsl:include )“样式表”Styles.xsl。 In the tag fo:table , I added xsl:use-attribute-sets , which in VS2010, provided intellisense for all the xsl:attribute-set defined in Styles.xsl. 在标签fo:table ,我添加了xsl:use-attribute-sets ,它在VS2010中为Styles.xsl中定义的所有xsl:attribute-set提供了intellisense。

I'm not sure how you could remove them from the document entirely, but you could use xsl:attribute-set to move them out of the fo:table . 我不确定你怎么能完全从文档中删除它们,但你可以使用xsl:attribute-set将它们移出fo:table

You could probably put them in a separate xsl file and then use a combination of xsl:include / xsl:import and xsl:call-template (your xsl:attribute-set could be put in a named template). 您可以将它们放在单独的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>

to use them, add the attribute xsl:use-attribute-sets="table" to fo:table . 要使用它们,请将属性xsl:use-attribute-sets="table"fo:table

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM