[英]Using external CSS in XSL-FO
我正在使用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
)“樣式表”Styles.xsl。 在標簽fo:table
,我添加了xsl:use-attribute-sets
,它在VS2010中為Styles.xsl中定義的所有xsl:attribute-set
提供了intellisense。
我不確定你怎么能完全從文檔中刪除它們,但你可以使用xsl:attribute-set
將它們移出fo:table
。
您可以將它們放在單獨的xsl文件中,然后使用xsl:include
/ xsl:import
和xsl: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
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.