Copied to clipboard

Flag this post as spam?

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


  • Jules 276 posts 587 karma points
    Jun 25, 2011 @ 11:25
    Jules
    0

    Slow XSLT for Sitemap

    Hi

    I have the following docuemtn type structure

    master

        -homePage

        -textPage

            -aboutUs

            -admissions

            -contactUs

            -etc...

    I want to list all level1 nodes and all level2 nodes and have this working but it is horrible slow (2 seconds). Anyone know how to make this more efficient?

    Cheers

    J

    <?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"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


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

    <xsl:if test="$currentPage [@level = 1]">
    <xsl:for-each select="$currentPage/../* [@isDoc and @nodeName !='Error']">
    <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'] != '' or searchEngineSitemapChangeFreq != ''">
    <changefreq>
    <xsl:value-of select="./data [@alias='searchEngineSitemapChangeFreq'] | searchEngineSitemapChangeFreq" />
    </changefreq>
    </xsl:if>
    <xsl:if test="./data [@alias='searchEngineSitemapPriority'] != '' or searchEngineSitemapPriority != ''">
    <priority>
    <xsl:value-of select="./data [@alias='searchEngineSitemapPriority'] | searchEngineSitemapPriority" />
    </priority>
    </xsl:if>
    </url>
    </xsl:if>
    <xsl:for-each select="*">
    <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'] != '' or searchEngineSitemapChangeFreq != ''">
    <changefreq>
    <xsl:value-of select="./data [@alias='searchEngineSitemapChangeFreq'] | searchEngineSitemapChangeFreq" />
    </changefreq>
    </xsl:if>
    <xsl:if test="./data [@alias='searchEngineSitemapPriority'] != '' or searchEngineSitemapPriority != ''">
    <priority>
    <xsl:value-of select="./data [@alias='searchEngineSitemapPriority'] | searchEngineSitemapPriority" />
    </priority>
    </xsl:if>
    </url>
    </xsl:if>
    </xsl:for-each>

    </xsl:for-each>
    </xsl:if>
    </xsl:template>
    </xsl:stylesheet>
  • Rich Green 2246 posts 4008 karma points
    Jun 25, 2011 @ 11:33
    Rich Green
    1

    Hey,

    Haven't looked through the code, but obviously if you turn caching on the macro even for a few seconds it'll make a huge difference.

    Rich

  • Jules 276 posts 587 karma points
    Jun 25, 2011 @ 17:37
    Jules
    0

    Perfect

    Ta very much

    Julian

  • Laurence Gillian 600 posts 1219 karma points
    Jul 18, 2011 @ 18:23
    Laurence Gillian
    0

    I'm experiencing similar problem using the code below;

    However, I've tracked it down that when @updateDate (lastmod) is removed, performance is as would be expected. It seems that loading in either @updateDate or @createDate is causing huge performance issues.

    This ghastly situation makes no sense at all. My head hurts and I am confused. 

    Lau

    * also why format the date, when its in the correct format anyway?

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umb="urn:umbraco.library"
        exclude-result-prefixes="umb"
    >
    
        <xsl:output method="xml" omit-xml-declaration="yes" />
        <xsl:param name="currentPage" />
    
        <!-- Navigation Sitemap XML (for search engines), Laurie 18th July, 2011 -->
        <xsl:variable name="maxLevel" select="4"/>
        <xsl:variable name="urlPrefix">
            <xsl:text>http://</xsl:text>;
            <xsl:value-of select="umb:RequestServerVariables('HTTP_HOST')" />
        </xsl:variable>
    
        <xsl:template match="/">
            <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="umb:IsProtected($parent/@id, $parent/@path) = 0 or (umb:IsProtected($parent/@id, $parent/@path) = 1 and umb:IsLoggedOn() = 1) and @level &lt;= $maxLevel ">
                <xsl:for-each select="$parent/* [@isDoc and metaSitemap !='Hide Page,Hide Children' and metaSitemap !='Hide Page' and @level &lt;= $maxLevel]">
                <!-- If the document does not have a template, nothing is shown in the frontend anyway. -->
                    <xsl:if test="@template &gt; 0">
                        <url>
                            <loc>
                                <xsl:value-of select="$urlPrefix" />
                                <xsl:value-of select="umb:NiceUrl(@id)" />
                            </loc>
                            <lastmod>
                                <xsl:value-of select="@updateDate" />
                            </lastmod>
                            <xsl:if test="metaSitemapChangeFreq">
                                <changefreq><xsl:value-of select="metaSitemapChangeFreq" /></changefreq>
                            </xsl:if>
                            <xsl:if test="metaSitemapPriority">
                                <priority><xsl:value-of select="metaSitemapPriority" /></priority>
                            </xsl:if>
                        </url>
                    </xsl:if>
                    <xsl:if test="count(./* [@isDoc and parent::*/metaSitemap !='Hide Children' and parent::*/metaSitemap !='Hide Page,Hide Children' and @level &lt;= $maxLevel]) &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>
    
    <!-- Inspired by Cultiv's Brilliant Sitemap Package -->
    <!-- Reference - http://our.umbraco.org/projects/website-utilities/cultiv-search-engine-sitemap -->

     

  • Laurence Gillian 600 posts 1219 karma points
    Jul 18, 2011 @ 18:29
    Laurence Gillian
    0

    (this performance issue is only noticable on sites with say around 500 nodes)

    Avg. Time with @updateDate = 8 second, without 0.25 seconds.

    (I plan on refactoring the XSLT, and make it use match templates properly, which will improve performance too)

  • Petr Snobelt 923 posts 1535 karma points
    Jul 18, 2011 @ 19:12
    Petr Snobelt
    0

    I have same issue and find out it can be solved by using this chunk of code:

    <lastmod>
     <xsl:value-of select="@updateDate" />+00:00
    </lastmod>

    Note that all chunk can't be on one line.

    Petr

  • Laurence Gillian 600 posts 1219 karma points
    Jul 19, 2011 @ 12:06
    Laurence Gillian
    0

    Brilliant Petr, problem solved.

    Do you have any idea why this is happening, is the field being read as invalid by the XSLT processor? 

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jul 19, 2011 @ 12:39
    Sebastiaan Janssen
    0

    That makes no sense at al?! Weird....

    By the way, a better way to write that lastmode would be:

    <lastmod>
     <xsl:value-of select="@updateDate" />
    <xsl:text>+00:00</xsl:text>
    </lastmod>

    That way, the +00 won't drop down to the next line when you format the xslt in visual studio.

    The date won't always be formatted correctly when different locale's are used, so that's why I put in the formatting. Are you sure it's not the formatdatetime that has the perf issue?

  • Petr Snobelt 923 posts 1535 karma points
    Jul 19, 2011 @ 12:41
    Petr Snobelt
    0

    Hi Laurence, I have no idea why this is happening, I just find first workaround.

    I also want to know if it's caused by xslt processor or by umbraco, but I have not time to explore it more.

    P.

     

  • Laurence Gillian 600 posts 1219 karma points
    Jul 19, 2011 @ 12:45
    Laurence Gillian
    0

    It is very odd indeed! 

    I had orginally thought the issue was with the umbraco:format-date-time,

    umbraco:format-date - 8 seconds
    exslt:format-date - 8 seconds
    @updateDate - 8 seconds
    @update />+00:00 - 0.25 second

    Weird. 

  • Petr Snobelt 923 posts 1535 karma points
    Jul 19, 2011 @ 12:46
    Petr Snobelt
    0

    Hi Sebastiaan,

    In my case it is not caused by formating, because it is slow also if I put my code to one line.

  • Thijs Kuipers 43 posts 66 karma points
    Jul 25, 2011 @ 14:21
    Thijs Kuipers
    1

    Just want to chime in that I was having the exact same performance problem in my self-created XSLT file for Sitemaps. Petr Snobelts solution worked perfectly for me!

    I got time-outs on the sitemap, which I only found out after opening it on the server itself. Before 4.7 (I just upgraded this particular site from 4.0.4.2), everything was still OK, so I'm trying to find out what's going on here... Just downloaded the 4.7.0 source.

  • Laurence Gillian 600 posts 1219 karma points
    Jul 28, 2011 @ 11:36
    Laurence Gillian
    0

    Keep us posted on what you find, would be good to get to the bottom of this one (: 

  • John 27 posts 49 karma points
    Aug 03, 2011 @ 17:42
    John
    0

    I am experiencing the exact same issue as you Thijs, one site was v 4.0.3 to 4.7 and the other was 4.5 to 4.7 both have the same issue.

    I have done a little digging and found some strange issues

    this doesn't work:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
    <!ENTITY nbsp "&#x00A0;">
    <!ENTITY lower "'abcdefghijklmnopqrstuvwxyz'">
    <!ENTITY upper "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'">
    ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:b="http://www.babelwebservice.com/XSD/Babel"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"

    exclude-result-prefixes="msxml umbraco.library b">

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


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

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <xsl:value-of select="umbraco.library:ChangeContentType('text/xml')"/>
    <xsl:text disable-output-escaping="yes"><![CDATA[<?xml version="1.0" encoding="utf-8" ?>]]></xsl:text>
    <xsl:variable name="homeRoot" select="umbraco.library:GetXmlNodeById(1043)" />
    <xsl:variable name="domain">
    <xsl:text>http://www.site.com</xsl:text>;
    </xsl:variable>

    <xsl:variable name="pages" select="$homeRoot/node[@id=1127]/node[
    @nodeType='1114']"/>
    <xsl:for-each select="$pages">
    <url>
    <loc>
    <xsl:value-of select="$domain"/>
    <xsl:value-of select="umbraco.library:NiceUrl(./@id)"/>

    </loc>
    </url>

    </xsl:for-each>

    </xsl:template>

    </xsl:stylesheet>

    However the following will work

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
      <!ENTITY nbsp "&#x00A0;">
      <!ENTITY lower "'abcdefghijklmnopqrstuvwxyz'">
      <!ENTITY upper "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'">
    ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:b="http://www.babelwebservice.com/XSD/Babel"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:msxsl="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library"

      exclude-result-prefixes="msxml umbraco.library b">

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


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

      <xsl:param name="currentPage"/>

      <xsl:template match="/">
        <xsl:value-of select="umbraco.library:ChangeContentType('text/xml')"/>
        <xsl:text disable-output-escaping="yes"><![CDATA[<?xml version="1.0" encoding="utf-8" ?>]]></xsl:text>
        <xsl:variable name="homeRoot" select="umbraco.library:GetXmlNodeById(1043)" />
        <xsl:variable name="domain">
          <xsl:text>http://www.site.com</xsl:text>
        </xsl:variable>

        <xsl:variable name="pages" select="$homeRoot/node[@id=1127]/node[
                            @nodeType='1114']"/>
        <xsl:for-each select="$pages">
          <url>
            <loc>
              <xsl:value-of select="$domain"/>/         
                <xsl:value-of select="umbraco.library:NiceUrl(./@id)"/>
              
            </loc>
          </url>
          
        </xsl:for-each>

      </xsl:template>

    </xsl:stylesheet>

    Notice the extra forward slash on the line

    <xsl:value-of select="$domain"/>

    I happen to haver this issue with Umbraco support so will keep you posted to there solution.

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Sep 06, 2011 @ 17:48
    Tim
    1

    I've had this on a few sites recently, see post here: http://our.umbraco.org/forum/developers/xslt/23767-Sitemap-Macro-Running-Slow

    I've done a lot of digging, and it seems to be certain bits if the sitemap throw a wobble if they have a number or a date in them.

    For example, if you put @nodeName in the <lastmod> node, it renders super quick. Same for any other string based property. However, try it with @createDate, @updateDate or @level and it slows to a crawl. Casting the date to a string using string(@updateDate) doesn't fix it. However, outputting a literal string character after the node or url element (either a tab or a carriage return) seems to solve the issue. This is what Petr's solution does, albeit in the lastmod node. However, adding

    <xsl:text>
    </xsl:text>

    Underneath the closing </url> in the Macro seems to work too (and doesn't shove a huge gap after the date/time).

    It's odd that it works fine on some sites, but on others it falls over like this. We're currently investigating whether this is caused by an XSLT Extension or similar from a 3rd party datatype. The components that are on our affected sites that aren't on the ones that work are:

    • uComponents
    • Embedded Content
    • Google Analytics
    • DocType Extensions

    Can anyone else who is having this issue post a list of what extensions they're running?

Please Sign in or register to post replies

Write your reply to:

Draft