Generating an HTML file from an XSL Style Sheet and an XML using Java.

For future reference..

I have this xml file called source.xml:
<?xml version="1.0" encoding="UTF-8"?>
        <title>Empire Burlesque</title>
        <artist>Bob Dylan</artist>
        <title>Hide your heart</title>
        <artist>Bonnie Tyler</artist>
        <company>CBS Records</company>

And this xsl file, style.xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
    <xsl:template match="/">
                <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>
                    <xsl:for-each select="catalog/cd">
                                <xsl:value-of select="title"/>
                                <xsl:value-of select="artist"/>

And of course the source code:
import javax.xml.transform.*;
public class TestClass {
    public static void main(String[] args) throws Exception {
        final StreamSource style = new StreamSource("style.xsl");
        final StreamSource data = new StreamSource("source.xml");
        final TransformerFactory transformerFactory = TransformerFactory.newInstance();
        final Transformer transformer = transformerFactory.newTransformer(style);
        final StreamResult outputTarget = new StreamResult(new FileOutputStream("result.html"));
        transformer.transform(data, outputTarget);

Now, put these 3 files in the same folder, and simply compile, execute, validate...
Korays-MacBook-Pro:~ koraytugay$ javac
Korays-MacBook-Pro:~ koraytugay$ java TestClass

And then open result.html in your browser and see the magic: