Problem with Sitemap Options
dajarvo
Posted: Friday, April 18, 2008 10:50:10 AM
Rank: Newbie

Joined: 1/29/2008
Posts: 11
Location: South Wales
I'm having some difficulty trying to implement a Google Sitemap. I've looked through the forums the last few days but cant find any topics that give help on what I need. I think i'm close to getting it working.

I've downloaded Warren's Creative web package (havent installed it onto my site as I thought it might interfere with some of our existing content namely the XSLT Search) and have opened up the Google Sitemap XSL file. My problem is what I need to do to get it working.

I've created a XSLT named GoogleSitemap using the XSLT provided in Warren's package (copied below) and selected the create macro with the same name. I then have created a new template for GoogleSitemap based on one of my other templates and within the tag for where the main body content goes put the umbraco macro link

<?UMBRACO_MACRO macroAlias="GoogleSitemap" ></?UMBRACO_MACRO>

When i publish the page however in the <body> i only get

Quote:
/googlesitemap.aspx2008-04-17T16:49:59+00:00


I guess I have not strucutured my site proberly for it to pick up every page contained on the site my current strucutre is like this

Code:

Content
   -Home
   -The College
        -Some sub pages
   -Community Learning
        -Some sub pages
   -Student Life
        -Some sub pages
   -News and Events
        -Some sub pages
   -Business
        -Some sub pages
   -Contact Us
        -Some sub pages
   -Google Sitemap



Code:
<?xml version="1.0" encoding="UTF-8"?>
<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="html"/>
<xsl:param name="currentPage"/>
<xsl:variable name="maxLevelForSitemap" select="6"/>
<xsl:variable name="url" select="$currentPage/data [@alias = 'DomainURL']" />


<xsl:template match="/">
    <url>    
        <loc>
            <xsl:value-of select="$url"/><xsl:value-of select="umbraco.library:NiceUrl($currentPage/ancestor-or-self::node [@level=1]/@id)"/>
        </loc>
        <lastmod>
            <xsl:value-of select="$currentPage/ancestor-or-self::node [@level=1]/@updateDate" />+00:00
        </lastmod>
        </url>

    <xsl:call-template name="drawNodes"> 
        <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=1]"/>
    </xsl:call-template>
</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 &lt;= $maxLevelForSitemap]">
            <url>    
                <loc>
                    <xsl:value-of select="$url"/><xsl:value-of select="umbraco.library:NiceUrl(@id)"/>
                </loc>
                <lastmod>
                    <xsl:value-of select="@updateDate" />+00:00
                </lastmod>
            </url>
            <xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 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>


Any help on this is much appreciated.
mortenbock
Posted: Friday, April 18, 2008 12:17:37 PM

Rank: Addict

Joined: 7/19/2006
Posts: 815
Location: Århus, Denmark
I think the reason for this is that you have placed all you nodes directly under the "Content" node.

Because Umbraco supports multiple sites in one installation, the best practice for site structure is like this

Code:

Content
   -Home (site 1 with some domain)
        -The College
             -Some sub pages
        -Community Learning
             -Some sub pages
        -Student Life
             -Some sub pages
        -News and Events
             -Some sub pages
        -Business
             -Some sub pages
        -Contact Us
             -Some sub pages
        -Google Sitemap
   -Home (site 2 with some other domain)
        -The College
             -Some sub pages
        -Community Learning
             -Some sub pages
        -Student Life
             -Some sub pages
        -News and Events
             -Some sub pages
        -Business
             -Some sub pages
        -Contact Us
             -Some sub pages
        -Google Sitemap


But if you are not too keen on rearranging your site, you could change the XSLT:

Code:

    <xsl:call-template name="drawNodes">
        <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::root"/>
    </xsl:call-template>


Also, you should note that the google sitemap should not be shown inside an HTML page, since it outputs XML for google to read. So your google sitemap template should only contain the macro, and nothing else, and should not have a master template attached.




Morten Bock - Level 2 certified - MVP 2008/2009 - My danish blog with a few english posts

VirtualRichard
Posted: Friday, April 18, 2008 1:26:53 PM

Rank: Fanatic

Joined: 9/17/2007
Posts: 265
Location: London, UK.
mortenbock wrote:


Code:

    <xsl:call-template name="drawNodes">
        <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::root"/>
    </xsl:call-template>




I've had a non-functioning Google map sitting on my site for a while. I thought this might fix it but I get:
Code:
System.Xml.XPath.XPathException: Function 'umbraco.library:IsProtected()' has failed. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.FormatException: Input string was not in a correct format.

My content is in the same layout (multiple nodes under content). This is because the client wanted website URLs in the browser to appear in a specific manner.

Richard

2 * 3 * 3 * 37 : The prime factorisation of The Beast.
mortenbock
Posted: Friday, April 18, 2008 1:41:18 PM

Rank: Addict

Joined: 7/19/2006
Posts: 815
Location: Århus, Denmark
Hmm. maybe it fails because the root element does not have a path attribute on it.

How about this solution?

Code:

<?xml version="1.0" encoding="UTF-8"?>
<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="html"/>
  <xsl:param name="currentPage"/>
  <xsl:variable name="maxLevelForSitemap" select="6"/>
  <xsl:variable name="url" select="$currentPage/data [@alias = 'DomainURL']" />


  <xsl:template match="/">
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
      <xsl:for-each select="$currentPage/ancestor-or-self::root/node">
      <xsl:call-template name="drawNodes">
        <xsl:with-param name="parent" select="."/>
      </xsl:call-template>
      </xsl:for-each>
    </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 &lt;= $maxLevelForSitemap]">
        <url>
          <loc>
            <xsl:value-of select="$url"/>
            <xsl:value-of select="umbraco.library:NiceUrl(@id)"/>
          </loc>
          <lastmod>
            <xsl:value-of select="@updateDate" />+00:00
          </lastmod>
        </url>
        <xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 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>


Morten Bock - Level 2 certified - MVP 2008/2009 - My danish blog with a few english posts

drobar
Posted: Friday, April 18, 2008 2:49:33 PM

Rank: Umbracoholic

Joined: 9/8/2006
Posts: 1,831
Location: MA, USA
Just chiming in to pick up on a comment you've had about the content tree structure... Morten is right in that sites typically have the structure he's outlined, but that not a requirement. The structure Richard has is also valid. In fact, they will each produce the same urls! Well, they will produce the same urls if the mbracoHideTopLevelNodeFromPath flag is changed in the web.config file.

By default, umbraco hides the top level nodes from the url path to documents. Thus Morten's structure produces this kind of url...
Code:

Content
   -Home (site 1 with some domain)     -> /home.aspx
        -The College                   -> /the-college.aspx
             -Some sub pages           -> /the-college/some-sub-pages.aspx


If umbracoHideTopLevelNodeFromPath is set to false in the web.config, then Richard's structure will produce the same result:
Code:

Content
   -Home                   -> /home.aspx
   -The College            -> /the-college.aspx
        -Some sub pages    -> /the-college/some-sub-pages.aspx


Don't you just love umbraco's flexibility!?!

I should note that Morten's structure allows for multiple domains to be contained in a single umbraco instance much more easily than Richard's. But if you are only going to have a single site and domain then either will work if you configure the web.config properly:
<add key="umbracoHideTopLevelNodeFromPath" value="true"/> (for Morten's approach)
<add key="umbracoHideTopLevelNodeFromPath" value="false"/> (for Richard's approach).


...okay, you two can get back to working on your xslt :)

cheers,
doug.

MVP 2007-2009 - Percipient Studios
VirtualRichard
Posted: Friday, April 18, 2008 4:24:33 PM

Rank: Fanatic

Joined: 9/17/2007
Posts: 265
Location: London, UK.
drobar wrote:
I should note that Morten's structure allows for multiple domains to be contained in a single umbraco instance much more easily than Richard's.


Blame my boss :) he wants /that/sompage.aspx rather than /this/that/somepage.aspx.

I was glad to find I could hide the top directory or I'd have lost both paddles overboard...

Anyway, I tried the XSLT above and it works! I am *very* grateful for that stylesheet! Many thanks.

Now I realise I should have paid more attention to hiding nodes Boo hoo!

Richard

2 * 3 * 3 * 37 : The prime factorisation of The Beast.
thomwhaites
Posted: Friday, May 02, 2008 3:48:29 PM
Rank: Fanatic

Joined: 7/20/2006
Posts: 256
Location: Boston, Massachusetts
I'm having some trouble generating the xml for a sitemap as well.
I first tried to set the output to xml, but I couldn't get the xsl:output to be correct.

I tried:
Code:

<xsl:output method="xml" encoding="utf-8" />


But the result would still be:
Code:

<?xml version="1.0" encoding="UTF-16"?>


Then I noticed in this thread using output method of html to generate the xml (which seemed odd to me), and I included the xml version line in the template.

That seemed to fix half the problem (although it seems incorrect to me to use output html to generate xml). The other half of my problem is that using either output method, the url element in my xml automatically has a blank xmlns attribute appended to it. The result looks like this:
Code:

<url xmlns="">

even though I did not include the xmlns in my stylesheet. This bit failed the sitemap validator I tested against. How can I remove the xmlns attribute?

Thanks,
Tom
drobar
Posted: Friday, May 02, 2008 4:16:42 PM

Rank: Umbracoholic

Joined: 9/8/2006
Posts: 1,831
Location: MA, USA
Hi, Tom,

Are you trying to create a sitemap page for your website visitors to use (which would be html-esque), or more like an (xml-based) google sitemap file?

Everything in this thread so far is for the first [EDIT: What was I thinking when I wrote that?!?]. But if you want the second... well, that's possible too but before I go and explain it I thought I'd ask :o)

cheers,
doug.

MVP 2007-2009 - Percipient Studios
thomwhaites
Posted: Friday, May 02, 2008 5:52:02 PM
Rank: Fanatic

Joined: 7/20/2006
Posts: 256
Location: Boston, Massachusetts
Hi Doug,

I had assumed that the example in this thread was for site visitors, but it looks like it is designed to output the sitemap protocol xml file
Code:

<urlset>
<url>
<loc></loc>
<lastmod></lastmod>
</url>
</urlset>


This is what I am trying to generate - a sitemap protocol xml file.

Thanks,
Tom
drobar
Posted: Friday, May 02, 2008 6:31:56 PM

Rank: Umbracoholic

Joined: 9/8/2006
Posts: 1,831
Location: MA, USA
Warren struggled with all the little details last year and came up with a great solution. It's in his Creative Website Wizard package. Go take a look at his Google Sitemap xslt file. That's where the magic happens for creating the raw xml.

Just download his package from his site and look in the .zip file for the GoogleSitemap.xslt file. http://www.creativewebspecialist.co.uk/2007/07/23/a-css-skinnable-umbraco-website-package-update-097/

cheers,
doug.

MVP 2007-2009 - Percipient Studios
thomwhaites
Posted: Friday, May 02, 2008 7:51:32 PM
Rank: Fanatic

Joined: 7/20/2006
Posts: 256
Location: Boston, Massachusetts
Hi Doug,

When I first looked at Warren's google sitemap xslt, I didn't notice that he had placed the root urlset tag in the template. That seems to be the key to creating sitemap xml file that will validate. Thanks for pointing out the package.

Have there been posts on why the xml file can't just be created using the output method xml?

Tom
drobar
Posted: Friday, May 02, 2008 8:58:43 PM

Rank: Umbracoholic

Joined: 9/8/2006
Posts: 1,831
Location: MA, USA
dawoe
Posted: Saturday, May 03, 2008 1:47:53 AM

Rank: Aficionado

Joined: 1/19/2008
Posts: 182
Location: Belgium


Nice to see one of my blogposts show up here :-)

Converting a DotNetNuke site to Umbraco : Follow it here
dawoe
Posted: Saturday, May 03, 2008 1:54:07 AM

Rank: Aficionado

Joined: 1/19/2008
Posts: 182
Location: Belgium
By the way I made my googlesitemap by using alternative template for my homepage. And in that template i use a macro to create the sitemap. So I have my home page like this http://www.dummy.com/home.aspx and my sitemap like http://www.dummy.com/home/googlesitemap.aspx

Converting a DotNetNuke site to Umbraco : Follow it here
sajith
Posted: Tuesday, September 02, 2008 3:52:58 PM
Rank: Devotee

Joined: 4/22/2008
Posts: 62
Location: Dubai
Hi thomwhaites,

If you are able to create the xml file for the sitemap can u please share it over here.



Sajith.
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.