Can't separate XSL styles with multiple RSS feeds

B

Burt Lewis

Hi,

I have 2 xsl style sheets calling separate rss feeds and I use ASP to
display.

Problem is that the 1st xsl takes on the style of the 2nd xsl even
though they are different formats. I think I need to clear from memory
but not sure how. This is the code and sample outputs. They work great
on their own but when I call them both they display the same formats.
Thanks for any help.

news4.asp

<%
Function getXML(sourceFile)
dim styleFile
dim source, style
styleFile = Server.MapPath("news.xsl")

Dim xmlhttp
Set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP")
xmlhttp.Open "GET", sourceFile, false
xmlhttp.Send

set source = Server.CreateObject("Microsoft.XMLDOM")
source.async = false
source.loadxml(xmlhttp.ResponseText)

set style = Server.CreateObject("Microsoft.XMLDOM")
style.async = false
style.load(styleFile)

getXML = source.transformNode(style)
set source = nothing
set style = nothing
End Function
%>
<html>

<%= getXML("http://syndication.boston.com/news?mode=rss_10?") %>

===========
news.xsl

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="*">
<table border="1" width="100%" align="center">
<tr><td valign="top" align="center" class="title" bgcolor="silver" >
<a>
<xsl:attribute name="href">
<xsl:value-of select="*[local-name()='channel']/*[local-name()='link']"/>
</xsl:attribute>
<xsl:attribute name="target">
<xsl:text>top</xsl:text>
</xsl:attribute>
<xsl:value-of select="*[local-name()='channel']/*[local-name()='title']"/>
</a>
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
<xsl:value-of select="*[local-name()='channel']/*[local-name()='lastBuildDate']"/>
</td></tr><tr><td valign="top" bgcolor="ghostwhite"
class="headlines"><font size="2">
<xsl:for-each select="//*[local-name()='item' and position() &lt;
10]">
<a>
<xsl:attribute name="href">
<xsl:value-of select="*[local-name()='link']"/>
</xsl:attribute>
<xsl:attribute name="target">
<xsl:text>top</xsl:text>
</xsl:attribute>
<xsl:value-of select="*[local-name()='title']"/>
</a>
|
</xsl:for-each>
</font></td></tr>
</table>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>

Output by itself:
http://www.eastonmass.com/forum/news4.asp

==========================================

Next feed: weather3.asp

<%
Function getXML(sourceFile)
dim styleFile
dim source, style
styleFile = Server.MapPath("weather3.xsl")

Dim xmlhttp
Set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP")
xmlhttp.Open "GET", sourceFile, false
xmlhttp.Send

set source = Server.CreateObject("Microsoft.XMLDOM")
source.async = false
source.loadxml(xmlhttp.ResponseText)

set style = Server.CreateObject("Microsoft.XMLDOM")
style.async = false
style.load(styleFile)

getXML = source.transformNode(style)
set source = nothing
set style = nothing
End Function
%>
<html>


<%= getXML("http://www.rssweather.com/rss.php?c...ountry=us&county=25005&zone=MAZ017&alt=rss20a")
%>

=============
weather3.xsl

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="xml" omit-xml-declaration="yes" indent="yes" />
<xsl:template match="*">
<table border="1" width="100%" align="center">
<tr>
<td valign="top" align="center" class="title" bgcolor="silver">
<xsl:value-of select="*[local-name()='channel']/*[local-name()='title']"
/>
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
<xsl:value-of select="*[local-name()='channel']/*[local-name()='lastBuildDate']"
/>
</td>
</tr>
<tr>
<td valign="top" bgcolor="ghostwhite" class="headlines">
<ul>
<xsl:for-each select="//*[local-name()='item' and position() &lt;
13]">
<!--
<xsl:value-of select="*[local-name()='channel']/*[local-name()='title']"
/>
-->
<b>
<xsl:value-of select="*[local-name()='title']" />
:
</b>
<xsl:value-of select="*[local-name()='description']"
disable-output-escaping="yes" />
--
</xsl:for-each>
</ul>
</td>
</tr>
</table>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>

===========================
output for weather3.asp
http://www.eastonmass.com/forum/weather3.asp

===========================
Calling them both:
testboth.asp

<!--#INCLUDE FILE="news4.asp" -->
<!--#INCLUDE FILE="weather3.asp" -->

==================
output for testboth.asp

http://www.eastonmass.com/forum/testboth.asp (here's the problem)

====================================
As you can see, the news feed takes on the attributes of the weather
feed which I don't want. Appreciate any help.
 
A

Andy Dingley

Problem is that the 1st xsl takes on the style of the 2nd xsl even
though they are different formats. I think I need to clear from memory
but not sure how. This is the code and sample outputs. They work great
on their own but when I call them both they display the same formats.
Thanks for any help.

This is an ASP (and general coding style) problem, not an XSL problem.

Your ASP "testboth" is using the include mechanism to link in both ASP
fragments. This is a good idea, but the implementation isn'right.
Each include file declares a function called getXML() and then invokes
it, and the two functions are slightly different to render the two
different feeds. This won't work in ASP (or almost any programming
environment) - because the two functions have the same name, only one
of them can be "in scope" at the same time.

I suggest that you make the stylesheet a parameter to the function in
just the same way you've already done it for the feed source. Then
it'll work.

Alternatively, keep two functions but rename them as
getRSSAsHTML_TableStyle() and getRSSAsHTML_BlockStyle() or
something like that.

Neater code might be to use three include files instead of two. Put
the function declaration in one, and put the two calls to it in the
others. That way you can use the function whenever you want - you
might even just use the include file once and place the two calls (and
their feed / stylesheet URLs) directly into the page that calls them.
 
B

Burt Lewis

Bingo!

Thank you very much for your help that was exactly what I needed.
Everything works great now.
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top