[xsl] Sorting and Paging in one pass with XSLT 2

Subject: [xsl] Sorting and Paging in one pass with XSLT 2
From: Kyle Himmerick <kyle@xxxxxxxxxxxx>
Date: Thu, 18 Nov 2004 20:25:35 -0700
Hello All,

I am trying to use some of the new XSLT 2 functionality to improve my sorting and paging performance.

Ideally I would be able to sort and splice a large document tree in one pass.

So sort the tree and put x # of records in each result document.

Here's a pseudo of what I'm trying to do:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xmlns:fo="http://www.w3.org/1999/XSL/Format";>
<xsl:param name="perPage" select="number('10')"/>


<xsl:template match="result">
<xsl:for-each select="row">
<xsl:sort select="lname"/>
<xsl:sort select="fname"/>
<xsl:variable name="page" select="ceiling(position()/$perPage)"/>
<xsl:result-document href="out{$page}.xml">
<result>
<xsl:copy-of select="."/>
</result>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


Obviously this won't work as it would try create a new result-document on each pass. Whereas I need the first $perPage rows to go into the same result-document.

I was hoping to find a way to use the grouping functionality in xslt 2. Possibly grouping records by their page and then iterate through creating a new result-document for each group of records. I couldn't find a way to do this with one pass through the document, which is what I'm trying to stick with since I can potentially have very large incoming xml.

Any ideas or suggestions for implementing an efficient method of sorting and then paging the results?

Best Regards,
Kyle

Current Thread