473,507 Members | 12,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using html in variables

So, I'm having a bit of a time trying to insert an <imgtag into an
<atag using an xsl variable. Consider the following template. The
contents of the foo variable doesn't show up in the anchor. When I use
named entities instead of < and >, it gets inserted just fine although
then it's not interpreted by the browser but, rather, simply included
as is in the page content.

<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:output method="html" version="4.0" />
<xsl:template match="foo">
<xsl:variable name="bar">
<xsl:if test="$some-boolean-variable">
<img src="http://some-image.gif" border="0" width="7" height="7"/>
</xsl:if>
</xsl:variable>
<a href="some-url.html" title="{title}"><xsl:value-of select="title"/
><xsl:value-of select="$bar"/></a>
</xsl:template>
</xsl:stylesheet>

Any help on this would be greatly appreciated!

David
Aug 5 '08 #1
4 1536
David Schwartz wrote:
><xsl:value-of select="$bar"/></a>
If your variable contains a result tree fragment then you need to use
xsl:copy-of instead of xsl:value-of e.g.
<xsl:copy-of select="$bar"/>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 5 '08 #2
If your variable contains a result tree fragment then you need to use
xsl:copy-of instead of xsl:value-of e.g.
<xsl:copy-of select="$bar"/>
That was it! Can you explain what the issue was a bit more fully?

Thanks so much,
David
Aug 5 '08 #3
Tue, 5 Aug 2008 11:03:41 -0700 (PDT), /David Schwartz/:
Tue, 05 Aug 2008 18:29:16 +0200, /Martin Honnen/:
>If your variable contains a result tree fragment then you need to use
xsl:copy-of instead of xsl:value-of e.g.
<xsl:copy-of select="$bar"/>

That was it! Can you explain what the issue was a bit more fully?
<http://www.w3.org/TR/xslt#value-of>:
The xsl:value-of element is instantiated to create a text node in
the result tree. The required select attribute is an expression;
this expression is evaluated and the resulting object is converted
to a string as if by a call to the string function. [...]

The xsl:copy-of element can be used to copy a node-set over to the
result tree without converting it to a string. See [11.3 Using
Values of Variables and Parameters with xsl:copy-of].
You could read about the 'string' function
<http://www.w3.org/TR/xpath#function-stringand what is the
string-value of root (and element) nodes
<http://www.w3.org/TR/xpath#dt-string-value(a bit down below).
Such node is the one in your variable result-tree-fragment value
<http://www.w3.org/TR/xslt#dt-result-tree-fragment>.

--
Stanimir
Aug 6 '08 #4
David Schwartz wrote:
>If your variable contains a result tree fragment then you need to use
xsl:copy-of instead of xsl:value-of e.g.
<xsl:copy-of select="$bar"/>

That was it! Can you explain what the issue was a bit more fully?
Well xsl:value-of takes the string value and inserts a text node in the
result tree. xsl:copy-of however copies the nodes into the result tree.

Your variable contains nodes and you want to copy them to the
transformation result hence you need to use xsl:copy-of.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 6 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5643
by: Gary | last post by:
I haver a table of students - Say 100 students that I need to be able to update/delete and amend. I know I can do this one student at a time which is simple but lets say I want to see all the...
28
20272
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
9
6880
by: Charley Kyd | last post by:
I'm a newbie who needs advice about how to use external files of JavaScript code. I spent an hour this afternoon browsing through JavaScript books at the local book store. In about 15 different...
15
3192
by: lawrence | last post by:
Sorry for the dumb question but I'm new to Javascript. I wrote this script hoping to animate some div blocks on a page. You can see the page here: http://www.keymedia.biz/demo.htm Can anyone...
17
2432
by: Davíð Þórisson | last post by:
now in my web I have some global variables to be used in many different subpages, in the old ASP I simply loaded a variables.asp file into memory using the eval() function. Now I'd like to use XML...
10
3136
by: Coleen | last post by:
Hi all :-) I have a weird formatting problem with an HTML table that I am populating using VB.Net and HTML. Here is the snippet of code for the cell I'm trying to format: Dim...
2
3034
by: Jake Barnes | last post by:
Using javascript closures to create singletons to ensure the survival of a reference to an HTML block when removeChild() may remove the last reference to the block and thus destory the block is...
13
2077
by: Andy Baxter | last post by:
Can anyone recommend a good online guide to using objects in javascript? The book I bought (DHTML Utopia) suggests using objects to keep the code clean and stop namespace clashes between different...
3
1877
by: vunet.us | last post by:
Hello, I am breaking my head running out of ideas about the best solution to my goal. I want to load some pages generated with the server (ASP) and assign their html results to JavaScript, so...
6
5121
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
0
7109
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...
0
7313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7481
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5039
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1537
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.