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.
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.
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.
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.
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!
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):
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
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
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.
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).
/Chriztian
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!
is working on a reply...