Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > How to use xsl variable in attribute value?

Reply
Thread Tools

How to use xsl variable in attribute value?

 
 
Richard
Guest
Posts: n/a
 
      08-27-2004
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?
 
Reply With Quote
 
 
 
 
Richard
Guest
Posts: n/a
 
      08-27-2004
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?



 
Reply With Quote
 
 
 
 
Gerald Aichholzer
Guest
Posts: n/a
 
      08-28-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I use a variable or parameter in an <xsl:if> expression to compare it with the value of an xml attribute? mark4asp XML 2 12-04-2007 07:58 AM
XSL: putting a XSL value inside an html attribute? Kourosh XML 6 05-17-2006 09:13 PM
Use of XSL:variable in XML-Attribute schaf XML 3 09-16-2005 08:22 AM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
[XSL] : use array variable in XSL stylesheet MC XML 1 03-24-2005 10:41 AM



Advertisments