<!-- ==================================================== This XSLT creates an XML sitemap used for search engines. Following these guidelines http://www.sitemaps.org ==================================================== -->
<!-- ==================================================== We setup two parameters. maxLevelForSitemap allows you to configure how deep the sitemap should go. url is the root url - eg: http://localhost ==================================================== --> <xsl:variable name="maxLevelForSitemap" select="10"/> <xsl:variable name="url" select="concat('http://',umbraco.library:RequestServerVariables('HTTP_HOST'))" />
<xsl:template match="/"> <!-- change the mimetype for the current page to xml --> <xsl:value-of select="umbraco.library:ChangeContentType('text/xml')"/> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<!-- ==================================================== This <URL> node is for the homepage/root page ==================================================== --> <url> <loc> <xsl:value-of select="concat($url,'/')"/> </loc> <lastmod> <xsl:value-of select="concat($currentPage/ancestor-or-self::* [@isDoc and @level=1]/@updateDate,'+00:00')" /> </lastmod> </url>
<!-- ==================================================== RUN template drawNodes passing the parent variable as the ROOT node. ==================================================== --> <xsl:call-template name="drawNodes"> <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/> </xsl:call-template> </urlset> </xsl:template>
<!-- ==================================================== If the parent variable is NOT protected ==================================================== --> <xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0">
<!-- ==================================================== For each CHILD node of the parent variable node WHERE umbracoNaviHide is NOT true AND the node's level is less than and equal to the maxLevelForSitemap variable. ==================================================== --> <xsl:for-each select="$parent/* [@isDoc and string(current()/umbracoNaviHide) != '1' and @level <= $maxLevelForSitemap]"> <url> <loc> <xsl:value-of select="$url"/><xsl:value-of select="umbraco.library:NiceUrl(@id)"/> </loc> <lastmod> <xsl:value-of select="concat(@updateDate,'+00:00')" /> </lastmod> </url>
<!-- ==================================================== IF the number of child nodes from the current node in the for-each loop WHERE umbracoNaviHide is NOT true AND the node's levels are less than and equal to the maxLevelForSitemap variable is GREATER than 0. ==================================================== --> <xsl:if test="count(current()/node [string(current()/umbracoNaviHide) != '1' and @level <= $maxLevelForSitemap]) > 0">
<!-- ==================================================== As we have further child nodes recall the same template we are in with the parent variable set to as the current node in the for-each loop. ==================================================== --> <xsl:call-template name="drawNodes"> <xsl:with-param name="parent" select="current()"/> </xsl:call-template> </xsl:if> </xsl:for-each> </xsl:if> </xsl:template> </xsl:stylesheet>
xmlSitemap problems
Hi
When I installed Umbraco I installed it with a lot of data. You know the exampel that follow with Umbraco.
In that exampel the have a file XMLSitemap.xslt
How come it only show pages of the first level in the xml file?
The code looks like this:
My Umbraco version is 4.5.2
Hi Kate
I guess that you are using the new XML schema, right?
I haven't tried working with this exact code snippet, but try changing the last <xsl:if> from this:
to this:
/Kim A
It works perfectly, Thanks
I'm glad that it worked out for you kate. Have a nice day :)
/Kim A
is working on a reply...