如何在xsl:attribute name ="width"中使用xsl:param值

Ele*_*ena 5 xslt width

听起来很简单,但我的"简单"语法都不起作用:

<xsl:param name="length"/>
<xsl:attribute name="width">$length</xsl:attribute>
not
<xsl:attribute name="width"><xsl:value-of-select="$length"></xsl:attribute>
Run Code Online (Sandbox Code Playgroud)

有什么建议?

谢谢

Dim*_*hev 8

<xsl:attribute name="width">$length</xsl:attribute>

这将创建一个值为字符串的属性$length.但是你想要命名的xsl:param的值$length.

<xsl:attribute name="width"><xsl:value-of-select="$length"></xsl:attribute>

这里<xsl:value-of>元素没有关闭 - 这使得XSLT代码没有格式良好的xml.

方案:

使用以下之一:

  1. <xsl:attribute name="width"><xsl:value-of select="$length"/></xsl:attribute>

要么

  1. <someElement width="{$length}"/>

为了可读性和紧凑性,尽可能使用上面的2 .