2013-07-05 35 views
3

我正在使用XSL文檔來創建PDF。有一些樣式定義爲內聯。我想將它們移動到一個外部CSS文件中,但我已經死了。在XSL-FO中使用外部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文件但任何更好的方法都會受到歡迎。

謝謝。

回答

6

有了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。

3

我不知道如何完全從文檔中刪除它們,但可以使用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

+0

謝謝丹尼爾。你的解決方案給了我應該去的方向,並基於此,我搜索了一些例子。我將介紹回覆此線程的解決方案。 – Farhan