How to use xsl variable in attribute value?

R

Richard

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?
 
R

Richard

Never mind. I found that I can do the following:
<xsl:variable name="var">VarValue</xsl:variable>
<Element>
 
G

Gerald Aichholzer

Richard said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top