How to display images when it is included in a text description

K

klingus

Hi,

I am in need of some xslt assistance. My xslt isn't rendering the
<img> tag when it is copied to the html page.

As you can see from the pasted code, the xml has in the <description>
tag embedded <img> but when I run the xslt, I get the full text but
the image isn't rendered.

Thank you for any assistance.
Kelvin

Below is the code for a test page:

HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>XML Transform : Firefox and IE</title>
<style>
body{
font:75%/150% "Trebuchet MS", "Lucida Grande", "Bitstream Vera
Sans", Arial, Helvetica, sans-serif;
color:#666666;
margin:100px;
}

td, th{
padding:5px;
}

th{
background:#993333;
color:#ffffff;
}
</style>

<script>
function runTransform(){
if(document.implementation &&
document.implementation.createDocument){
// Mozilla

var xsltProcessor = new XSLTProcessor();

// load the xslt file
var myXMLHTTPRequest = new XMLHttpRequest();
myXMLHTTPRequest.open("GET", "test.xsl", false);
myXMLHTTPRequest.send(null);

// get the XML document
xslStylesheet = myXMLHTTPRequest.responseXML;
xsltProcessor.importStylesheet(xslStylesheet);

// load the xml file
myXMLHTTPRequest = new XMLHttpRequest();
myXMLHTTPRequest.open("GET", "test.xml", false);
myXMLHTTPRequest.send(null);

var xmlSource = myXMLHTTPRequest.responseXML;

//transform
var resultDocument = xsltProcessor.transformToFragment(xmlSource,
document);
document.getElementById("example").appendChild(resultDocument);

}else if(window.ActiveXObject){
// IE

// Load XML
xml = new ActiveXObject("MSXML2.DOMDocument");
xml.async = false
xml.load("test.xml")

// Load XSL
xsl = new ActiveXObject("MSXML2.DOMDocument");
xsl.async = false
xsl.load("test.xsl")


// Transform

document.getElementById("example").innerHTML=xml.transformNode(xsl);
}else{
// Browser unknown
alert("Browser unknown");
}
}
</script>
</head>

<body onLoad="runTransform()">
<div id="example"></div>

</body>
</html>

XSLT:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:eek:utput method="html"/>
<xsl:template match="/">
<h2>U.S. News</h2>
<table border="0">
<tr>
<th align="left">Title</th>
<th align="left">Description</th>
</tr>
<xsl:for-each select="item">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:copy-of select="description"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>

XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<item>
<title>Bridge search ends for day with no luck (AP)</title>
<description><p><a href="http://us.rd.yahoo.com/dailynews/rss/
us/*http://news.yahoo.com/s/ap/20070805/ap_on_re_us/
bridge_collapse"><img src="http://d.yimg.com/us.yimg.com/p/ap/
20070804/
capt.b25df21cf4b0422e9074c64fac8e72e5.bush_bridge_collapse_wxs108.jpg?
x=130&amp;y=82&amp;sig=W0JdM0O4ep3mPDPq7pz2.w--" align="left"
height="82" width="130" alt="Divers continue the search for bodies
among the debris of the collapsed Interstate 35W bridge, just yards
away from where President Bush was meeting with public officials and
emergency crews in Minneapolis, Saturday, Aug. 4, 2007. The number of
dead stands at five, but authorities said another eight bodies likely
were trapped in the wreckage. (AP Photo/Joey McLeister, Pool)"
border="0" /></a>AP - Divers spent a third fruitless day searching
for victims of a deadly bridge collapse, finding no bodies inside a
crushed car pulled earlier Saturday from the murky Mississippi River
waters.</p><br clear="all"/></description>
</item>
 
J

Joe Kesselman

As you can see from the pasted code, the xml has in the <description>
tag embedded <img> but when I run the xslt, I get the full text but
the image isn't rendered.

The rendering is done on the HTML generated by the stylesheet. So the
questions are: (1) is the <img> getting to the output, and (2) since
you're working with XHTML, which is namespace-aware, is the <img> tag in
the XHTML namespace?

I haven't spent the time to analyse the code -- I don't do scripting, so
I could only comment on the XSLT itself in any case -- but I suspect the
latter is your problem.
 
R

roy axenov

I am in need of some xslt assistance. My xslt isn't
rendering the <img> tag when it is copied to the html
page.

That's because there's no <img/> element in your
As you can see from the pasted code, the xml has in the
<description> tag embedded <img>...

No, it doesn't.

No respect for 78 chars rule... chances of getting a useful
answer quartered.
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en"> <head>
<title>XML Transform : Firefox and IE</title>
<style>

Your XHTML is invalid. type attribute is mandatory (XHTML
1.0 2E, A.1.1).

See above.
<body onLoad="runTransform()">

There's no onLoad attribute in XHTML. See the spec if you
don't believe me (XHTML 1.0 2E, 4.2).
XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<item>
<title>Bridge search ends for day with no luck
(AP)</title> <description><p><a
href="http://us.rd.yahoo.com/dailynews/rss/
us/*http://news.yahoo.com/s/ap/20070805/ap_on_re_us/
bridge_collapse"><img
src="http://d.yimg.com/us.yimg.com/p/ap/ 20070804/
capt.b25df21cf4b0422e9074c64fac8e72e5.bush_bridge_collapse_wxs108.jpg?
x=130&amp;y=82&amp;sig=W0JdM0O4ep3mPDPq7pz2.w--"
align="left" height="82" width="130" alt="Divers continue
the search for bodies among the debris of the collapsed
Interstate 35W bridge, just yards away from where
President Bush was meeting with public officials and
emergency crews in Minneapolis, Saturday, Aug. 4, 2007.
The number of dead stands at five, but authorities said
another eight bodies likely were trapped in the wreckage.
(AP Photo/Joey McLeister, Pool)" border="0" /></a>AP -
Divers spent a third fruitless day searching for victims
of a deadly bridge collapse, finding no bodies inside a
crushed car pulled earlier Saturday from the murky
Mississippi River waters.</p><br
clear="all"/></description> </item>

You don't understand the difference between markup and text
that just happens to look like markup, do you? Strangely
enough, after fixing this (as well as all the other
problems introduced by posting without respect for usenet
posting guidelines and serving the resulting document as
text/html instead of application/xhtml+xml) your script
worked just fine in both Firefox 2 and MSIE 6. Of course,
it just silently fails if JS is disabled, but I don't
suppose that bothers you much.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top