29 May 2007
Converting a Windows playlist into a printable file
Windows Media Player saves playlists in an XML compliant format called WPL. This XSLT script will convert a WPL file into an HTML file that you can print (or copy and paste into a document):
Save the above file as 'wpl2html.xslt' and you can then use this DOS batch file to execute it:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- rename 'smil' element as 'html' (and ignore any attributes) -->
<xsl:template match="smil">
<xsl:element name="html">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<!-- include the playlist title as an h1 element in the body -->
<xsl:template match="body">
<xsl:element name="body">
<xsl:element name="h1"><xsl:value-of select="../head/title"/></xsl:element>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<!-- rename 'seq' element as 'ol' (numbered list) (and ignore any attributes) -->
<xsl:template match="seq">
<xsl:element name="ol">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<!-- rename 'media' element as 'li' (list item) -->
<xsl:template match="media">
<xsl:element name="li">
<xsl:value-of select="@src"/>
</xsl:element>
</xsl:template>
<!-- this template captures and ignores any elements we want to discard -->
<xsl:template match="author | meta | @tid">
<!-- ignore these elements -->
</xsl:template>
<!-- this is the 'identity' template, which copies any other content -->
<xsl:template match="@*|*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Save the above file as 'wpl2html.xslt' and you can then use this DOS batch file to execute it:
@ECHO OFF
REM Check there is a parameter
IF "%1" == "" GOTO MISSING_PARAMETERS
:START
SET file=%1
IF NOT EXIST %file%.wpl GOTO MISSING_FILE
:MAIN
ECHO Creating HTML...
java -jar ../resources/saxon8.jar %file%.wpl wpl2html.xslt >%file%.html
ECHO Done
GOTO END
:MISSING_PARAMETERS
ECHO Usage: "go myplaylist" to process "myplaylist.wpl" and create "myplaylist.html"
GOTO END
:MISSING_FILE
ECHO Error: '%file%.wpl' not found
GOTO END
:END
@ECHO ON
Subscribe to Posts [Atom]