Google Sitemap
Tuesday, 30. December 2008, 19:36:13
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" exclude-result-prefixes="msxml umbraco.library"> <xsl:output method="xml" omit-xml-declaration="yes"/> <xsl:param name="currentPage"/> <!-- update this variable on how deep your site map should be --> <xsl:variable name="maxLevelForSitemap" select="10"/> <xsl:template match="/"> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <xsl:call-template name="drawNodes"> <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=1]"/> </xsl:call-template> </urlset> </xsl:template> <xsl:template name="drawNodes"> <xsl:param name="parent"/> <xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)"> <xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level <= $maxLevelForSitemap]"> <url xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <loc>http://www.corazine.com<xsl:value-of select="umbraco.library:NiceUrl(@id)"/></loc> <lastmod><xsl:value-of select="umbraco.library:FormatDateTime(@updateDate, 'yyyy-MM-dd')"/></lastmod> <changefreq>weekly</changefreq> </url> <xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1' and @level <= $maxLevelForSitemap]) > 0"> <xsl:call-template name="drawNodes"> <xsl:with-param name="parent" select="."/> </xsl:call-template> </xsl:if> </xsl:for-each> </xsl:if> </xsl:template> </xsl:stylesheet>
and the template:
<%@ Master Language="C#" MasterPageFile="/umbraco/masterpages/default.master" AutoEventWireup="true" %> <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server"> <umbraco:Macro ContentType="text/xml" Alias="uuContentType" runat="server"></umbraco:Macro><?xml version="1.0" encoding="UTF-8"?><umbraco:Macro Alias="SitemapXml" runat="server"></umbraco:Macro> </asp:Content>
et voila


Anonymous # 30. December 2008, 22:56
Maybe a weird question... but if you check your RSS output, don't you see UTF-16 on top instead of UTF-8?
Anonymous # 30. December 2008, 23:02
... or none at all or course, in which case you'd need to add that for a valid sitemap. But I have this feeling that omit-xml-declaration="no" would produce strange results. Does it validate?
Anonymous # 31. December 2008, 01:17
I think i also see in v4 that change content type is built into umbraco.library here is a snippet from the rss template that came with RC4
Gerty Engrie # 31. December 2008, 10:31
the omit-xml-declaration="no" does idd produce non-valid things...
@bootnumlock Thanks for the tip!
Anonymous # 2. January 2009, 10:38
But then your sitemap is invalid. Have had parsing problems with that. (http://www.sitemaps.org/protocol.php)
The trick is to either add the XML declaration in your template, or using an to render it inside XSLT.
Gerty Engrie # 2. January 2009, 13:50