<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:param name="page-size" select="2"/>
	<xsl:output method="xml"/>
	<xsl:key name="zone" match="root/record" use="zone"/>

	<xsl:template match="/">
		<xsl:apply-templates/>
	</xsl:template>

	<xsl:template match="root">
		<xsl:copy>
			<xsl:for-each select="record[ generate-id() = generate-id( key('zone', zone)[1] )]">
				<xsl:sort select="zone" case-order="lower-first"/>
				<xsl:for-each select="key('zone', zone)">
					<xsl:copy>
						<xsl:copy-of select="@ID"/>
						<xsl:attribute name="zone">
							<xsl:value-of select="zone"/>
						</xsl:attribute>
					</xsl:copy>
					<xsl:variable name="zone" select="zone"/>
					<xsl:variable name="p" select="position()"/>
					<xsl:variable name="offset" select="count(key('zone', $zone)[position() &lt;= $p])"/>
					<xsl:variable name="position" select="count(../record[zone &lt; $zone]) + $offset"/>
					<xsl:if test="$position mod $page-size = 0">
						<break/>
					</xsl:if>
				</xsl:for-each>
			</xsl:for-each>
		</xsl:copy>
	</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="zone.xml" htmlbaseurl="" outputurl="" processortype="msxml4" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->