xslt - 如何通过@variable在xsl中添加样式属性
问题描述
我有一个变量@expectedLength。我需要将其分配给样式属性。
<xsl:if test="@expectedLength">
<xsl:attribute name="style">
<xsl:value-of select="'width:200px'"/>
</xsl:attribute>
</xsl:if>
我需要用@expectedLength 的值替换200。如何使用变量?
解决方案
您可以将您的代码段更改为
<xsl:if test="@expectedLength">
<xsl:attribute name="style">width: <xsl:value-of select="@expectedLength"/>;</xsl:attribute>
</xsl:if>
这应该适用于任何版本的 XSLT。
在 XSLT 2 及更高版本中,您还可以使用select
表达式
<xsl:if test="@expectedLength">
<xsl:attribute name="style" select="concat('width: ', @expectedLength, ';')"/>
</xsl:if>
我更愿意并建议设置一个模板
<xsl:template match="@expectedLength">
<xsl:attribute name="style" select="concat('width: ', @expectedLength, ';')"/>
</xsl:template>
然后确保处理任何属性节点。
推荐阅读
- excel-formula - 无法过滤 sumprod 中的空单元格
- php - 字体文件在控制台上显示为未找到,并且在页面加载时未立即呈现
- python - 实时物体检测python
- c++ - 将两个字符串合并为布尔表达式
- sql - Ms Access 数据库的 SQL 查询。从相似 id 组查询访问数据库
- javascript - 如何通过滚动来缩放元素?
- extendscript - After Effects 脚本 - 来自源素材的 inPoint
- flutter - StorageReference 不是一种类型
- python - 当我不希望它时,Panda 会尝试将我的字符串转换为浮点数
- swift - 结构的异步闭包递归