469,265 Members | 1,991 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,265 developers. It's quick & easy.

How to use xsl variable in attribute value?

Suppose I create a variable named "var" such as:
<xsl:variable name="var">VarValue</xsl:variable>
and then I want to insert its value into an attribute
<Element attr=" {the value of var} ">
so that it would generate
<Element attr=" VarValue ">

What syntax do I use to do this? If I specify
<Element attr=" <xsl:value-of select='$var'/> ">
then the parser complains that &lt; &gt; must be used for
brackets inside attribute values. However, if I change it to
<Element attr=" &lt;xsl:value-of select='$var'/&gt; ">
then it generates exactly that string with no variable
substitution. I tried using quotes and brackets in various
ways with no success. Is there a way to insert a variable's
value into an attribute?
Jul 20 '05 #1
2 30175
Never mind. I found that I can do the following:
<xsl:variable name="var">VarValue</xsl:variable>
<Element>
<xsl:attribute name="attr"><xsl:value-of select="$var" /></xsl:attribute>
</Element>

Suppose I create a variable named "var" such as:
<xsl:variable name="var">VarValue</xsl:variable>
and then I want to insert its value into an attribute
<Element attr=" {the value of var} ">
so that it would generate
<Element attr=" VarValue ">

What syntax do I use to do this? If I specify
<Element attr=" <xsl:value-of select='$var'/> ">
then the parser complains that &lt; &gt; must be used for
brackets inside attribute values. However, if I change it to
<Element attr=" &lt;xsl:value-of select='$var'/&gt; ">
then it generates exactly that string with no variable
substitution. I tried using quotes and brackets in various
ways with no success. Is there a way to insert a variable's
value into an attribute?

Jul 20 '05 #2
Richard wrote:
Never mind. I found that I can do the following:
<xsl:variable name="var">VarValue</xsl:variable>
<Element>
<xsl:attribute name="attr"><xsl:value-of select="$var" /></xsl:attribute>
</Element>


<Element attr="{$var}"/>

should work, too.

HTH,
Gerald
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Andrew Lord | last post: by
5 posts views Thread by Mateusz Loskot | last post: by
6 posts views Thread by Newbie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.