Converting XML via XSLT to HTML page
"parkwood149" <[email protected]> Mon, 25 Jul 2005 05:40:49 -0000
| Newsgroups | gmane.network.syndication.rss.devel |
|---|---|
| Message-ID | <[email protected]> |
I am trying to convert an xml file to HTML and have it look similiar to the CSS
styleesheet. I am getting stuck with the XSLT. Can someone advise? Or does
someone have a XSLT I can use to learn from. I have not seen a good
example:
the css file is:
channel {
display: block;
margin-left: 10px;
height:80px;
width: 450px;
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size: 14px;
}
channel > title {
display: block;
position:absolute;
top:0px;
left:0px;
height: 80px;
background-color: #6699FF;
font-weight:bold;
color: #FFFFFF;
font-family: Arial,Helvetica,sans-serif;
font-size: 48px;
}
channel > description {
display: block;
color:#003366;
margin-left: 10px;
width: 450px;
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size: 18px;
}
channel > link, docs, copyright, lastBuildDate, language, link {
display: none;
}
image > title, url, link {
display: none;
}
item > author, pubDate, Category, Source, Comments {
display: none;
}
item {
display: block;
margin-left: 10px;
width: 450px;
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size: 14px;
}
item > title {
display: block;
background-color: white;
color: black;
border-bottom: 1px solid silver;
font-size: 18px;
}
item > link, Enclosure {
display: block;
font-size: 14px;
}
item > description {
display: block;
font-size: 14px;
width: 450px;
}
the XML file is:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="rss1.css" type="text/css"?>
<rss version="2.0">
<channel>
<title>prsa.org </title>
<link>http://www.prsa.org</link>
<description>The latest articles from Tactics and Strategist Online</
description>
<language>en-us</language>
<copyright>@2004-2005 PRSA</copyright>
<docs>docs</docs>
<lastBuildDate>July 14, 2005</lastBuildDate>
<item>
<title>Final Watergate revelation prompts questions</title>
<description>When I was a journalism student at the University of Colorado,
"All the President's Men" was required reading. The notion that a couple of
persistent reporters could unravel a White House conspiracy and help unseat
the most powerful man in the world was exhilarating. As a PR counselor and
media interview trainer, I caution clients never to go off-the-record unless they
can live with the possibility that they won't remain anonymous.</description>
<link>http://prsa.org/_Publications/magazines/0705news.asp</link>
<Enclosure>http://www.cnn.com</Enclosure>
<author>Dan Keeney, APR</author>
<pubDate>July 14, 2005</pubDate>
<Category>News and Views</Category>
<Source>PRSA</Source>
<Comments>Optional Field</Comments>
</item>
<item>
<title>Overcoming obstacles to achieve PR success</title>
<description>For as long as she can remember, Paula Pedene, APR,
wanted to be a journalist. In high school she wrote for the local newspaper
and was the yearbook editor. She planned on attending college to study
journalism, but a devastating fire destroyed her family home and all of
Pedene's college funds were used in its restoration. She remained
undaunted, however, and looked for another way to get an education and
pursue her dream.</description>
<link>http://prsa.org/_Publications/magazines/strategist.asp</link>
<Enclosure>http://www.apple.com/itunes/prsa.mp3</Enclosure>
<author>Dennis John Gaschen, APR</author>
<pubDate>July 1, 2005</pubDate>
<Category>Profiles in PR</Category>
<Source>PRSA</Source>
<Comments>Optional Field</Comments>
</item>
</channel>
</rss>
the XSLT file is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<!-- Indicating to Display Output in HTML Format -->
<xsl:output method="html" />
<!-- Matching RSS FEED Characteristics -->
<xsl:template match="rss">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><xsl:apply-templates select="rss/channel/description" /></title>
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<!-- Display Channel Element in HTML -->
<xsl:template match="channel">
<div class="channel" style="display:block; position:absolute;
top:0px;
left:0px;
height: 24px;
background-color: #6699FF;
font-weight:bold;
width:100%;
color: #FFFFFF;
font-family: Arial,Helvetica,sans-serif;
font-size: 24px;">
<xsl:apply-templates select="title" />
</div>
</xsl:template>
<!-- Display Item Elements in HTML -->
<xsl:template match="item">
<p /><xsl:apply-templates select="title" />
<br /><xsl:apply-templates select="description" /><br />
<b>Full Story:</b> <xsl:apply-templates select="link" /><br />
<b>Podcast:</b> <xsl:apply-templates select="Enclosure" /><br />
<hr></hr>
</xsl:template>
<!-- Exclude Channel Elements from HTML Display -->
<xsl:template match="rss/channel/author" />
<xsl:template match="rss/channel/language" />
<xsl:template match="rss/channel/docs" />
<xsl:template match="rss/channel/copyright" />
<xsl:template match="rss/channel/lastBuildDate" />
<xsl:template match="rss/channel/description" />
<xsl:template match="rss/channel/link" />
<!-- Exclude Item Elements from HTML Display -->
<xsl:template match="rss/item/author" />
<xsl:template match="rss/item/Category" />
<xsl:template match="rss/item/Source" />
<xsl:template match="rss/item/pubDate" />
<xsl:template match="rss/item/Comments" />
</xsl:stylesheet>
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/rss-dev/
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/