I’m trying to make a url in an XML file show up on an HTML page as a clickable hyperlink instead of just the url being displayed as text.
How can this be done? I’m pretty sure what I’ve done isn’t far off…
Here’s what the code looks like:
XML
<linkedin>
<discussion>
<topic>This is the discussion name</topic>
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce ligula mi, convallis eget iaculis id, euismod non arcu. Morbi porta.</content>
<url>http://www.google.com</url>
</discussion>
</linkedin>
XSL
<xsl:for-each select="linkedin/discussion">
<h3><xsl:value-of select="topic"/></h3>
<p><xsl:value-of select="content"/></p>
<p><a><xsl:attribute name="href"><xsl:value-of select="url"/></xsl:attribute><xsl:value-of select="url"/></a></p>
</xsl:for-each>
and I’m using JavaScript in the HTML to extract what’s in the XML file
<script type="text/javascript">
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","linkedin.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var x=xmlDoc.getElementsByTagName("discussion");
for (i=0;i<x.length;i++)
{
document.write("<p><strong>");
document.write(x[i].getElementsByTagName("topic")[0].childNodes[0].nodeValue);
document.write("</strong></p><p>");
document.write(x[i].getElementsByTagName("content")[0].childNodes[0].nodeValue);
document.write("</p><p>");
document.write(x[i].getElementsByTagName("url")[0].childNodes[0].nodeValue);
}
document.write("</p>");
</script>
Here’s how it’s looking… URL is just text and not a hyperlink:

Solved. Made the JavaScript in my HTML this: