Click to See Complete Forum and Search --> : styling an atom feed


Solaar
06-14-2007, 03:59 PM
Hello,

I have added an RSS feed to a site i'm working on, I'm now tring to add an atom feed which is rendered here...

http://staging.connect-spot.com/repton2007/create_atom_feed.php

I have been trying to use the test XSL pasted below for the styling but it's *****ing me up. If, in the XML above, I replace <feed xmlns="http://www.w3.org/2005/Atom">with <feed> then it works but I'm guessing is no longer an atom feed?

The line...<?xml-stylesheet type="text/xsl" href="feed.xsl"?> is missing from the above so the XML can be seen clearly.

When <?xml-stylesheet type="text/xsl" href="feed.xsl"?> is included it looks like this...

http://staging.connect-spot.com/repton2007/create_atom_feed2.php

Any input appreciated

feed.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="/">
<html>
<body style="font-family:Arial,helvetica,sans-serif;font-size:12pt;
background-color:#EEEEEE">
<div style="background-color:teal;color:white;padding:4px;">
<span style="font-weight:bold;color:white"><xsl:value-of select="feed/title"/></span>
- <xsl:value-of select="feed/id"/>
- <xsl:value-of select="feed/link"/>
- <xsl:value-of select="feed/updated"/>
</div>

<xsl:for-each select="feed/author">
<div style="background-color:blue;color:white;padding:4px">
- <xsl:value-of select="name"/>
- <xsl:value-of select="email"/>
</div>
</xsl:for-each>

<xsl:for-each select="feed/entry">
<div style="background-color:red;color:white;padding:4px">
- <xsl:value-of select="id"/>
- <xsl:value-of select="title"/>
- <xsl:value-of select="link"/>
- <xsl:value-of select="updated"/>
- <xsl:value-of select="summary"/>
</div>
</xsl:for-each>

</body>

</html>
</xsl:template>

</xsl:stylesheet>

jkmyoung
06-15-2007, 10:07 AM
To use namespaces in your stylesheet, you have to declare it beforehand. eg
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:atom="http://www.w3.org/2005/Atom">
('atom' chosen arbitrarily).

Then when referencing an element, prefix it with the declared namespace, eg:
<xsl:value-of select="atom:feed/atom:id"/>