I have a bunch of files (Playlist files for media player) and I am
trying to create an automatically generated web page that includes the
last 20 or 30 of these files. The files are created every week and are
named XX-XX-XX.ASX where the X's represent the date i.e. 05-22-05.asx
The files are a specific format and will always contain tags like the
following:
<TITLE>My media file title</TITLE>
<AUTHOR>Media file author</AUTHOR>
<Ref href = "mms://media.mydomainname.com/2005/05-01-05.wma" />
I would like to parse these files for the info in the tags, Title,
Author, and Date and then add them to a table on a web page, but I
have had no luck creating the parsing on my own. Can anyone give me a
good start in the right direction using vbscript to get this going.
I especially have trouble pulling the date out since it is at the end
of a tag.. Though I suppose the filename could be used if that could
be converted into a properly formatted date i.e. May 1, 2005
Help?
Here's a proof of concept using the MSXML Parser
[ShowASX.asp]
<%
CONST PATH = "<<ASX DIRECTORY>>"
Dim xslt, xsl, proc, xml, fso, fld, fc, f
Set xsl = CreateObject("MSXML2.FreeThreadedDOMDocument.4.0")
xsl.Load Server.MapPath("asx2html.xsl")
Set xslt = CreateObject("MSXML2.XSLTemplate.4.0")
Set xslt.stylesheet = xsl
Set proc = xslt.createProcessor()
Set xml = CreateObject("MSXML2.DOMDocument.4.0")
Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(PATH)
Set fc = fld.Files
Response.Write "<table border='1'>"
For Each f In fc
If Right(f.Name,4) = ".asx" Then
xml.Load Server.MapPath(f.Name)
proc.input = xml
proc.Transform
Response.Write proc.output
End If
Next
Response.Write "</table>"
Set f = Nothing
Set fc = Nothing
Set fld = Nothing
Set xml = Nothing
Set proc = Nothing
Set xslt = Nothing
Set xsl = Nothing
%>
[asx2html.xsl]
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="
http://www.w3.org/1999/XSL/Transform">
<xsl
utput method="html" version="4.0" indent="yes"/>
<xsl:template match="Asx">
<xsl:apply-templates select="Entry"/>
</xsl:template>
<xsl:template match="Entry">
<tr>
<td><xsl:value-of select="Title"/></td>
<td><xsl:value-of select="Author"/></td>
<td>
<xsl:call-template name="String2Date">
<xsl:with-param name="s"
select="substring(Ref/@href,string-length(Ref/@href)-11,8)"/>
</xsl:call-template>
</td>
</tr>
</xsl:template>
<xsl:template name="String2Date">
<xsl
aram name="s"/>
<xsl:variable name="m" select="substring($s,1,2)"/>
<xsl:variable name="d" select="substring($s,4,2)"/>
<xsl:variable name="y" select="substring($s,7,2)"/>
<xsl:choose>
<xsl:when test="$m='01'">January</xsl:when>
<xsl:when test="$m='02'">February</xsl:when>
<xsl:when test="$m='03'">March</xsl:when>
<xsl:when test="$m='04'">April</xsl:when>
<xsl:when test="$m='05'">May</xsl:when>
<xsl:when test="$m='06'">June</xsl:when>
<xsl:when test="$m='07'">July</xsl:when>
<xsl:when test="$m='08'">August</xsl:when>
<xsl:when test="$m='09'">September</xsl:when>
<xsl:when test="$m='10'">October</xsl:when>
<xsl:when test="$m='11'">November</xsl:when>
<xsl:when test="$m='12'">December</xsl:when>
</xsl:choose>
<xsl:value-of select="concat(' ',$d,', ')"/>
<xsl:choose>
<xsl:when test="$m < '30'"><xsl:value-of
select="concat('20',$y)"/></xsl:when>
<xsl
therwise><xsl:value-of
select="concat('19',$y)"/></xsl
therwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Notes:
1. Make sure ShowASX.asp and asx2html.xsl are in the same directory.
2. In ShowASX.asp, you'll need to replace the MSXML version references
to whichever version of MSXML you're using, most likely 3.0. So, for
example, "MSXML2.DOMDocument.4.0" becomes "MSXML2.DOMDocument.3.0"
3. I used a cached template in this scenario since multiple xml files
were being processed by the same xsl stylesheet. This also has the
advantage of using a free-threaded xsl document object. As such, the
xsl document can be safely stored in the application scope which
should yield some performance benefits if the transformed playlists
are to be accessed by multiple users.
4. Please consider using ISO standard date formats (YYYY-MM-DD).
HTH
-Chris Hohmann
Wow... thats deep, and I almost get what you are doing.. almost...
When I run the page the resulting page source code is only
<table border='1'></table>
nothing else.
I have looked for what could be the problem and can't locate it. No
errors are reported on screen.
any idea?
Did you set the PATH constant correctly at the top of the ShowASX.asp
page?