Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Shannon 148 posts 171 karma points
    Feb 12, 2011 @ 18:54
    Shannon
    0

    Creating a news sitemap in Umbraco.

    www.google.com/.../answer.py?answer=93992

    Is there an easy way to mod a sitemap to support Google News Sitemap . I've been trying to find a way of including <news:news> into the XSLT and I keep getting errors.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 12, 2011 @ 21:26
    Chriztian Steinmeier
    0

    Hi Shannon,

    You probably just forgot to declare the news: prefix + namespace - something along the lines of:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
           
    version="1.0"
           
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
           
           
    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
           
    xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"

           
           
    xmlns:umbraco.library="urn:umbraco.library"
           
    exclude-result-prefixes="umbraco.library"
    >

           
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />

           
    <xsl:param name="currentPage" />
           
           
    <xsl:template match="/">
                   
    <urlset>
                           
    <xsl:for-each select="...">
                                   
    <url>
                                            ...
                                           
    <news:news>
                                                    ...
                                           
    </news:news>
                                           
                                   
    </url>
                           
    </xsl:for-each>
                   
    </urlset>
           
    </xsl:template>

    </xsl:stylesheet>

    /Chriztian

  • Shannon 148 posts 171 karma points
    Feb 12, 2011 @ 21:30
    Shannon
    0

    That did it but now I have another issue. After including the name namespace, it's gets included in the <loc> location.

     

    <?xml version='1.0' encoding='UTF-8'?>
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
    xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
    <url xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
    <loc>http://umbraco/news/2009/3/29/gm-chief-rick-wagoner-stepping-down</loc>
    <news:news>
    <news:publication>
    <news:name>Njection</news:name>
    <news:language>en</news:language>
    </news:publication>
    <news:publication_date>2011-02-11T19:50:00+00:00</news:publication_date>
    <news:title></news:title>
    <news:keywords>Lifestyle, Automotive, Technology, </news:keywords>
    </news:news>
    </url>
    <url xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
  • Shannon 148 posts 171 karma points
    Feb 12, 2011 @ 21:31
    Shannon
    0

    oops.. I ment in the <url>

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 12, 2011 @ 21:39
    Chriztian Steinmeier
    0

    OK, actually it shouldn't be a problem but try to remove the "news" prefix from the "exclude-result-prefixes" attribute then... then the processor should just include the namespace on the element and not repeat it anywhere else. (Edit: I've removed it from the sample code now, so that works).

    /Chriztian

  • Shannon 148 posts 171 karma points
    Feb 12, 2011 @ 21:50
    Shannon
    0

    Thanks. I forgot to "include" it in the "exclude-result-prefixes" Works like a dream

  • Shannon 148 posts 171 karma points
    Feb 12, 2011 @ 22:40
    Shannon
    0

    Odd. Now the xmlns:news moved from the <loc> section to the <news:news> section

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 12, 2011 @ 23:07
    Chriztian Steinmeier
    0

    Hi Shannon,

    Namespace display issues has everything to do about scopes - but the main thing you should know is this: The XML will work just fine (unless the parser reading it is seriously badly implemented).

    If you like, post the full XSLT file here, and I can tell you what's going on...

    Very short explanation - these 2 snippets are exactly the same to an XML parser:

    <!-- Version 1 -->
    <urlset xmlns="http://defaultnamespace.com">
        <url>
            <news:news xmlns:news="http://news-namespace.com">...</news:news>
        </url>
    </urlset>
    
    <!-- Version 2 -->
    <urlset xmlns="http://defaultnamespace.com" xmlns:news="http://news-namespace.com">
        <url>
            <news:news>...</news:news>
        </url>
    </urlset>

    - It doesn't matter where the namespace and its prefix gets defined, as long as it's in scope when used.

    /Chriztian

  • Shannon 148 posts 171 karma points
    Feb 12, 2011 @ 23:10
    Shannon
    0

     

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
    <!ENTITY nbsp "&#x00A0;"
    >

    ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon"
    xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes"
    xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath"
    xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions"
    xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings"
    xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
    xmlns:umbraco.contour="urn:umbraco.contour"

    exclude-result-prefixes="msxml news umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets umbraco.contour ">


    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />

    <xsl:param name="currentPage"/>

    <xsl:variable name="urlPrefix">
    <xsl:text>http://</xsl:text>
    <xsl:value-of select="umbraco.library:RequestServerVariables('HTTP_HOST')" />
    </xsl:variable>

    <!-- update this variable on how deep your site map should be -->
    <xsl:variable name="maxLevelForSitemap" select="100"/>
    <xsl:variable name="today" select="umbraco.library:CurrentDate()" />
    <xsl:variable name="later" select="umbraco.library:DateAdd($today, 'd', -20)" />

    <xsl:template match="/">
    <!-- change the mimetype for the current page to xml -->
    <xsl:value-of select="umbraco.library:ChangeContentType('text/xml')"/>

    <xsl:call-template name="drawNodes">
    <xsl:with-param name="parent" select="umbraco.library:GetXmlNodeById(1187)"/>
    </xsl:call-template>
    </xsl:template>

    <xsl:template name="drawNodes">
    <xsl:param name="parent"/>
    <xsl:if test="$parent/ancestor-or-self::*//BlogPost [@isDoc and umbraco.library:DateGreaterThanOrEqual(PostDate, $later)]">
    <xsl:for-each select="$parent/ancestor-or-self::* [@isDoc]/Blog [@isDoc]//BlogPost">

    <!-- If the document does not have a template, nothing is shown in the frontend anyway.
    So this is not proper content and should not be in the sitemap -->

    <xsl:if test="@template &gt; 0">
    <url>
    <loc>
    <xsl:value-of select="$urlPrefix" /><xsl:value-of select="umbraco.library:NiceUrl(@id)" />
    </loc>
    <news:news>
    <news:publication>
    <news:name>Njection</news:name>
    <news:language>en</news:language>
    </news:publication>
    <news:publication_date><xsl:value-of select="umbraco.library:FormatDateTime(@updateDate, 'yyyy-MM-ddTHH:mm:ss+00:00')" /></news:publication_date>
    <news:title><xsl:value-of select="pageTitle"/></news:title>
    <news:keywords>Lifestyle, Automotive, Technology, <xsl:value-of select="metaKeywords"/></news:keywords>
    </news:news>
    </url>
    </xsl:if>

    <xsl:if test="(count(./* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 0) or (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>
Please Sign in or register to post replies

Write your reply to:

Draft