XSL to transform iTunes play lists to html

It outputs tables, but it *is* tabular data :)

if I was stronger with xsl, it would be a bit cleaner, and allow you to supply the colors easily, but you get what you pay for.
To use it, File > Export Song List > Save as XML.
Then navigate to it on the form, and hit “upload”

Here is the form if you want to play with it (please be kind):
iTunes Playlist Transformer
Source Code

Here is just the XSL:

<?xml version="1.0" ?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
  
  <xsl:output method="html" />
  <xsl:template match="/">
        <table style='border-collpase:collapse; ' border='1'>
            <tr style='background-color:#ddd;'>
                <th colspan='4'>Playlist Name: <xsl:value-of select="plist/dict/key[text()='Playlists']/following-sibling::array/dict/string" /></th>
            </tr>
            <tr style='background-color:#ddd;'>
                <th>Artist</th>
                <th>Track Name</th>
                <th>Album</th>
                <th>Played</th>
            </tr>
        <xsl:for-each select="plist/dict/key[text()='Playlists']/following-sibling::array/dict/array/dict">
            <xsl:call-template name="track">
                <xsl:with-param name="trackid" select='integer' />
            </xsl:call-template>
        </xsl:for-each>
        </table>
    </xsl:template>
    <xsl:template name="track">
        <xsl:param name="trackid" />
        <xsl:variable name="thistrack" select="/plist/dict/key[text()='Tracks']/following-sibling::dict/key/following-sibling::dict/integer[text()=\$trackid]" />
        <tr>
            <xsl:choose>
                <xsl:when test="position() mod 2 = 1">
                    <xsl:attribute name="style">background-color: #bbb</xsl:attribute>
                </xsl:when>
                <xsl:otherwise> 
                    <xsl:attribute name="style">background-color: #999</xsl:attribute>
                </xsl:otherwise>
            </xsl:choose>
            
            <td><xsl:value-of select="\$thistrack/following-sibling::key[text()='Artist']/following-sibling::string" /></td>
            <td><xsl:value-of select="\$thistrack/following-sibling::key[text()='Name']/following-sibling::string" /></td>
            <td><xsl:value-of select="\$thistrack/following-sibling::key[text()='Album']/following-sibling::string" /></td>
            <td><xsl:value-of select="\$thistrack/following-sibling::key[text()='Play Count']/following-sibling::integer" /></td>
        </tr>
    </xsl:template>

</xsl:stylesheet>

One thought on “XSL to transform iTunes play lists to html”

Comments are closed.