Warning: mysql_connect(): Access denied for user 'mysql_feedback'@'localhost' (using password: YES) in /usr/local/psa/home/vhosts/coin-c.com/httpdocs/CCTunes/inc_rate.php on line 18
I cannot connect to the database because: Access denied for user 'mysql_feedback'@'localhost' (using password: YES)

8. Making HTML

One little stage is still left, and that is formatting the XML files so that they make nice HTML files that we can render in a browser. A full explanation of all things you can do in XSL is out of the scope of this document, but this very basic style sheet should provide a good starting point for anyone willing to get his or her hands dirty.

Code listing 8.1: This very basic XSL style sheet creates a list of all albums in the libary

<xsl:stylesheet
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xsl:version="1.0">
            
  <xsl:key name="album-sort-keys" match="AlbumItem" use="SortKey" />
  <xsl:template match="xmlLibrary">
    <html>
      <head>
        <title>Music Library - Exported from iTunes</title>
      </head>
      <body>
        <xsl:for-each select="AlbumItem">
          <xsl:sort select="SortKey"/>
          <xsl:value-of select="Album" /> - <xsl:value-of select="Artist" /><br/>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

This style sheet basically consists of only a couple of processing instructions that are specific to XSL. Anyone that has ever seen some HTML should be able to recognize the HTML structure within this style sheet: the <html> section, the <head> and the <body> are there.

In the body there is just one big loop, indicated by the xsl:for-each tag. The first instruction indicates how to get the albums sorted - there is a key ready for your usage in the XML that is generated by the script, and using the <xsl:value-of> directive, it selects artist and album, prints a dash in between them and a newline (<br>) after it.

How easy can it be? You can start from this to lay out the HTML like you want it and use the other XSL files in the package for further inspiration to do the trickier things. Good luck!

line
Updated $LastChangedDate: 2005-01-07 20:53:38 +0100 (Fri, 07 Jan 2005) $
line
Kristof Van Landschoot
Author

line
Summary: When we've got nice XML, how do we make it into HTML?
line
Single-page Version
Copyright 2003-2004 Coin-C bvba. Questions, Comments, Corrections? Email cctunes@coin-c.com.