JavaScript XML

Example Transform

news.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="./feedtohtml.xsl" ?>
<myrss> <!--changed from rss because firefox is too smart
            and asks me if I want to subscribe. -->
<channel xmlns:html="http://www.w3.org/1999/xhtml">
        <title>CSCE 782: Fall 2006</title>
        <link>http://jmvidal.cse.sc.edu/csce782/</link>
        <description>Announcements.</description>
        <language>en-us</language>
        <copyright>Copyright 2006 jmvidal</copyright>
        <docs>http://blogs.law.harvard.edu/tech/rss/</docs>
        <lastBuildDate>Mon, 04 Dec 2006 15:16:10 EST</lastBuildDate>
<item>
    <title>Final Project Handout</title>
    <pubDate>Mon, 04 Dec 2006 15:14:42 EST</pubDate>
    <guid>http://jmvidal.cse.sc.edu/csce782/news.rss#1165263282</guid>
    <description>

OK, I have posted the final project handout. Let me know if you have
questions.

    </description>
    <link>http://jmvidal.cse.sc.edu/csce782/news.rss</link>
</item>

<item>
    <title>Last Week: No Classes</title>
    <pubDate>Thu, 30 Nov 2006 09:06:43 EST</pubDate>
    <guid>http://jmvidal.cse.sc.edu/csce782/news.rss#1164895603</guid>
    <description>

We will not be meeting during the last week. But, I will be in my
office during class time in case you want to talk about your final
project.
    </description>
    <link>http://jmvidal.cse.sc.edu/csce782/news.rss</link>
</item>

<item>
    <title>Test 2</title>
    <pubDate>Tue, 28 Nov 2006 06:40:37 EST</pubDate>
    <guid>http://jmvidal.cse.sc.edu/csce782/news.rss#1164714037</guid>
    <description>
In case I did not mention it in class, Test 2 will be based solely on the rest of the book chapters. That is, it does not cover the papers I presented in class.
    </description>
    <link>http://jmvidal.cse.sc.edu/csce782/news.rss</link>
</item>

</channel>
</myrss>


feedtohtml.xsl:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/myrss">
<html>
<head>
  <link href="xsl.css" rel="stylesheet" type="text/css" />
        <style type="text/css">
        body {
                font-size:0.83em;
        }
        </style>
</head>
<body>
        <div id="logo">
                <xsl:element name="a">
                        <xsl:attribute name="href">
                                <xsl:value-of select="channel/link" />
                        </xsl:attribute>
                        <xsl:value-of select="channel/title" />
                </xsl:element>
        </div>
        <div class="Snippet" style="border-width:0; background-color:#FFF; margin:1em">
                <div class="titleWithLine">
                        <xsl:value-of select="channel/description" />
                </div>
                <dl style="padding-right:1em">
                        <xsl:for-each select="channel/item">
                                <dd>
                                  <xsl:value-of select="title"/>
                                </dd>
                                <dt>
                                        <xsl:value-of select="description" disable-output-escaping="yes"/><br />
                                        <span class="comments"><xsl:value-of select="pubDate" /></span>
                                </dt>
                        </xsl:for-each>
                </dl>
        </div>
        <div id="footer">
                <xsl:value-of select="channel/copyright" />
        </div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


José M. Vidal .

8 of 10