[xsl] Performance degraded with grouping and sorting.

Subject: [xsl] Performance degraded with grouping and sorting.
From: Bhupendra Singh <skbhupendra@xxxxxxxxxxx>
Date: Wed, 27 Oct 2004 16:04:25 +0100 (BST)
Hi,
I have an XML something like this.

<PROJECTIONS>
   <PROJECTION>
      <ACCT_NBR>Q47807005</ACCT_NBR>
      <SYSTEM_NAME>OMN</SYSTEM_NAME>
      <ACCT_TITLE_SHORT>XYZ</ACCT_TITLE_SHORT>
      <CURRENCY_TYPE/>
      <PRINCIPAL_BASE/>
      <INCOME_BASE/>
      <TRAN_INC_LOCAL/>
      <TRAN_PRIN_LOCAL/>
      <SECURITY_NBR/>
      <DATE_VALUE>10/12/2004</DATE_VALUE>
      <SPN>5602831</SPN>
      <ACCT_KEY/>
      <COPY_TYPE>2A</COPY_TYPE>
      <BAL_PRIN_PROJECT>176.94</BAL_PRIN_PROJECT>
      <BAL_INC_PROJECT>0</BAL_INC_PROJECT>
      <SEC_ACCT_KEY/>
      <ID_CAS>0128124708</ID_CAS>
      <INDICATOR_HERITAGE>M</INDICATOR_HERITAGE>
      <STATUS/>
      <REASON_STRING/>
   </PROJECTION>
   ....
   ....
</PROJECTIONS>

The size of my XML is about 2 MB or I have abt 2000
Projection nodes in the XML.

I am using an XSLT to change this to an HTML table.
The data has to be sorted and displayed. The sorting
can be done on either ACCT_NBR, SPN or ID_CAS based
upon the users input. I pass this sortkey using the
<xsl:param>

I first did a simple sort based upon the input
paramter. The total time to make HTML table was around
5 secs. But then I found that simple sorting was not
correctly displaying the data correctly and I had to
group the data based upon ACCT_NBR.

After the grouping the total time taken was 45 secs.
which I think is too much. 
Can anyone please let me know what wrong have I done.
I have used the proess described in Jeni Tennisons
grouping process at:
http://www.jenitennison.com/xslt/grouping/index.html


Here is my XSL :
<?xml version="1.0" ?> 
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="html" omit-xml-declaration="yes"/>

  
<xsl:param name="paramSortKey" select="'ACCT_NBR'"/>
<xsl:param name="paramRadChecked"
select="'radCashEq'"/>


<xsl:template match="/">
	<xsl:apply-templates/>
</xsl:template>

<xsl:key name="group-by-accountnbr" match="PROJECTION"
use="ACCT_NBR" />


<xsl:template match="PROJECTIONS">
   	<xsl:for-each select="PROJECTION[count(. |
key('group-by-accountnbr', ACCT_NBR)[1]) = 1]">
	   	<xsl:sort select="*[name()=$paramSortKey]"
data-type = "text" order = "ascending"/>
		<xsl:sort select="ACCT_NBR" data-type = "text" order
= "ascending"/>
		<xsl:for-each select="key('group-by-accountnbr',
ACCT_NBR)">		
			<xsl:sort select="concat(substring(DATE_VALUE,
7,4), substring(DATE_VALUE, 1,2),
substring(DATE_VALUE, 4,2))" order="ascending" />
			<xsl:sort select="COPY_TYPE" data-type = "text"
order = "ascending"/>
			<xsl:variable name="copyType" select="COPY_TYPE"/>
			<xsl:variable name="dateValue"
select="concat(substring(DATE_VALUE, 7,4),
substring(DATE_VALUE, 1,2), substring(DATE_VALUE,
4,2))"/>
			<xsl:choose>
				<xsl:when test="$paramRadChecked='radProjection'">
	      			<xsl:if test="$copyType &lt; '3'">
						<xsl:apply-templates select="."
mode="projection" > 
			    	    	<xsl:with-param name = "copyType" 
select="$copyType"/>
			        		<xsl:with-param name = "dateValue"
select="$dateValue"/>  
						</xsl:apply-templates>
					</xsl:if>
				</xsl:when>
				<xsl:when test="$paramRadChecked='radSummary'">
	      			<xsl:if test="$copyType=1">
						<xsl:apply-templates select="."
mode="projection" > 
			    	    	<xsl:with-param name = "copyType" 
select="$copyType"/>
			        		<xsl:with-param name = "dateValue"
select="$dateValue"/>  
						</xsl:apply-templates>
					</xsl:if>			
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates select="." mode="projection"
> 
		    	    	<xsl:with-param name = "copyType" 
select="$copyType"/>
		        		<xsl:with-param name = "dateValue"
select="$dateValue"/> 
					</xsl:apply-templates>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:for-each>
</xsl:template>

<xsl:template match="node() | @*" mode="projection">
	<xsl:param name = "copyType" />
	<xsl:param name = "dateValue" />
.........
.........
........
.......
..........
........
</xsl:stylesheet>


regards,
Bhupi.



	
	
		
___________________________________________________________ALL-NEW Yahoo! Messenger - all new features - even more fun!  http://uk.messenger.yahoo.com

Current Thread