PDA

View Full Version : XML and XSL into HTML??


rr299
06-20-2007, 01:56 PM
Hi I am fairly new to XML when using it with HTML and can't figure this out. It's probably very basic but I can't find the answer anywhere (usually means i am searching for the wrong thing!)

Basically I have an XML document with some information in it which I want to put into a table. I have followed an XSLT tutorial and have created an XSL document which does just this. When I load my XML document in a browser it loads the table as required (ie C:/mystuff/table.xml). My problem is that I want to put this table into a HTML page with some other information on and I can't work out how to do this. So basically I want to load a .html file rather than a .xml file.

Any pointers would be great.
Thanks

Alex Vincent
06-20-2007, 08:21 PM
How about a pointer to the source code you're working with?

rr299
06-20-2007, 08:26 PM
Sure here is the basic xml file...


<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="stock.xsl"?>
<stock>
<car>
<summary>A fantastic convertible in top condition.</summary>
<model>02 Reg MERCEDES-BENZ SL CLASS SL 500 2dr Tip Auto (TV+SAT NAV)</model>
<price>£35,995</price>
<thumbMain>stock/sl500/thumbMain.jpg</thumbMain>
</car>


The car part is repeated. Then my xsl file is like this....


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Current Stock</h2>
<table border="1">
<tr bgcolor="#9acd32">

<th>Model</th>
<th>Price</th>
<th>Image</th>
</tr>
<xsl:for-each select="stock/car">
<tr>
<td><xsl:value-of select="model"/></td>
<td><xsl:value-of select="price"/></td>
<td>
<img>
<xsl:attribute name="src">
<xsl:value-of select="thumbMain" />
</xsl:attribute>
</img>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>