Tuesday, December 30, 2008

Human Readable iTunes Playlist

Some quick xslt for converting an iTunes playlist exported as xml into plain text suitable for copy/paste to email or whatever:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text">

<xsl:strip-space elements="*">

<xsl:template match="*">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="dict/dict">
<xsl:apply-templates/>
<xsl:text>
</xsl:text>
</xsl:template>

<xsl:template match="key[text()='Year']">
<xsl:value-of select="following-sibling::integer">
<xsl:text> </xsl:text>
</xsl:template>

<xsl:template match="key[text()='Name']">
<xsl:value-of select="following-sibling::string">
<xsl:text> </xsl:text>
</xsl:template>

<xsl:template match="key[text()='Artist']">
<xsl:value-of select="following-sibling::string">
<xsl:text> </xsl:text>
</xsl:template>

<xsl:template match="text()|@*">
</xsl:template>

</xsl:stylesheet>


Then run as such:

xsltproc playlist.xslt NewYearsPlaylist.xml