Copied to clipboard

Flag this post as spam?

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


  • Eric Boen 40 posts 64 karma points
    Jul 05, 2010 @ 02:02
    Eric Boen
    1

    Getting to work in v4.5

    Since there are changes in 4.5 xsl engine the 1.0.1 version does not work.  I had to make 2 changes.

    1st: I had to change the xslt ended up lookin like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <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" 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:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary ">
    <xsl:output method="xml" 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="8"/>
    <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="$currentPage/ancestor-or-self::node [@level=1]"/>-->
        <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@level=1 and @isDoc]"/>
      </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/* [@isDoc and string(./umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]">
       <!-- 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>
          <lastmod><xsl:value-of select="umbraco.library:FormatDateTime(@updateDate, 'yyyy-MM-ddThh:mm:ss+00:00')" /></lastmod>
          <xsl:if test="./data [@alias='searchEngineSitemapChangeFreq'] != ''">
            <changefreq><xsl:value-of select="./data [@alias='searchEngineSitemapChangeFreq']" /></changefreq>
          </xsl:if>
          <xsl:if test="./data [@alias='searchEngineSitemapPriority'] != ''">
            <priority><xsl:value-of select="./data [@alias='searchEngineSitemapPriority']" /></priority>
          </xsl:if>
          </url>
       </xsl:if>
       <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>

    2nd: A space is introduced at the top of the xml sitemap so it doesn't validate in browsers.  I ended up taking out all the line breaks in the CultivSearchEngineSitemap template so it would validate (the templates looks as if it is minified...all on one line).

    Thanks


    Eric

     

     

  • Sebastiaan Janssen 4850 posts 14395 karma points MVP admin hq
    Jul 09, 2010 @ 10:58
    Sebastiaan Janssen
    0

    Thanks Eric, I plan to look at it some time soon, this is a great starting point!

    The only whitespace you'd (unfortunately) have to remove is the one between the "asp:Content" opening tag and the "xml" tag, like so: 

    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server"><?xml version='1.0' encoding='UTF-8'?>

    Any other whitespace is fine, but this one is indeed essential. When you install the package, it already sets up the Template/masterpage correctly for you.

  • Hundebol 167 posts 314 karma points
    Aug 02, 2010 @ 19:35
    Hundebol
    0

    Hi Eric and Sebastian,

    Actually there is an error in Eric's code. The last if-test in his code is not updated for the new schema.

    I have updated the code, and added the possibillity of also getting the very top node in your site map. That is if your content is structured like this:

    CONTENT
    -- Homepage
    ----- Subpage
    -------- Sub-subpage
    ----- Subpage
    etc.

    Here's the code - cheers! Best regards, hundebol!

    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" 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:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary ">
    <xsl:output method="xml" 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>
        

    <xsl:variable name="maxLevelForSitemap" select="6"/>
    <xsl:variable name="url" select="concat('http://',umbraco.library:RequestServerVariables('HTTP_HOST'))" />
        
    <xsl:template match="/">
     
     <xsl:value-of select="umbraco.library:ChangeContentType('text/xml')"/>
     
      
                
                <url>
                    <loc>
                        <xsl:value-of select="concat($url,'/')"/>
                    loc>
                    <lastmod>
                        <xsl:value-of select="concat($currentPage/ancestor-or-self::* [@level=1]/@updateDate,'+00:00')" />
                    lastmod>
                url>
      
      
      
      <xsl:call-template name="drawNodes">  
        <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@level=1 and @isDoc]"/>
      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/* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevelForSitemap]">
       
       <xsl:if test="@template > 0">
          <url>
          <loc><xsl:value-of select="$urlPrefix" /><xsl:value-of select="umbraco.library:NiceUrl(@id)" />loc>
          <lastmod><xsl:value-of select="umbraco.library:FormatDateTime(@updateDate, 'yyyy-MM-ddThh:mm:ss+00:00')" />lastmod>
          <xsl:if test="./data [@alias='searchEngineSitemapChangeFreq'] != ''">
            <changefreq><xsl:value-of select="./data [@alias='searchEngineSitemapChangeFreq']" />changefreq>
          xsl:if>
          <xsl:if test="./data [@alias='searchEngineSitemapPriority'] != ''">
            <priority><xsl:value-of select="./data [@alias='searchEngineSitemapPriority']" />priority>
          xsl:if>
          url>
       xsl:if>
         
         <xsl:if test="count(./* [@isDoc and string(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>
  • Eric Boen 40 posts 64 karma points
    Aug 02, 2010 @ 19:51
    Eric Boen
    0

    @Hundebol...good catch, thanks!  I'll update my code...I didn't catch that.

    Thanks

    Eric

  • Sebastiaan Janssen 4850 posts 14395 karma points MVP admin hq
    Sep 12, 2010 @ 10:16
    Sebastiaan Janssen
    0

    A new version of the package is available that has support for both the legacy and new xml schema in the same xslt file. I recommend using that one.

Please Sign in or register to post replies

Write your reply to:

Draft