xml - Creating XSL for Atom feed -



xml - Creating XSL for Atom feed -

i'm creating little custom xsl file render rss feed. contents basic, follows. works flawlessly except when source xml contains line 'xmlns="http://www.w3.org/2005/atom"' in feed definition. how address this? i'm not familiar plenty namespaces know how business relationship case.

<?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 xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns="http://www.w3.org/1999/xhtml"> <body style="font-family:arial;font-size:12pt;background-color:#eeeeee"> <xsl:for-each select="feed/entry"> <div style="background-color:teal;color:white;padding:4px"> <span style="font-weight:bold"><xsl:value-of select="title"/></span> - <xsl:value-of select="author"/> </div> <div style="margin-left:20px;margin-bottom:1em;font-size:10pt"> <b><xsl:value-of select="published" /> </b> <xsl:value-of select="summary" disable-output-escaping="yes" /> </div> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet>

you set namespace declaration xslt, this:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:atom="http://www.w3.org/2005/atom" exclude-result-prefixes="atom" > <xsl:template match="/"> <html xmlns="http://www.w3.org/1999/xhtml"> <body style="font-family:arial;font-size:12pt;background-color:#eeeeee"> <xsl:apply-tepmplates select="atom:feed/atom:entry" /> </body> </html> </xsl:template> <xsl:template match="atom:entry"> <div style="background-color:teal;color:white;padding:4px"> <span style="font-weight:bold"> <xsl:value-of select="atom:title"/> </span> <xsl:text> - </xsl:text> <xsl:value-of select="atom:author"/> </div> <div style="margin-left:20px;margin-bottom:1em;font-size:10pt"> <b><xsl:value-of select="atom:published" /> </b> <xsl:value-of select="atom:summary" disable-output-escaping="yes" /> </div> </xsl:template> </xsl:stylesheet>

note atom namespace registered prefix atom: , used in xpath throughout stylesheet. i've used exclude-result-prefixes create sure atom: not show in resulting document.

also note replaced <xsl:for-each> template. should seek avoid for-each in favor of templates, well.

the utilize of disable-output-escaping="yes" unsafe in conjunction xhtml - unless absolutely positive contents of summary well-formed xhtml, too.

xml xslt

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -