Variables 如何在xslt中为所有字段设置一次颜色
我可以设置一个变量或什么的,让我们说“红色”一次,当我想一些字体是红色的,我只是调用该变量?这样,我可以编辑所有指定文本的颜色,以方便将来的可能性。我是xslt新手,非常感谢您的帮助。多谢各位 编辑:添加一些我想要的代码Variables 如何在xslt中为所有字段设置一次颜色,variables,xslt,colors,Variables,Xslt,Colors,我可以设置一个变量或什么的,让我们说“红色”一次,当我想一些字体是红色的,我只是调用该变量?这样,我可以编辑所有指定文本的颜色,以方便将来的可能性。我是xslt新手,非常感谢您的帮助。多谢各位 编辑:添加一些我想要的代码 <?xml version="1.0" encoding="utf-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="htt
<?xml version="1.0" encoding="utf-8"?><xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<!--Probably declare the variable here-->
<!--Like <variable=outputcolor value="red" -->
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="A4-portrait"
page-height="29.7cm" page-width="21.0cm" margin="2cm">
<fo:region-body />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4-portrait">
<fo:flow flow-name="xsl-region-body" font-family="Helvetica"
font-size="6pt">
<fo:block font-size="8pt" text-indent="5pt">
<fo:inline font-weight="bold"><xsl:text>Application Summary</xsl:text></fo:inline>
<!--Here i would like to make red a variable that i could possibly changed -->
<!--like fo:inline color="{outputcolor}"-->
<fo:inline color="red">
<xsl:value-of select="businessInfo/appSum" />
</fo:inline>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
申请摘要
您可以将定义为xsl:stylesheet
的直接子级,其中包含要重用的属性:
<xsl:attribute-set name="colouredText">
<xsl:attribute name="color">red</xsl:attribute>
<!-- you can set other attributes too: font-weight, font-style, ... -->
</xsl:attribute-set>
如果输出要求发生变化(“除了红色,重要信息也必须加粗”/“忘记颜色,只需将其设置为斜体”/“尝试使用漫画SAN”),则只需调整属性集中的属性定义,而无需修改应用这些“样式”的模板
xsl:use attribute sets
属性的值是一个以空格分隔的属性集名称列表:
<xsl:attribute-set name="spacedText">
<xsl:attribute name="space-before">12pt</xsl:attribute>
<xsl:attribute name="space-after">12pt</xsl:attribute>
</xsl:attribute-set>
...
<fo:block xsl:use-attribute-sets="colouredText spacedText">
This block is both coloured and spaced!
</fo:block>
12磅
12磅
...
这一块是彩色和间隔!
属性集可以依次引用其他集:
<xsl:attribute-set name="colouredTitle" use-attribute-sets="colouredText">
<xsl:attribute name="font-size">16pt</xsl:attribute>
<xsl:attribute name="text-align">center</xsl:attribute>
</xsl:attribute-set>
16磅
居中
XSL 1.0规范(or)的链接部分提供了有关如何扩展和合并属性集的更多信息。使用
属性集是一个值得探索的选项。另一种选择是执行您开始执行的操作:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<!--Probably declare the variable here-->
<xsl:variable name="outputcolor" select="'red'" />
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="A4-portrait"
page-height="29.7cm" page-width="21.0cm" margin="2cm">
<fo:region-body />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4-portrait">
<fo:flow flow-name="xsl-region-body" font-family="Helvetica"
font-size="6pt">
<fo:block font-size="8pt" text-indent="5pt">
<fo:inline font-weight="bold"><xsl:text>Application Summary</xsl:text></fo:inline>
<!--Here i would like to make red a variable that i could possibly changed -->
<fo:inline color="{$outputcolor}">
<xsl:value-of select="businessInfo/appSum" />
</fo:inline>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
申请摘要
请注意,在模板的顶层声明变量将其范围限制为仅限于该模板。您可以声明全局变量(在样式表的顶层,在任何模板之外),以使它们在样式表中的任何位置都可用。是的,您可以。如果您想要更具体的答案,请发布一些示例代码(XML+XSLT+预期输出)。此外,如果您的输出是HTML,那么您可以使用CSS实现同样的功能。
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<!--Probably declare the variable here-->
<xsl:variable name="outputcolor" select="'red'" />
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="A4-portrait"
page-height="29.7cm" page-width="21.0cm" margin="2cm">
<fo:region-body />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4-portrait">
<fo:flow flow-name="xsl-region-body" font-family="Helvetica"
font-size="6pt">
<fo:block font-size="8pt" text-indent="5pt">
<fo:inline font-weight="bold"><xsl:text>Application Summary</xsl:text></fo:inline>
<!--Here i would like to make red a variable that i could possibly changed -->
<fo:inline color="{$outputcolor}">
<xsl:value-of select="businessInfo/appSum" />
</fo:inline>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>