On Joe Kesselman's advice (thanks Joe!) I've provided a test case in
case anyone can figure out what's taking up time/memory.

Thanks,
Martin

Data to sort:
<DataSet>
  <ResultSetMetaData>
    <ColumnMetaData dtype="number" name="Quantity">
    <ColumnMetaData dtype="text" name="Description">
  </ResultSetMetaData>

  <DataRow type="detail">
    <column name="Quantity">255.00</column>
    <column name="Description">IBM</column>
  </DataRow>

  <DataRow type="detail">
    <column name="Quantity">100.00</column>
    <column name="Description">Sun Microsystems</column>
  </DataRow>
</DataSet>

XSL used for sorting (attachment):




On Thu, 2003-03-20 at 21:17, Martin Dengler wrote:
> Hi,
> 
>    Please yell if this is an FAQ or my googling skills need help.
> 
>    What sorting algorithm does Xalan use -- and what is the algorithm(s)
> runtime and memory footprint in big-O notation?
> 
>    I am using Xalan to sort large XML documents: approx 3 levels deep of
> a tree with 2-20,000 first child (attached to root) nodes and 30
> grandchildren per child node.  Sorting is done on an attribute of the
> grandchild nodes.  The performance -- especially in memory usage -- is
> abysmal: 10-60 seconds sort time, memory usage is at least O(n^2).
> 
>    I've read the w3c performance pointers, but cutting the document down
> and doing fewer transforms really doesn't cut it (neither are applicable
> to a one-pass sort of a large document).
> 
>    Are there any ways to change the sort algortihm's memory/runtime
> behavior?
> 
> Thanks,
> Martin
> 
> PS -- test specs: Xerces, Xalan (latest), Solaris 2.8, JVM 1.2.2_07, Sun
> E450, 2GB real mem, 1GB JVM heap, 2x450mhz processors.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
                
<xsl:strip-space elements="DataSet ResultSet ResultSetMetaData DataRow column"/>

<xsl:output method="xml" />

<!-- The sort parameters along with sortorder for different levels -->
<xsl:param name="sortby0" />
<xsl:param name="sortorder0" />
<xsl:param name="sortby1" />
<xsl:param name="sortorder1" />
<xsl:param name="sortby2" />
<xsl:param name="sortorder2" />
<xsl:param name="sortby3" />
<xsl:param name="sortorder3" />
<xsl:param name="sortby4" />
<xsl:param name="sortorder4" />

<xsl:template match="DataSet">
    <!-- Copy top DataSet node to result -->
    <xsl:copy>
    
        <!-- Copying entire meta data section into result XML -->
        <xsl:copy-of select="ResultSetMetaData" />

        <!-- The datatype is obtained from the XML metadata sction for all the 
sort levels. If no sort column is specified
             for a sort level, the data type is defaulted to "text".-->
        <xsl:variable name="sortdatatype0">
            <xsl:choose>
                <xsl:when test="$sortby0='none'">
                    <xsl:text>text</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="//DataSet/ResultSetMetaData/[EMAIL 
PROTECTED]/@dtype" />
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="sortdatatype1">
            <xsl:choose>
                <xsl:when test="$sortby1='none'">
                    <xsl:text>text</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="//DataSet/ResultSetMetaData/[EMAIL 
PROTECTED]/@dtype" />
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="sortdatatype2">
            <xsl:choose>
                <xsl:when test="$sortby2='none'">
                    <xsl:text>text</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="//DataSet/ResultSetMetaData/[EMAIL 
PROTECTED]/@dtype" />
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="sortdatatype3">
            <xsl:choose>
                <xsl:when test="$sortby3='none'">
                    <xsl:text>text</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="//DataSet/ResultSetMetaData/[EMAIL 
PROTECTED]/@dtype" />
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="sortdatatype4">
            <xsl:choose>
                <xsl:when test="$sortby4='none'">
                    <xsl:text>text</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="//DataSet/ResultSetMetaData/[EMAIL 
PROTECTED]/@dtype" />
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <!-- Actual sorting of data rows -->            
        <xsl:for-each select="DataRow">
            <xsl:sort select="[EMAIL PROTECTED]" data-type="{$sortdatatype0}" 
order="{$sortorder0}" />
            <xsl:sort select="[EMAIL PROTECTED]" data-type="{$sortdatatype1}" 
order="{$sortorder1}" />
            <xsl:sort select="[EMAIL PROTECTED]" data-type="{$sortdatatype2}" 
order="{$sortorder2}" />
            <xsl:sort select="[EMAIL PROTECTED]" data-type="{$sortdatatype3}" 
order="{$sortorder3}" />
            <xsl:sort select="[EMAIL PROTECTED]" data-type="{$sortdatatype4}" 
order="{$sortorder4}" />
            <!-- Finally copy each DataRow node to output XML -->
            <xsl:copy-of select="." />
        </xsl:for-each>

    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to