Copied to clipboard

Flag this post as spam?

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


  • Harm-Jan Abbing 62 posts 102 karma points
    Oct 05, 2012 @ 16:47
    Harm-Jan Abbing
    0

    Slow node selection with large amount of nodes

    Hi guys,

    I have a problem with some basic xslt selecting and combining a lot of nodes.

    This is the basic code (old schema):

    <xsl:variable name="organisations" select="umbraco.library:GetXmlNodeById(15335)/node [@nodeTypeAlias = 'organisation']" />
    <xsl:variable name="employees" select="umbraco.library:GetXmlNodeById(15336)/node [@nodeTypeAlias = 'employee']" />

    <xsl:for-each select="$employees">
    <xsl:variable name="emOrgId" select="data [@alias = 'organisationId']" />
    <xsl:variable name="itemOrg" select="$organisations [data [@alias = 'organisation_id'] = $itemOrgId]" />
    </xsl:for-each>

    Both variables contain 2000+ nodes and this proves to be extremely slow (30sec+). Is there anyway i can speed this up..? What i'm trying to do is combine organisation info with each employee.

    Using umbraco v 4.7.1

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Oct 05, 2012 @ 22:21
    Chriztian Steinmeier
    0

    Hi Harm-Jan,

    There are a couple of things you can try - first of all it would be good to know what you're trying to do, e.g., do you "just" need to render something like "Name, Organisation" for all employees, or is it a bigger task? Would it be possible to run the transformation once, creating a better suited XML file (i.e., does the records change often?) where the organisation was embedded?

    It's hard to say exactly what will improve the processing time (other than sheer the amount of nodes) without knowing a little more about what's being done.

    /Chriztian

  • Harm-Jan Abbing 62 posts 102 karma points
    Oct 06, 2012 @ 15:11
    Harm-Jan Abbing
    0

    Hey Chriztian,

    It's two separate node collections that get updated with an import every night. Maybe creating a combined XML is the best way but how could i do this?
    I list the employees with a couple fields like name and id and their organisation info like address.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Oct 06, 2012 @ 22:12
    Chriztian Steinmeier
    1

    Hi Harm-Jan,

    It'd be interesting to see what kind of results you get using keys to index the data - here's a sample of a very simple way to use them for indexing and subsequently performing the lookup - note that it does both ways to show the data (list employees looking up their organisation, and listing organisations and finding their employees).

    <xsl:variable name="organisations" select="/root/*/node[@id = 15335]/node[@nodeTypeAlias = 'organisation']" />
    <xsl:variable name="employees" select="/root/*/node[@id = 15336]/node[@nodeTypeAlias = 'employee']" />
    
    <!-- Index organisations by their id -->
    <xsl:key name="organisation-by-id" match="node" use="data[@alias = 'organisation_id']" />
    
    <!-- Index employees by their organisation -->
    <xsl:key name="employee-by-organisation" match="node" use="data[@alias = 'organisationId']" />
    
    <xsl:template match="/">
        <!-- Show Employees -->
        <xsl:apply-templates select="$employees">
            <xsl:sort select="@nodeName" data-type="text" order="ascending" />
        </xsl:apply-templates>
    
        <hr />
    
        <!-- Show Organisations -->
        <xsl:apply-templates select="$organisations">
            <xsl:sort select="@nodeName" data-type="text" order="ascending" />
        </xsl:apply-templates>        
    </xsl:template>
    
    <!-- Employee template -->
    <xsl:template match="node[@nodeTypeAlias = 'employee']">
        <p>
            <!-- Name of employee -->
            <xsl:value-of select="@nodeName" />,
    
            <!-- Name of associated organisation -->
            <xsl:value-of select="key('organisation-by-id', data[@alias = 'organisationId'])/@nodeName" />
        </p>
    </xsl:template>
    
    <!-- Organisation template -->
    <xsl:template match="node[@nodeTypeAlias = 'organisation']">
        <!-- Name of organisation -->
        <h2><xsl:value-of select="@nodeName" /></h2>
        <ul>
            <!-- List all employees associated -->
            <xsl:for-each select="key('employee-by-organisation', data[@alias = 'organisation_id'])">
                <li><xsl:value-of select="@nodeName" /></li>
            </xsl:for-each>
        </ul> 
    </xsl:template>
    
    This same technique could later be used to generate a combined XML file with everything sorted and nested as needed for your output.
     

    /Chriztian

  • Harm-Jan Abbing 62 posts 102 karma points
    Oct 08, 2012 @ 10:41
    Harm-Jan Abbing
    0

    Using keys the way you said brought page response back to normal.
    I've been working with xslt for a couple of years now but never used keys, i guess i should!

    This helped me out a lot, thanks Chriztian!

Please Sign in or register to post replies

Write your reply to:

Draft