Parsing text into web page table entries?

D

Dave Anderson

..:mmac:. said:
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.

I realize this is late in the discussion, but have you considered just using
publishing points in Media Services?



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
C

Chris Hohmann

.:mmac:. said:
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?

As long as the ShowASX.asp and the asx2html.xsl files are in the same
directory, they should work regardless of where the actual asx files are
located.
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?

You will need to modify the asx2html.xsl file. It shouldn't be too hard. You
would add something like the following:

<td>
<a>
<xsl:attribute name="href">
<xsl:value-of select="Ref/@href"/>
</xsl:attribute>
<img src="icon.gif"/>
</a>
</td>

I'll leave it to you to do the copy and paste.
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?

Yes, the reference to the TITLE tag occurs within a template that processes
the ENTRY tag. As such it does not apply to the TITLE tag that is a direct
descendant of the ASX tag.
 
M

.:mmac:.

ummm ... no... I was having so much fun with the XML I didn't think beyond
that. How does that work?
 
M

.:mmac:.

1. I found that I have to have these two files in the same directory as
As long as the ShowASX.asp and the asx2html.xsl files are in the same
directory, they should work regardless of where the actual asx files are
located.

Thanks Chris, this has been very enlightening!

As for the file location, I tried it in two folders and it only displayed
when I placed it in the same dir as the asx files. I guess then there is a
path issue? I'll fiddle with that.

Would sorting the display by date be a major undertaking? I would like to
show them in top down decending date order.
I believe that it would be a bigger deal than I am capable of but I thought
I would ask.
 
C

Chris Hohmann

.:mmac:. said:
Thanks Chris, this has been very enlightening!

As for the file location, I tried it in two folders and it only displayed
when I placed it in the same dir as the asx files. I guess then there is a
path issue? I'll fiddle with that.

Whoops, my mistake. Replace the following line in ShowASX.asp:

xml.Load Server.MapPath(f.Name)

With this line:

xml.Load PATH & f.Name

Also, make sure there's a trailing backslash in the PATH constant.

Would sorting the display by date be a major undertaking? I would like to
show them in top down descending date order.
I believe that it would be a bigger deal than I am capable of but I
thought I would ask.

Two things would be involved. First, you would need to combine all the
playlist data into one file, either programmatically or manually. Then you
could use the <xsl:sort> tag in XSL to sort the ENTRY tags by date
associated with Ref/@href.

Here's a section of the wcschools.com tutorial on XSL that deals with
sorting:
http://www.w3schools.com/xsl/xsl_sort.asp
 
M

.:mmac:.

Chris Hohmann said:
Whoops, my mistake. Replace the following line in ShowASX.asp:

xml.Load Server.MapPath(f.Name)

With this line:

xml.Load PATH & f.Name

Also, make sure there's a trailing backslash in the PATH constant.



Two things would be involved. First, you would need to combine all the
playlist data into one file, either programmatically or manually. Then you
could use the <xsl:sort> tag in XSL to sort the ENTRY tags by date
associated with Ref/@href.

Here's a section of the wcschools.com tutorial on XSL that deals with
sorting:
http://www.w3schools.com/xsl/xsl_sort.asp

Chris, I am in your debt.
I gotta get my head around this XML, it seems to be a good solution to my
ever growing web site wish-list.
Thank you again, Very Much for your time.
I'm gonna start work on the sorting now. the school site makes it look so
easy!
-michael
 
M

.:mmac:.

2. I would like to have a small gif at one end or the other linked to the
You will need to modify the asx2html.xsl file. It shouldn't be too hard.
You would add something like the following:

<td>
<a>
<xsl:attribute name="href">
<xsl:value-of select="Ref/@href"/>
</xsl:attribute>
<img src="icon.gif"/>
</a>
</td>

Chris, The sample above functions, but links to the wma file (from the href
in the asx file) , not the asx file itself.
I can't locate a call to the filename in the xsl because it isn't in the
..asx file. I can figure out a response.write solution but the xsl is so
interesting I want to stick with it. can you tell how to display the .asx
filename in the link?
 
C

Chris Hohmann

.:mmac:. said:
Chris, The sample above functions, but links to the wma file (from the
href in the asx file) , not the asx file itself.
I can't locate a call to the filename in the xsl because it isn't in the
.asx file. I can figure out a response.write solution but the xsl is so
interesting I want to stick with it. can you tell how to display the .asx
filename in the link?
Oh, I see. I misinterpreted the question above. Since the playlist file does
not contain a reference to the asx filename, you will need to pass in a
parameter to the stylesheet processor. This will involve the following
steps:

1. Add a global parameter tag to the stylesheet.
2. Add a link to the playlist file in the output of the stylesheet
referencing the asx_uri parameter.
3. Add code to ShowASX.asp to pass in the asx_uri parameter value to the
stylesheet processor.

Here are the modified versions of the asx2html.xsl and ShowASX.asp files.
These modifications are based on a directory structure where the asx
playlist files are in a "Files" subdirectory relative to the ShowASX.asp and
asx2html.xsl files. You will need to make adjustments based on your own
directory structure. You will also need to adjust for the case sensitivity
as you did before.

[ShowASX.asp]
<%
CONST PATH = "C:\INETPUB\ANSWER\PUBLIC_HTML\ASX\FILES\"
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 UCase(Right(f.Name,4)) = ".ASX" Then
xml.Load PATH & f.Name
proc.input = xml
proc.addParameter "asx_uri", "Files/" & f.Name
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:param name="asx_uri" select="concat('Files/',/Asx/Title,'.asx')"/>
<xsl:template match="Asx">
<tr>
<td colspan="3">
<a>
<xsl:attribute name="href">
<xsl:value-of select="$asx_uri"/>
</xsl:attribute>
<img src="icon.gif"/>
</a>
</td>
</tr>
<xsl:for-each select="Entry">
<xsl:sort
order="descending"
select="concat( substring(Ref/@href,string-length(Ref/@href)-5,2),
substring(Ref/@href,string-length(Ref/@href)-11,2),
substring(Ref/@href,string-length(Ref/@href)-8,2))"
/>
<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:for-each>
</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:
.:mmac:. said:
Chris, The sample above functions, but links to the wma file (from the
href in the asx file) , not the asx file itself.
I can't locate a call to the filename in the xsl because it isn't in the
.asx file. I can figure out a response.write solution but the xsl is so
interesting I want to stick with it. can you tell how to display the .asx
filename in the link?
Oh, I see. I misinterpreted the question above. Since the playlist file
does not contain a reference to the asx filename, you will need to pass in
a parameter to the stylesheet processor. This will involve the following
steps:

1. Add a global parameter tag to the stylesheet.
2. Add a link to the playlist file in the output of the stylesheet
referencing the asx_uri parameter.
3. Add code to ShowASX.asp to pass in the asx_uri parameter value to the
stylesheet processor.

Here are the modified versions of the asx2html.xsl and ShowASX.asp files.
These modifications are based on a directory structure where the asx
playlist files are in a "Files" subdirectory relative to the ShowASX.asp
and asx2html.xsl files. You will need to make adjustments based on your
own directory structure. You will also need to adjust for the case
sensitivity as you did before.

[ShowASX.asp]
<%
CONST PATH = "C:\INETPUB\ANSWER\PUBLIC_HTML\ASX\FILES\"
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 UCase(Right(f.Name,4)) = ".ASX" Then
xml.Load PATH & f.Name
proc.input = xml
proc.addParameter "asx_uri", "Files/" & f.Name
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:param name="asx_uri" select="concat('Files/',/Asx/Title,'.asx')"/>
<xsl:template match="Asx">
<tr>
<td colspan="3">
<a>
<xsl:attribute name="href">
<xsl:value-of select="$asx_uri"/>
</xsl:attribute>
<img src="icon.gif"/>
</a>
</td>
</tr>
<xsl:for-each select="Entry">
<xsl:sort
order="descending"
select="concat( substring(Ref/@href,string-length(Ref/@href)-5,2),
substring(Ref/@href,string-length(Ref/@href)-11,2),
substring(Ref/@href,string-length(Ref/@href)-8,2))"
/>
<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:for-each>
</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>

Thanks for not taking a holiday Chris ;-),
I noticed you did the sort! You are too cool! I'll be testing tonight.

Just out of curiousity, can I create a custom tag in the ASX file and then
call it from the XSL file?
For instance, if I had a tag in the ASX file that looked like this:
<MikesCustomTag>01-01-05.asx</MikesCustomTag>
Then using <td><xsl:value-of select="MikesCustomTag"/></td> in it's place,
would that be possible? Or is that not supported?

BTW I did discover the hard way that ampersands are a no-no in the tags
using this method. Important discovery! The listing doesn't generate any
error, it just doesn't show up!
 
C

Chris Hohmann

[snip]
Just out of curiousity, can I create a custom tag in the ASX file and then
call it from the XSL file?
For instance, if I had a tag in the ASX file that looked like this:
<MikesCustomTag>01-01-05.asx</MikesCustomTag>
Then using <td><xsl:value-of select="MikesCustomTag"/></td> in it's place,
would that be possible? Or is that not supported?

Yes and no. You could certainly add custom tags and process them in the
asx2html.xsl stylesheet. However, technically it would no longer be an ASX
file and media player might not be able to "play" the resulting file.
BTW I did discover the hard way that ampersands are a no-no in the tags
using this method. Important discovery! The listing doesn't generate any
error, it just doesn't show up!

Yes, the ampersand (&) is a reserved character in XML, as are the less-than
(<), greater-than (>), quote (") and apostrophe (') characters. These
characters have special meaning in markup languages like XML. Namely, they
are used to define elements (tags) and attributes. Of the five (5) "entity"
characters, only the "<" and the "&" are strictly reserved, but it's good
practice to uses entity references when dealing with any of these special
characters. Here's a discussion about how character data is handled in XML:

http://www.w3schools.com/xml/xml_cdata.asp
 
M

.:mmac:.

Chris Hohmann said:

This is really great Chris!
I got all of this to work except the sort, I looked all over for syntax
errors and even tried an "order-by" syntax and still the sort doesn't
change. It's like the "concat(..." is not coming back with a value so it's
being ignored.
 
C

Chris Hohmann

.:mmac:. said:
Chris Hohmann said:

This is really great Chris!
I got all of this to work except the sort, I looked all over for syntax
errors and even tried an "order-by" syntax and still the sort doesn't
change. It's like the "concat(..." is not coming back with a value so
it's being ignored.
It's hard to diagnose without seeing your code. Please post your current
asx2html.xsl and one of the asx files you're processing.
 
M

.:mmac:.


This is really great Chris!
I got all of this to work except the sort, I looked all over for syntax
errors and even tried an "order-by" syntax and still the sort doesn't
change. It's like the "concat(..." is not coming back with a value so
it's being ignored.
It's hard to diagnose without seeing your code. Please post your current
asx2html.xsl and one of the asx files you're processing.
Here it is, I only changed the layout and the border for the gif

<?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="3.0" indent="yes"/>
<xsl:param name="asx_uri" select="concat('2005/',/Asx/Title,'.asx')"/>
<xsl:template match="ASX">

<!-- Supposed to sort but doesn't -->
<xsl:for-each select="ENTRY">
<xsl:sort
order="descending"
select="concat( substring(Ref/@href,string-length(Ref/@href)-5,2),
substring(Ref/@href,string-length(Ref/@href)-11,2),
substring(Ref/@href,string-length(Ref/@href)-8,2))"
/>
<tr>
<td>

<!-- Hyperlinked image code -->
<a>
<xsl:attribute name="href">
<xsl:value-of select="$asx_uri"/>
</xsl:attribute>
<img border="0" src="\images\wmp.gif"/>
</a>
</td>

<!-- Title Cell -->
<td><xsl:value-of select="TITLE"/></td>

<!-- Author Cell -->
<td><xsl:value-of select="AUTHOR"/></td>

<!-- Date Routine -->
<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:for-each>
</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>

---------
<ASX version = "3.0">
<TITLE>My Web Site</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> My Web Site </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 - - - - - - - - - - - - - - - - - - - - - - - - -->
<TITLE>Like a Rock</TITLE>
<AUTHOR> MMAC </AUTHOR>
<COPYRIGHT>(c)2005 MyWebSite</COPYRIGHT>
<Ref href = "mms://media.MyWebSite.com/2005/01-02-05.wma" />
</ENTRY>
</ASX>
 
C

Chris Hohmann

.:mmac:. said:
[snip]

This is really great Chris!
I got all of this to work except the sort, I looked all over for syntax
errors and even tried an "order-by" syntax and still the sort doesn't
change. It's like the "concat(..." is not coming back with a value so
it's being ignored.
It's hard to diagnose without seeing your code. Please post your current
asx2html.xsl and one of the asx files you're processing.
Here it is, I only changed the layout and the border for the gif
[snip]

I don't see anything wrong at first glance. Is there only one wma reference
per asx file? If so, that would explain why it's not sorting. I mentioned
previously, that to accomplish the sort you will need to merge the contents
of all the asx files into one file. Can you try adding a few more entries to
one of the asx files and see if that asx file in particular sorts correctly?
 
M

.:mmac:.

I do remember you saying that, I thought you had found a way around it.
My bad.
As for combining them into one, I'm not sure that would work for me. In my
case, each entry would have to have it's own asx file to play so that would
mean that each week I would have to modify the main asx file and also create
the one that plays the file. I live with the ascending order. Which is still
really cool BTW and I am very grateful.
I always had a vision of generating these playlists on the fly,
eliminating the need to keep building them every week...but given what you
have shown me, that sounds like a much larger project and you have been so
generous and such a tremendous help that to ask any more of you would be
rude.
Thanks so much for all your help.

Chris Hohmann said:
.:mmac:. said:
[snip]

This is really great Chris!
I got all of this to work except the sort, I looked all over for syntax
errors and even tried an "order-by" syntax and still the sort doesn't
change. It's like the "concat(..." is not coming back with a value so
it's being ignored.

It's hard to diagnose without seeing your code. Please post your current
asx2html.xsl and one of the asx files you're processing.
Here it is, I only changed the layout and the border for the gif
[snip]

I don't see anything wrong at first glance. Is there only one wma
reference per asx file? If so, that would explain why it's not sorting. I
mentioned previously, that to accomplish the sort you will need to merge
the contents of all the asx files into one file. Can you try adding a few
more entries to one of the asx files and see if that asx file in
particular sorts correctly?
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top