[thelist] XSLT transformation

Tim Palac tymartist at gmail.com
Fri Feb 29 10:07:59 CST 2008

Ok so in order to link a stylesheet from your main document, declare this up
top in between the XML tag and RSS tag:
<?xml-stylesheet type="text/xsl" href="file.xsl" version="1.0"?>

Then make an external .xsl file (call it file.xsl or whatever you want) and
put in the content below.  Unfortunately, the only stumbling block I ran
into was parsing the CData, it looks like XSLT cannot directly transform
CData into actual HTML, it just prints all the tags.  You might need to use
PHP for that, since you probably don't want to put the CData directly into
the XSLT file.  Your other option is to re-do the formatting in the XSLT
based on keywords, not sure how that would work though!

Also, you're going to have to replace the image you defined as being from
example.com with your actual source image to get it to work correctly.

Anyway, here's the code.  It defines the namespaces, outputs the doctype
tags/html tags/title tags, and then outputs the content based on what you
have in the items (for as many items as you want, you can restrict it).  Let
me know if you have any questions.

<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0"

    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"
        media-type="application/xhtml+xml" encoding="iso-8859-1"
        doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"

    <xsl:template match="channel">
                <title>RSS Feed</title>
                <meta http-equiv="content-type"
content="application/xhtml+xml; charset=iso-8859-1"/>
    <xsl:for-each select="item">
            <h1><xsl:value-of select="title"/></h1>
            <p><xsl:value-of select="description"/></p>
              <img src="{media:content/@url}"/>


On Fri, Feb 29, 2008 at 5:42 AM, <shaun at porkandpaws.com> wrote:

> Anyone able to help,
> My colleague is trying to transform some xml that contains the following
> has
> asked me for help but I do not know
> <?xml version="1.0" ?>
> <rss version="2.0">
> <channel xmlns:media="http://search.yahoo.com/mrss/"
> xmlns:dc="http://purl.org/dc/elements/1.1/"
> xmlns:atom="http://www.w3.org/2005/Atom">
> <title>Customer</title>
> <description>Customer RSS News Feed.</description>
> <link>http://example.com/rss</link>
> <language>en-gb</language>
> <atom:link href="http://example.com/rss" rel="self"
> type="application/rss+xml"
> />
> <image><title>Customer</title>
> <url>http://example.com/images/feature_box_logo.gif</url>
> <link>http://example.com/rss</link>
> </image>
> <item>
> <title>This is an example article1</title>
> <description><![CDATA[<p>This is some <strong>BOLD TEXT</strong> and this
> is
> <em>ITALIC </em>and now back to normal!</p><p>A
> list.....</p><ul><li>1</li><li>2</li><li>3</li><li>4</li></ul><p>Now some
> order...</p><ol><li>a</li><li>b</li><li>c</li><li>d</li></ol><p>Finally a
> link... <a href="http://www.google.co.uk/">HERE</a></p>]]></description>
> <link>http://example.com/rss/2008/02/20/This-is-an-example-article</link>
> <guid>http://example.com/rss/2008/02/20/This-is-an-example-article</guid>
> <dc:creator>creator</dc:creator>
> <pubDate>20 Feb 2008</pubDate>
> <media:group><media:content url="http://example.com/media/sample.jpg"
> fileSize="27445" type="image/jpeg" isDefault="true">
> <media:rating>nonadult</media:rating>
> </media:content>
> <media:content url="http://example.com/media/sample.jpg" fileSize="27445"
> type="image/jpeg" isDefault="false">
> <media:rating>nonadult</media:rating>
> </media:content>
> </media:group></item>
> </channel>
> </rss>
> He needs to be able to parse both namespaces xsl: and media:
> How?
> Ideally the html would look like
> <h2>title</h2>
> <p>description</p>
> <img src='media:content/@url' ???????????
> Help really appreciated..
> Even if it is just a pointer to another list or reference.
> Shaun
> --
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !

More information about the thelist mailing list