Re: Newbie: XSL transform with ASP

Discussion in 'XML' started by Andy Dingley, Jun 26, 2003.

  1. Andy Dingley

    Andy Dingley Guest

    On Thu, 26 Jun 2003 13:57:55 -0400, ddavis <>
    wrote:

    >I'm using the below XSL to transform an RSS feed through ASP, but it
    >doesn't write out any HTML. Is there something wrong with the structure
    >of this XSL?


    Works OK for me.

    What's your RSS source ?
     
    Andy Dingley, Jun 26, 2003
    #1
    1. Advertising

  2. Andy Dingley

    ddavis Guest

    The RSS is at
    http://www.computerworld.com/news/xml/coverage/0,5451,1408,00.xml

    And here's the ASP code:
    <%
    Function getXML(sourceFile)
    dim styleFile
    dim source1, style
    styleFile = Server.MapPath("hipaa2.xsl")

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

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

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

    getXML = source1.transformNode(style)
    set source1 = nothing
    set style = nothing
    End Function
    %>

    And it (theoretically) writes it out on the ASP page here (but it
    doesn't work):
    <%
    getXML("http://www.computerworld.com/news/xml/coverage/0,5451,1408,00.xml")
    %>

    Anyone have any thoughts?

    Andy Dingley wrote:
    >>I'm using the below XSL to transform an RSS feed through ASP, but it
    >>doesn't write out any HTML. Is there something wrong with the structure
    >>of this XSL?

    >
    >
    > Works OK for me.
    >
    > What's your RSS source ?
    >
     
    ddavis, Jun 27, 2003
    #2
    1. Advertising

  3. Andy Dingley

    Andy Dingley Guest

    On Fri, 27 Jun 2003 08:23:13 -0400, ddavis <>
    wrote:


    >And it (theoretically) writes it out on the ASP page here (but it
    >doesn't work):
    ><%
    >getXML("http://www.computerworld.com/news/xml/coverage/0,5451,1408,00.xml")
    >%>
    >
    >Anyone have any thoughts?


    ROFL.....

    You're evaluating getXML, but you aren't doing anything with the
    answer. Try this instead:

    <%=getXML("http://www.computerworld.com/news/xml/coverage/0,5451,1408,00.xml")
    %>


    Having said that, your stylesheet is pretty broken. It works (in a
    fashion) for RSs 1.0, but not for 0.91 et al.

    Using
    <xsl:value-of select="channel/title"/> and
    <xsl:for-each select="channel/item"> instead will fix a few things.
    But it's still a poorly-structured piece of code. There are lots of
    RSS stylesheets around, so borrow them instead.


    <xsl:template match="*">

    Yeuch. This matches anything - it's unsupportable for any stylesheet
    with more than a couple of rules in it.

    Don't use <xsl:template match="... anyway Use a named template and
    call it by name. Pass the channel, or the set of items, as named
    parameters to it. This will give you much clearer code that you can
    maintain in the future. Keep <xsl:template match="... for matching
    the dregs near the leaves of the document tree, when you no longer
    know what the structure will be.

    Whenever you write a template rule, include a comment that describes
    what it expects as input. In your example it's unclear.



    As a couple of other comments:

    You can ditch the XMLHTTP object (load it straight into the DOM)

    Object creation is expensive and slow. Try holding them in an
    application variable instead, and only creating the object if the
    reference is empty.

    Check the errors returned on loading and transforming. Many RSS feeds
    are broken.

    Use XMLDOM.Save (Response) to return the results, not
    Response.Write()

    Don't use <%= anywhere you care about performance. Response.Write()
    is much better.
     
    Andy Dingley, Jun 27, 2003
    #3
  4. Andy Dingley

    ddavis Guest

    Thank you for the thorough eval. As mentioned in the subject line, I'm
    new to XML/XSL, so please forgive the errors. I'm going through your
    suggestions now. Much appreciated.


    Andy Dingley wrote:
    > On Fri, 27 Jun 2003 08:23:13 -0400, ddavis <>
    > wrote:
    >
    >
    >
    > You're evaluating getXML, but you aren't doing anything with the
    > answer. Try this instead:
    >
    > <%=getXML("http://www.computerworld.com/news/xml/coverage/0,5451,1408,00.xml")
    > %>
    >
    >
    > Having said that, your stylesheet is pretty broken. It works (in a
    > fashion) for RSs 1.0, but not for 0.91 et al.
    >
     
    ddavis, Jun 27, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KathyB
    Replies:
    0
    Views:
    1,024
    KathyB
    Jun 25, 2003
  2. Barry Anderberg
    Replies:
    2
    Views:
    589
    Chris Barber
    Apr 8, 2004
  3. chris
    Replies:
    1
    Views:
    414
    chris
    Jan 21, 2004
  4. Alan
    Replies:
    1
    Views:
    426
    Patrick TJ McPhee
    Jul 11, 2004
  5. Replies:
    1
    Views:
    3,615
    A. Bolmarcich
    May 27, 2005
Loading...

Share This Page