如何在一个地方设置边框样式并在整个 XSL 中引用它

How to set the border style in one place and reference it throughout XSL

我想要一个 var/attribute 来设置边框样式并引用它,所以如果我想将边框从 1pt 更改为 2pt,我不需要在不同位置更改它。

例如我现在这样做;

<fo:table border="1pt solid black"  table-layout="fixed"
  width="100%" display-align="center">
 <fo:table-column column-width="10%" border-right="1pt solid black"/>
 <fo:table-column column-width="10%" border-right="1pt solid black"/>
 <fo:table-column column-width="23%" border-right="1pt solid black"/>
 <fo:table-column column-width="8%" border-right="1pt solid black"/>
 <fo:table-column column-width="11%" border-right="1pt solid black"/>
 <fo:table-column column-width="8%" border-right="1pt solid black"/>
 <fo:table-column column-width="20%" border-right="1pt solid black"/>
 <fo:table-header>...

我更喜欢这样的东西;

<xsl:variable
    name="border"
    select="1pt solid black">
</xsl:variable>

<fo:table border="$border"  table-layout="fixed"
  width="100%" display-align="center">
 <fo:table-column column-width="10%" border-right="$border"/>
 <fo:table-column column-width="10%" border-right="$border"/>
 <fo:table-column column-width="23%" border-right="$border"/>
 <fo:table-column column-width="8%" border-right="$border"/>
 <fo:table-column column-width="11%" border-right="$border"/>
 <fo:table-column column-width="8%" border-right="$border"/>
 <fo:table-column column-width="20%" border-right="$border"/>
 <fo:table-header>...

所以我的问题真的是可能的吗?如果是的话,正确的语法是什么?

任何帮助都会很棒,

提前致谢!

像这样定义变量(使用撇号表示文字字符串,而不是 xpath 表达式)

<xsl:variable name="border" select="'1pt solid black'" />

然后,使用Attribute Value Templates在属性中使用它

<fo:table-column column-width="20%" border-right="{$border}"/>

或者,您可以使用 Attribute Sets 实现此目的。像这样定义一个属性集

<xsl:attribute-set name="border">
    <xsl:attribute name="border-right" select="'12pt solid black'" />
</xsl:attribute-set>

然后如下使用

<fo:table-column column-width="20%" xsl:use-attribute-sets="border"/>

使用属性集,您可以在集合中包含多个属性。