Click to See Complete Forum and Search --> : XML hyperlinks basics


xml_newbie
07-08-2010, 08:43 AM
Hi all, very new to XML, i am unable to store and recall hyperlinks from XML, I have the following code;

XML;

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Table>
<Row>
<JobTitle>Doctor</JobTitle>
<Training>Fire</Training>
<Frequency>Every 12 months</Frequency>
<Link>http://www.bbc.co.uk</Link>
</Row>
<Row>
<JobTitle>Doctor</JobTitle>
<Training>Safe Prescribing</Training>
<Frequency>Every 12 months</Frequency>
<Link>http://www.bbc.co.uk</Link>
</Row>
</Table>

-------
XSL;

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<body>
<table border="2" bgcolor="yellow">
<tr>
<th>JobTitle</th>
<th>Training</th>
<th>Link</th>
</tr>
<xsl:for-each select="Table/Row[JobTitle='Doctor']">
<tr>
<td><xsl:value-of select="Training"/></td>
<td><xsl:value-of select="Frequency"/></td>
<td><xsl:value-of select="Link"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

-------

HTML;
<html>
<body>
<script language="javascript">
// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("jobs.xml")

// Load the XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("jobs.xsl")

// Transform
document.write(xml.transformNode(xsl))
</script>

</body>
</html>

------
The HTML just shows the links as text not active links.

Please could someone kindly explain where i am going wrong, all help very much appreciated:D

Charles
07-08-2010, 08:59 AM
Something more on the lines of<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<body>
<table border="2" bgcolor="yellow">
<tr>
<th>JobTitle</th>
<th>Training</th>
<th>Link</th>
</tr>
<xsl:for-each select="Table/Row[JobTitle='Doctor']">
<tr>
<td><xsl:value-of select="Training"/></td>
<td><xsl:value-of select="Frequency"/></td>
<td>
<a>
<xsl:attribute name="href">
<xsl:value-of select="Link"/>
</xsl:attribute>
<xsl:value-of select="Link"/>
</a>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>By the way, your HTML is off, your JavaScript lost in the last century and you should not be doing this with JavaScript it the first place.

xml_newbie
07-08-2010, 10:51 AM
Many thanks sorry for the coding mistakes; i have also tried to sort the data with the following piece of script, however it appears to not work, would anyone now why? thanks again

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<body>
<table border="2" bgcolor="yellow">
<tr>
<th>JobTitle</th>
<th>Training</th>
<th>Link</th>
</tr>
<xsl:for-each select="Table/Row[JobTitle='Doctor']">
<xsl:sort select="Training"/>

<tr>
<td><xsl:value-of select="Training"/></td>
<td><xsl:value-of select="Frequency"/></td>
<td>
<a>
<xsl:attribute name="href">
<xsl:value-of select="Link"/>
</xsl:attribute>
<xsl:value-of select="Link"/>
</a>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

xml_newbie
07-08-2010, 10:53 AM
Other than Javascript what would you recommend using?

Charles
07-08-2010, 11:06 AM
Just serve the XML as is and let the browser apply the stylesheet. Or do the transformation server side.

xml_newbie
07-08-2010, 11:10 AM
How would I serve the XML as is? please remember I am new to XML but would like to learn, many thanks

Charles
07-08-2010, 11:15 AM
Just link to the XML instead of the HTML. You'll need to keep the .xml at the end of the name, though.

xml_newbie
07-08-2010, 11:23 AM
so I can forget about the html file altogether? how do i link the stylesheet to the XML?

Charles
07-08-2010, 11:32 AM
In the XML prolog:<?xml version="1.0"?>
<?xml-stylesheet type='text/xsl' href='jobs.xsl'?>

xml_newbie
07-08-2010, 12:51 PM
Perfect, thank you very much for all your help, the very final issue is do you know why my sort function described earlier is not working? thanks again