473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 31323
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jorn W Janneck | last post by:
hello everyone. i have the sort of question that makes me feel like i am missing the forest for the trees, so apologies if i am missing the blatantly obvious here. i am using saxon, and mostly...
0
by: Andrew Lord | last post by:
XML-Schema: Attribute Value dependent rules? As far as I can tell XML-Schema does not permit the sepcification of rules that only apply if an attribute has a certain value. For example, in the...
4
by: elora_c | last post by:
I'm trying to write XSLT that will filter out an XML based on an attribute's value. XML looks like: <postings> <channel name="A"> <posting Connected="True" name="Posting1" /> <posting...
5
by: Mateusz Loskot | last post by:
Hi, I'd like to ask how XML parsers should handle attributes which consists of &quot; entity as value. I know XML allows to use both: single and double quotes as attribute value terminator. That's...
0
by: Kathy Burke | last post by:
Hi, sorry I've asked similar questions, but still having trouble. I'm using asp.net (vb.net). I select a node from an xmlDoc string (I've made sure that the intended item exists), then want to...
2
by: Greg | last post by:
Hi. I have a rather large xml document (object) that can have one or more nodes with a certain attribute throughout (at ANY depth, not at the same level necessarily). I need to find this...
6
by: Newbie | last post by:
hi all, in a webform's codebehind, i have a variable (ie: nTotal). and in UI i have a hidden htmlinput (ie: fld1). Q: how to assign the value of nTotal to now i want to assign the value of...
10
by: Jon Noring | last post by:
Out of curiosity, may a CDATA section appear within an attribute value with datatype CDATA? And if so, how about other attribute value datatypes which accept the XML markup characters? To me,...
0
by: kelvin273 | last post by:
Hi all, i'm new in this community (and in .NET programming) and i've a problem with xpathnavigator. The idea is to have an xml document with attribute editable by windows form. I write this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.