Intent to Unship: XSLT

5 pointsposted 4 hours ago
by tambourine_man

1 Comments

dfabulich

2 hours ago

Now seems a good time to mention that you can beautify your XML RSS/Atom feeds without XSLT using CSS and JS.

You can add a stylesheet to an Atom feed by adding a <link> tag with an xmlns attribute, like this:

    <?xml version="1.0" encoding="utf-8"?>
    <feed xmlns="http://www.w3.org/2005/Atom">
        <link rel="stylesheet" href="style.css" xmlns="http://www.w3.org/1999/xhtml" />
        <!-- ... the rest of the feed goes here ... -->
Or add styles directly with a <style> tag:

    <?xml version="1.0" encoding="utf-8"?>
    <feed xmlns="http://www.w3.org/2005/Atom">
        <style xmlns="http://www.w3.org/1999/xhtml"><![CDATA[
            * { color: red; }
        ]]></style>
        <!-- ... the rest of the feed goes here ... -->
You can even run JavaScript when users browse to your feed like this:

    <?xml version="1.0" encoding="utf-8"?>
    <feed xmlns="http://www.w3.org/2005/Atom">
        <script src="script.js" xmlns="http://www.w3.org/1999/xhtml" />
        <!-- ... the rest of the feed goes here ... -->
You can use JS to transform your XML, just like you can (could) with XSLT.