It sounds easy, but none of my "easy" syntax worked:
<xsl:param name="length"/>
<xsl:attribute name="width">$length</xsl:attribute>
not
<xsl:attribute name="width"><xsl:value-of-select="$length"></xsl:attribute>
any suggestions?
thanks
It sounds easy, but none of my "easy" syntax worked:
<xsl:param name="length"/>
<xsl:attribute name="width">$length</xsl:attribute>
not
<xsl:attribute name="width"><xsl:value-of-select="$length"></xsl:attribute>
any suggestions?
thanks
<xsl:attribute name="width">$length</xsl:attribute>
This will create an attribute with value the string $length
. But you want the value of the xsl:param named $length
.
<xsl:attribute name="width"><xsl:value-of-select="$length"></xsl:attribute>
Here the <xsl:value-of>
element is not closed -- this makes the XSLT code not well-formed xml.
Solution:
Use one of the following:
<xsl:attribute name="width"><xsl:value-of select="$length"/></xsl:attribute>
or
<someElement width="{$length}"/>
For readability and compactness prefer to use 2. above, whenever possible.
You probably don't even need xsl:attribute
here; the simplest way to do this is something like:
<someElement width="{$length}" ... >...</someElement>
Your first alternative fails because variables are not expanded in text nodes. Your second alternative fails because you attempt to call <xsl:value-of-select="...">
, while the proper syntax is <xsl:value-of select="..."/>
, as described in the section Generating Text with xsl:value-of in the standard. You can fix your code by using
<xsl:attribute name="width"><xsl:value-of select="$length"/></xsl:attribute>
or, as others have noted, you can use attribute value templates:
<someElement width="{$length}" ... >...</someElement>