首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在一个地方设置边框样式并在整个XSL中引用它

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

Stack Overflow用户
提问于 2018-01-08 22:26:26
回答 1查看 2.8K关注 0票数 0

我希望有一个var/属性来设置边框样式并引用它,这样如果我想将边框从1pt更改为2pt,就不需要在不同的位置更改它。

例如,在我做这件事的时候;

代码语言:javascript
复制
<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>...

我更喜欢这样的东西:

代码语言:javascript
复制
<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>...

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

任何帮助都是最好的,

提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-08 22:32:17

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

代码语言:javascript
复制
<xsl:variable name="border" select="'1pt solid black'" />

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

代码语言:javascript
复制
<fo:table-column column-width="20%" border-right="{$border}"/>

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

代码语言:javascript
复制
<xsl:attribute-set name="border">
    <xsl:attribute name="border-right" select="'12pt solid black'" />
</xsl:attribute-set>

然后使用它,如下所示

代码语言:javascript
复制
<fo:table-column column-width="20%" xsl:use-attribute-sets="border"/>

使用属性集,您可以在集合中具有多个属性。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48152302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档