Parsing text into web page table entries?

M

.:mmac:.

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?
 
M

Mark Schupp

Your input files appear to be in XML format. If that is the case then use
the MSXML parser. Unfortunately I don't have any sample code handy. But if
your input is XML let us know and I am sure that someone will be able to get
you started.
 
C

Chris Hohmann

.:mmac:. said:
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:eek: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:param 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 &lt; '30'"><xsl:value-of
select="concat('20',$y)"/></xsl:when>
<xsl:eek:therwise><xsl:value-of select="concat('19',$y)"/></xsl:eek: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
 
M

.:mmac:.

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?


Chris Hohmann said:
.:mmac:. said:
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:eek: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:param 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 &lt; '30'"><xsl:value-of
select="concat('20',$y)"/></xsl:when>
<xsl:eek:therwise><xsl:value-of select="concat('19',$y)"/></xsl:eek: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
 
C

Chris Hohmann

.:mmac:. said:
Chris Hohmann said:
.:mmac:. said:
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:eek: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:param 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 &lt; '30'"><xsl:value-of
select="concat('20',$y)"/></xsl:when>
<xsl:eek:therwise><xsl:value-of select="concat('19',$y)"/></xsl:eek: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?
 
M

.:mmac:.

yes, I believe so, I used "E:\www\audio\myasxfiles"
the showasx and XML2html files are in the "audio" directory, I assume it's
OK to have it one level up as long as the path is right?
I "sniffed" the parser version from a utility on a web page and it found
v3.0 and I changed all the references to 3.0


Chris Hohmann said:
.:mmac:. said:
Chris Hohmann said:
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:eek: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:param 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 &lt; '30'"><xsl:value-of
select="concat('20',$y)"/></xsl:when>
<xsl:eek:therwise><xsl:value-of select="concat('19',$y)"/></xsl:eek: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?
 
C

Chris Hohmann

.:mmac:. said:
Chris Hohmann said:
.:mmac:. said:
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:eek: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:param 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 &lt; '30'"><xsl:value-of
select="concat('20',$y)"/></xsl:when>
<xsl:eek:therwise><xsl:value-of
select="concat('19',$y)"/></xsl:eek: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?

yes, I believe so, I used "E:\www\audio\myasxfiles"
the showasx and XML2html files are in the "audio" directory, I assume it's
OK to have it one level up as long as the path is right?
I "sniffed" the parser version from a utility on a web page and it found
v3.0 and I changed all the references to 3.0
You renamed the xsl stylesheet to XML2html? If so, you'll need to adjust
ShowASX.asp accordingly. It references a file called asx2html.xsl. Also
please post your responses below the quoted text. Top-posting makes it very
difficult to follow the flow of the conversation.
 
M

.:mmac:.

Chris Hohmann said:
.:mmac:. said:
Chris Hohmann said:
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:eek: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:param 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 &lt; '30'"><xsl:value-of
select="concat('20',$y)"/></xsl:when>
<xsl:eek:therwise><xsl:value-of
select="concat('19',$y)"/></xsl:eek: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?

yes, I believe so, I used "E:\www\audio\myasxfiles"
the showasx and XML2html files are in the "audio" directory, I assume
it's OK to have it one level up as long as the path is right?
I "sniffed" the parser version from a utility on a web page and it found
v3.0 and I changed all the references to 3.0
You renamed the xsl stylesheet to XML2html? If so, you'll need to adjust
ShowASX.asp accordingly. It references a file called asx2html.xsl. Also
please post your responses below the quoted text. Top-posting makes it
very difficult to follow the flow of the conversation.
Sorry
no I didn't rename the stylesheet, I just called it the wrong name in my
hurried reply. I used the name you gave it.
 
M

.:mmac:.

Chris Hohmann said:
[snip]

Ugh! The extention on your playlist files is ".ASX", not ".asx" right?
Because your original post is ambigous on that point. Replace the
following line in ShowASX.asp:

If Right(f.Name,4) = ".asx" Then

With this line:

If UCase(Right(f.Name,4)) = ".ASX" Then

no, they are all lowercase, but the change makes sense anyway.
I didn't know this would be case sensitive but I should 'cause I ran into
that before.
Bearing that in mind, is this line" <xsl:template match="Asx">" in the style
sheet OK as far as case goes?
 
C

Chris Hohmann

[snip]

Ugh! The extention on your playlist files is ".ASX", not ".asx" right?
Because your original post is ambigous on that point. Replace the following
line in ShowASX.asp:

If Right(f.Name,4) = ".asx" Then

With this line:

If UCase(Right(f.Name,4)) = ".ASX" Then
 
M

.:mmac:.

Chris Hohmann said:
[snip]

Ugh! The extention on your playlist files is ".ASX", not ".asx" right?
Because your original post is ambigous on that point. Replace the
following line in ShowASX.asp:

If Right(f.Name,4) = ".asx" Then

With this line:

If UCase(Right(f.Name,4)) = ".ASX" Then

IF I add a line in your script:

Response.Write "<table border='1'>"
For Each f In fc
If UCase(Right(f.Name,4)) = ".ASX" Then
xml.Load Server.MapPath(f.Name)
proc.input = xml
proc.Transform
Response.Write proc.output
response.Write f + "<br>" <---------------added this line
End If
Next
Response.Write "</table>"

I get a list of the files with path like this
E:\Www\myfiles\AUDIO\2005\01-02-05.asx
E:\Www\myfiles\AUDIO\2005\01-09-05.asx
E:\Www\myfiles\AUDIO\2005\01-16-05.asx
E:\Www\myfiles\AUDIO\2005\01-23-05.asx
E:\Www\myfiles\AUDIO\2005\01-30-05.asx
E:\Www\myfiles\AUDIO\2005\02-06-05.asx

so part of it is working....
 
C

Chris Hohmann

.:mmac:. said:
Chris Hohmann said:
Chris Hohmann said:
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
[snip]

Ugh! The extention on your playlist files is ".ASX", not ".asx" right?
Because your original post is ambigous on that point. Replace the
following line in ShowASX.asp:

If Right(f.Name,4) = ".asx" Then

With this line:

If UCase(Right(f.Name,4)) = ".ASX" Then

IF I add a line in your script:

Response.Write "<table border='1'>"
For Each f In fc
If UCase(Right(f.Name,4)) = ".ASX" Then
xml.Load Server.MapPath(f.Name)
proc.input = xml
proc.Transform
Response.Write proc.output
response.Write f + "<br>" <---------------added this line
End If
Next
Response.Write "</table>"

I get a list of the files with path like this
E:\Www\myfiles\AUDIO\2005\01-02-05.asx
E:\Www\myfiles\AUDIO\2005\01-09-05.asx
E:\Www\myfiles\AUDIO\2005\01-16-05.asx
E:\Www\myfiles\AUDIO\2005\01-23-05.asx
E:\Www\myfiles\AUDIO\2005\01-30-05.asx
E:\Www\myfiles\AUDIO\2005\02-06-05.asx

so part of it is working....
Can you post one of the asx files so I can confirm the format?
 
M

.:mmac:.

Chris Hohmann said:
Can you post one of the asx files so I can confirm the format?

here you are...

<ASX version = "3.0">
<TITLE>Valley </TITLE>
<MOREINFO HREF="http://www.mywebsite.com" />
<Logo href = "http://www.mywebsite.com/audio/images/valleylogosm.gif" Style
= "ICON" />
<Logo href = "http://www.mywebsite.com/audio/images/valleylogolg.gif" Style
= "mark" />
<Entry ClientSkip="yes">
<BANNER HREF = "http://www.mywebsite.com/audio/images/valleybanner.gif">
<Abstract>Visit my website</abstract>
<MoreInfo href = "http://www.mywebsite.com" />
</BANNER>
<Logo href = "http://www mywebsite.com/audio/images/valleylogosm.gif" Style
= "ICON" />
<MoreInfo href = "http://www.mywebsite.com" />
<Abstract>Visit mywebsite</abstract>

<!-- All above this line remains the same for each
file - - - - - - - - - - - - - - - - - - - - - - - - -->
<TITLE>The title of the audio file</TITLE>
<AUTHOR>Files author</AUTHOR>
<COPYRIGHT>(c)2005 my web site</COPYRIGHT>
<Ref href = "mms://media.mywebsite.com/2005/05-01-05.wma" />
</Entry>
</ASX>
 
C

Chris Hohmann

.:mmac:. said:
here you are...

<ASX version = "3.0">
<TITLE>Valley </TITLE>
<MOREINFO HREF="http://www.mywebsite.com" />
<Logo href = "http://www.mywebsite.com/audio/images/valleylogosm.gif"
Style = "ICON" />
<Logo href = "http://www.mywebsite.com/audio/images/valleylogolg.gif"
Style = "mark" />
<Entry ClientSkip="yes">
<BANNER HREF = "http://www.mywebsite.com/audio/images/valleybanner.gif">
<Abstract>Visit my website</abstract>
<MoreInfo href = "http://www.mywebsite.com" />
</BANNER>
<Logo href = "http://www mywebsite.com/audio/images/valleylogosm.gif"
Style = "ICON" />
<MoreInfo href = "http://www.mywebsite.com" />
<Abstract>Visit mywebsite</abstract>

<!-- All above this line remains the same for each
file - - - - - - - - - - - - - - - - - - - - - - - - -->
<TITLE>The title of the audio file</TITLE>
<AUTHOR>Files author</AUTHOR>
<COPYRIGHT>(c)2005 my web site</COPYRIGHT>
<Ref href = "mms://media.mywebsite.com/2005/05-01-05.wma" />
</Entry>
</ASX>
In answer to your earlier question, XML is case sensitive. As such, you will
need to modify asx2html.xsl accordingly. Can I ask how these playlist files
are being generated? For my own testing, I did the following:

1. Opened Windows Media Player 10.
2. Selected File->New Now Playing List.
3. Dragged files from the media library to the now playing list.
4. Selected File->Save Now Playing List As...
5. Specified Save as Type->Any Playlist(*.wpl,*.asx,*.m3u)
6. Specified File name->05-22-05.asx
7. Saved playlist.

I based the asx2html.xsl file on the resulting playlist file which contained
mixed case entity names. Note, that this contradicts the online
documentation which lists all entities in uppercase and also states
"Elements and attributes are not case sensitive. The text used in the
playlist to define an element or attribute can be either uppercase or
lowercase, or a mixture of both." Here's a link to the documentation:

http://msdn.microsoft.com/library/en-us/wmplay10/mmp_sdk/creatingmetafileplaylists.asp

What they're actually saying is that Windows Media Player is case
insensitive when it comes to ASX files. XML on the other hand is case
sensitive. But as long as the files are being generated in a consistent
manner, then all you need to do is make the appropriate replacements in the
asx.html.xsl file and all should be well.
 
C

Chris Hohmann

Chris Hohmann said:
In answer to your earlier question, XML is case sensitive. As such, you
will need to modify asx2html.xsl accordingly.

Here's a modified version of asx2html.xsl based on the playlist file sample
you posted:

[asx2html.xsl]
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek: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:param 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 &lt; '30'"><xsl:value-of
select="concat('20',$y)"/></xsl:when>
<xsl:eek:therwise><xsl:value-of select="concat('19',$y)"/></xsl:eek:therwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
 
M

.:mmac:.

Chris Hohmann said:
In answer to your earlier question, XML is case sensitive. As such, you
will need to modify asx2html.xsl accordingly. Can I ask how these playlist
files are being generated? For my own testing, I did the following:

1. Opened Windows Media Player 10.
2. Selected File->New Now Playing List.
3. Dragged files from the media library to the now playing list.
4. Selected File->Save Now Playing List As...
5. Specified Save as Type->Any Playlist(*.wpl,*.asx,*.m3u)
6. Specified File name->05-22-05.asx
7. Saved playlist.

I based the asx2html.xsl file on the resulting playlist file which
contained mixed case entity names. Note, that this contradicts the online
documentation which lists all entities in uppercase and also states
"Elements and attributes are not case sensitive. The text used in the
playlist to define an element or attribute can be either uppercase or
lowercase, or a mixture of both." Here's a link to the documentation:

http://msdn.microsoft.com/library/en-us/wmplay10/mmp_sdk/creatingmetafileplaylists.asp

What they're actually saying is that Windows Media Player is case
insensitive when it comes to ASX files. XML on the other hand is case
sensitive. But as long as the files are being generated in a consistent
manner, then all you need to do is make the appropriate replacements in
the asx.html.xsl file and all should be well.
I hand type each one changing the data below the "all above this line..."
each week.
I don't understand what replacements I need to make to that file.
If I am using all lowercase then this should work? then what am I doing
wrong??
I renamed one of the extensions to uppercase and no change.
How should the web page display in your view?
 
M

.:mmac:.

In answer to your earlier question, XML is case sensitive. As such, you
will need to modify asx2html.xsl accordingly.

Here's a modified version of asx2html.xsl based on the playlist file
sample you posted:

[asx2html.xsl]
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek: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:param 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 &lt; '30'"><xsl:value-of
select="concat('20',$y)"/></xsl:when>
<xsl:eek:therwise><xsl:value-of select="concat('19',$y)"/></xsl:eek:therwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

Chris, I see what you mean by case sensitive, You mean the tags as well as
the filename. Got it.
But the page still doesn't work on my end. It doesn't look like anything is
being processed. I get the list of files by adding that response.write line
but nothing formatted by the stylesheet.
What should it look like? I have an idea but what does it look like when you
run it?
How can I step through it to look for where it breaks?
 
C

Chris Hohmann

.:mmac:. said:
I hand type each one changing the data below the "all above this line..."
each week.
I don't understand what replacements I need to make to that file.
If I am using all lowercase then this should work? then what am I doing
wrong??
I renamed one of the extensions to uppercase and no change.
How should the web page display in your view?
The <Abstract> tags in your asx files are not properly closed. You start the
tag is mixed case and the end tag is lowercase. After I made that change,
your sample asx file processed correctly with the modified version of
asx2html.xsl I sent.
 
M

.:mmac:.

Chris Hohmann said:
The <Abstract> tags in your asx files are not properly closed. You start
the tag is mixed case and the end tag is lowercase. After I made that
change, your sample asx file processed correctly with the modified version
of asx2html.xsl I sent.

Yeeeea! I got some success! I found I have LOTS of case changes to make!
This is REALLY great! Thanks a ton! If I'm not being too greedy I have a
couple more q's.

1. I found that I have to have these two files in the same directory as the
ASX files or the stylesheet doesn't see them. The ASP script does as
evidenced by the listing of files with the ".write f" that I added,
Shouldn't the PATH const allow me to place the two files anywhere?

2. I would like to have a small gif at one end or the other linked to the
asx file for clicking to play the asx file. How can I do that?

3. In the ASX file I supplied, there are Two "TITLE" tags, how does this
know which one to read? Does it not look until finding the first ENTRY tag?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top