Google Sitemap in Vertical Site

We consultants must be on top of every hype. This is not a new one but still important to know it takes only minutes to implement.

Sitemap in general

To make a sitemap is an easy task i Vertical Site.

First, you need a datasource for your objekt:

<datasources>
<datasource>
<methodname>getMenu</methodname>
<parameters>
<parameter name="menu" override="false" type="int">0</parameter>
<parameter name="id" override="false" type="int">0</parameter>
<parameter name="levels" override="false" type="int">0</parameter>
</parameters>
</datasource>
</datasources>

The xsl can also be pretty clean but I like to test if it's the first or last node. It depends on the design.

<xsl:template match="/">
<div class="sitemap">
<ul>
<xsl:for-each select="/verticaldata/menus/menu/menuitems/menuitem">
<li>
<xsl:if test="position() = 1">
<xsl:attribute name="class">first</xsl:attribute>
</xsl:if>
<xsl:if test="position() = last()">
<xsl:attribute name="class">end</xsl:attribute>
</xsl:if>
<a href="{portal:createPageUrl(@key, ())}">
<xsl:value-of select="name"/>
</a>
<xsl:if test="menuitems/menuitem">
<ul>
<xsl:for-each select="menuitems/menuitem">
<xsl:call-template name="menu">
<xsl:with-param name="curitem" select="."/>
<xsl:with-param name="level" select="1"/>
</xsl:call-template>
</xsl:for-each>
</ul>
</xsl:if>
</li>
</xsl:for-each>
</ul>
</div>
</xsl:template>

You need one more template but you get the idea.

What about the Google Sitemap? This is not a HTML-page, but a XML-page. Google uses this to get an overview over your sites structure.

You can use the same datasource as a start.

Sitemap XSL

I implement this as a standalone page, with no object. I put the datasource on the Page template.

I create a Page XSL and start of by importing all the namespaces that I need.

<xsl:stylesheet exclude-result-prefixes="portal xsi" version="2.0" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:portal="http://www.enonic.com/cms/xslt/portal" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<xsl:output encoding="UTF-8" indent="yes" method="xml" omit-xml-declaration="no"/>
<xsl:include href="formatDate.xsl"/>
<xsl:param name="baseURL" select="'http://www.helsebiblioteket.no/'"/>
<xsl:param name="name" select="'google'"/>
<xsl:param name="priority" select="0.5"/>
<xsl:param name="changefreq" select="'weekly'"/>
<xsl:variable name="language" select="/verticaldata/context/@languagecode"/>

.......

After that it's pretty much basic stuff:

<xsl:template match="/">
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<xsl:if test="/verticaldata/contents/content or /verticaldata/menus/menu/menuitems/menuitem or /verticaldata/menuitems/menuitem or /verticaldata/menuitems/menuitem/menuitems/menuitem">
<xsl:for-each select="/verticaldata | /verticaldata/menus/menu">
<xsl:call-template name="applyItems"/>
</xsl:for-each>
</xsl:if>
</urlset>
</xsl:template>

I the applyItems template I test if it's a menuitem or content. I really dump the whole node-tree with all content.

In the combined template content and menuitem I print the sitemap xml:

<xsl:template match="menuitem | content">
.... a lot of variables here ....
<url>
<loc>
<xsl:value-of select="$href"/>
</loc>
<lastmod>
<xsl:call-template name="formatDate">
<xsl:with-param name="date" select="@timestamp"/>
<xsl:with-param name="format" select="'sitemapXML'"/>
</xsl:call-template>
</lastmod>
<xsl:if test="not($changefreq_final = '')">
<changefreq>
<xsl:value-of select="$changefreq_final"/>
</changefreq>
</xsl:if>
<xsl:if test="not($priority_final = '')">
<priority>
<xsl:value-of select="$priority_final"/>
</priority>
</xsl:if>
</url>
<xsl:if test="menuitems/menuitem">
<!-- Rekursivt -->
<xsl:apply-templates select="menuitems/menuitem"/>
</xsl:if>
</xsl:template>

Final result

I use this template on all my recent project, and the last one you can find at Helsebiblioteket's website.

The really cool thing is that you can have (almost) any name on your menuitems, and then offcourse I named my "sitemap.xml".

Then I navigate to my gmail-account and register the new sitemap.xml and everyting is just great.

Take a look here:

http://www.helsebiblioteket.no/sitemap.xml

Comments

If you want to comment on this article you need to be logged in.

Published in 2011

2010

2009

2008

2007