The Atom feed has an Atom namespace specified in the root element without a namespace prefix. The <div/> and other XHTML elements inherit the Atom namespace because they did not explicitly declare the XHTML namespace.
If you want XHTML elements to be bound to the XHTML namespace, you will need to change the <div> in the Atom feed:
<div xmlns:xhtml="http://www.w3.org/1999/xhtml" class="byline">By Sheila F. Buckmaster</div>
or
<xhtml:div class="byline">By Sheila F. Buckmaster</xhtml:div>
If you keep the Atom feed the same and want to generate XHTML elements, you will need to tweak the stylesheet to match the AP:div , and then construct the XHTML elements in the output.
For example, by changing the stylesheet, I apply-templates on the matching AP:div in the mode named xhtml . There is pattern matching for any element in this mode (therefore it will also work for AP:h2 ), which builds XHTML elements using the local-name() matching element.
<?xml version="1.0" encoding="UTF-8"?> <xslt:stylesheet version="1.0" xmlns:xslt="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="urn:my-scripts" xmlns:x="http://www.w3.org/1999/xhtml" xmlns:AP="http://www.w3.org/2005/Atom" exclude-result-prefixes="xslt msxsl user"> <xslt:output method="xml" indent="yes"/> <xslt:template match="/"> <xslt:apply-templates select="/AP:feed//AP:entry"/> </xslt:template> <xslt:template match="AP:entry"> <xslt:text>Hello from entry</xslt:text> <xslt:apply-templates select="AP:content"/> </xslt:template> <xslt:template match="AP:content"> <xslt:text>Hello from content</xslt:text> <xslt:apply-templates select="AP:div[@class='byline']"/> </xslt:template> <xslt:template match="AP:div[@class='byline']"> <xslt:apply-templates select="." mode="xhtml"/> </xslt:template> <xslt:template match="*" mode="xhtml"> <xslt:element name="{local-name()}" namespace="http://www.w3.org/1999/xhtml"> <xslt:apply-templates select="@*|node()" mode="xhtml"/> </xslt:element> </xslt:template> <xslt:template match="@*|text()|comment()|processing-instruction()"> <xslt:copy-of select="."/> </xslt:template> </xslt:stylesheet>
source share