472,374 Members | 1,089 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 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 31139
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.