有什么事吗;例如;XSL-FO中内置的CSS?
我知道XSLT本身有属性集,但这迫使我使用有什么事吗;例如;XSL-FO中内置的CSS?,css,xslt,xsl-fo,Css,Xslt,Xsl Fo,我知道XSLT本身有属性集,但这迫使我使用 <xsl:element name="fo:something"> 每次我想输出一个 <fo:something> 标签。XSL-FO规范中是否有允许我为FO输出中的所有表指定(比方说)一组默认属性(边距、填充等) 本质上,我是在寻找CSS的功能,但是对于FO输出,而不是HTML。不,您不需要使用xsl:element,如果将use-attribute-set属性放在XSLT名称空间中,它可以出现在literal-r
<xsl:element name="fo:something">
每次我想输出一个
<fo:something>
标签。XSL-FO规范中是否有允许我为FO输出中的所有表指定(比方说)一组默认属性(边距、填充等)
本质上,我是在寻找CSS的功能,但是对于FO输出,而不是HTML。不,您不需要使用xsl:element,如果将use-attribute-set属性放在XSLT名称空间中,它可以出现在literal-result元素上,因此您可以使用如下内容:
<fo:something xsl:use-attribute-sets="myAttributeSet">
如果您希望具有接近CSS功能的功能,那么可以在处理结束时添加另一个XSLT转换,以添加所需的属性。您可以从递归标识转换开始,然后添加与要更改的元素匹配的模板,请参见下面的一个小示例
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:attribute-set name="commonAttributes">
<xsl:attribute name="common">value</xsl:attribute>
</xsl:attribute-set>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="someElement">
<xsl:copy use-attribute-sets="commonAttributes">
<xsl:attribute name="someAttribute">someValue</xsl:attribute>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
价值
一些价值
在XSLT2.0中还有另一个选项。
以下模板可以位于单独的文件中。您只需要将此文件包含在生成FO结构的原始xsl文件中
<xsl:transform
version="2.0"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/" priority="1000">
<!-- Store generated xsl-fo document in variable-->
<xsl:variable name="xsl-fo-document">
<xsl:next-match/>
</xsl:variable>
<!-- Copy everything to result document and apply "css" -->
<xsl:apply-templates select="$xsl-fo-document" mode="css"/>
</xsl:template>
<xsl:template match="@*|node()" priority="1000" mode="css">
<xsl:param name="copy" select="true()" tunnel="yes"/>
<xsl:if test="$copy">
<xsl:copy>
<xsl:next-match>
<xsl:with-param name="copy" select="false()" tunnel="yes"/>
</xsl:next-match>
<xsl:apply-templates select="@*|node()" mode="css"/>
</xsl:copy>
</xsl:if>
</xsl:template>
<!-- **************************** -->
<!-- CSS Examples (e.g. fo:table) -->
<!-- **************************** -->
<xsl:template match="fo:table-cell[not(@padding)]" mode="css">
<xsl:attribute name="padding" select="'2pt'"/>
<xsl:next-match/>
</xsl:template>
<xsl:template match="fo:table-header/fo:table-row/fo:table-cell" mode="css">
<xsl:attribute name="color" select="'black'"/>
<xsl:attribute name="font-style" select="'bold'"/>
<xsl:next-match/>
</xsl:template>
</xsl:transform>
对此答案底部的递归标识内容不感兴趣,但简单添加xsl:use属性集非常有效。实际上,您可以像(use attribute sets=“attributeSet1 attributeSet2”)中那样添加多个属性集引用,因此实际上,它的行为非常类似于CSS!杰出的请参阅关于用Web标准生态系统的更新内容替换旧XSL-FO