Far*_*han 5 css xml xslt 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>
Run Code Online (Sandbox Code Playgroud)
我想要的是从本文档中删除所有样式标记,即:
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"
Run Code Online (Sandbox Code Playgroud)
我想在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>
Run Code Online (Sandbox Code Playgroud)
我导入样式的主文件(例如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>
Run Code Online (Sandbox Code Playgroud)
在这里你可以看到Main.xsl,我有一个导入(也可以使用xsl:include)"样式表"Styles.xsl.在标签中fo:table,我补充说xsl:use-attribute-sets,在VS2010中,它为xsl:attribute-setStyles.xsl中定义的所有内容提供了智能感知.
我不确定如何将它们从文档中完全删除,但是可以将其从中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>
Run Code Online (Sandbox Code Playgroud)
要使用它们,请将属性添加xsl:use-attribute-sets="table"到fo:table。
| 归档时间: |
|
| 查看次数: |
4095 次 |
| 最近记录: |