Because XSL is still XML we must start it as we would an XML file:
xml Code:
<?xml version=’1.0′
The next line is an XMLns (XML Name Space) declaration, this is so that we can get access to the XSLT elements, attributes and features through the namespace ‘xsl’, the url just represents an URL that contains the list of elements, attributes and features that we can now use.
Next to define what output form our XSL will take:
xml Code:
<xsl:output method=’html/>
template:
xml Code:
<xsl:template match=”/”>
This is where a bit of xPath knowledge comes in, the match attribute is used to associate a template with an XML element. The value of the match attribute is an XPath expression (i.e. match=”/” defines the whole document, because “/” in xPath is used to select the root node) so starting a template for the whole document.
now some html to start buiding up the template:
xml Code:
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1″ />
<title><xsl:value-of select=”$title”/></title>
normal html tags <head>/<meta>/<title> then im back into an xsl tag:
that one little tag grabs the data from it.
Parameters allow us to have values that we can access from anywhere within the XSL file, the way we access them is by using the value-of method, normally this is used to get values of XML element by using an xPath statement like ‘car/name’ but because we prefixed the name with ‘$’ it knows that it is a parameter and not an XML element we want.
So basically that produces the HTML code:
html Code:
<title>Car List Generated by PHP/XML/XSTL</title>
getting back into HTML again (tags aren’t prefixed with xsl, so the xsl parser will just ignore them and present them to the browser ‘as is’, a bit like the way php ignores any html outside of the <?php ?> tags.
THE NEXT HALF OF CODING TO START AN STYLE TAG WITH SOME CSS FEED IS TO COME NEXT.