I am trying to follow the basic example on the W3Schools for xslt.
xml.xml:
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
</catalog>
xslt.xslt:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Title</th>
<th style="text-align:left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Whenever i try to do this locally outside of the W3Schools it doesn't work, getting the following error.
This XML file does not appear to have any style information associated with it. The document tree is shown below.
Looking around stack overflow I can't seem to find an answer to my specific query as this is something that should be quite simple.
My question is: how does the xslt file know that i want it to use xml.xml as the xml to match on?
logically you would have thought you would have to include it in the xslt file. When i've looked around i've seen people do the following:
xml.xml:
<?xml version="1.0"?>
<?xml-stylesheet href="xsl.xsl" type="text/xsl" ?>
xsl.xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="1.0">
But that doesn't work for me locally, any suggestions?