[xsl] sorting before selecting by position

Subject: [xsl] sorting before selecting by position
From: "Russ Holmes" <russ1@xxxxxxxxxx>
Date: Mon, 20 Aug 2001 19:19:19 +1200
Given XML;

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl"
href="C:\WebView\Root\WebView\Locations.xsl"?>
<xml>
	<rs>
		<z loc="NY" ldesc="New York Office" locno="1"/>
		<z loc="VAN" locdesc="Vancouver Office" locno="2"/>
		<z loc="LON" locdesc="London Office" locno="3"/>
		<z loc="DC" locdesc="Washington DC" locno="4"/>
		<z loc="QUE" locdesc="Quebec" locno="5"/>
		<z loc="CHI" locdesc="Chicago" locno="6"/>
		<z loc="KY" locdesc="Kentucky Office" locno="7"/>
		<z loc="LA" locdesc="Los Angeles County Office" locno="8"/>
		<z loc="TOR" locdesc="Toronto" locno="9"/>
		<z loc="MON" locdesc="Montreal" locno="10"/>
		<z loc="PAR" locdesc="Paris" locno="11"/>
		<z loc="SDY" locdesc="Sydney Office" locno="12"/>
		<z loc="MDR" locdesc="Marina del Rey" locno="13"/>
		<z loc="BUF" locdesc="Buffalo, NY" locno="14"/>
		<z loc="POR" locdesc="Portland Oregon Office" locno="15"/>
		<z loc="SF" locdesc="San Francisco" locno="16"/>
	</rs>
</xml>

I would like to sort according to attribute "loc" and then output rows with
position greater than 14 AFTER the sort ie

..
<z loc="TOR" locdesc="Toronto" locno="9" />
<z loc="VAN" locdesc="Vancouver Office" locno="2" />
..

I have tried XSL;

<?xml version="1.0"?>
<xsl:stylesheet version="1.0">

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

	<xsl:template match="text()|@*">
		<xsl:value-of select="."/>
	</xsl:template>

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

	<xsl:template match="//rs">
		<rs>
			<xsl:apply-templates select="z[position() &gt; 14]">
			<xsl:sort select="@loc" data-type="text" order="ascending"/>
			</xsl:apply-templates>
		</rs>
	</xsl:template>

	<xsl:template match="//z">
		<z>
			<xsl:for-each select="@*">
				<xsl:copy>
					<xsl:apply-templates select="@* |  text()"/>
				</xsl:copy>
			</xsl:for-each>
		</z>

	</xsl:template>

</xsl:stylesheet>

but this results in;
...
<z loc="POR" locdesc="Portland Oregon Office" locno="15" />
<z loc="SF" locdesc="San Francisco" locno="16" />
..

as the position criteria is performed before the sorting..

How can I sort, then select according to a criteria?

This will eventually be part of a table based on Data islands using client
side paging and sorting.

Thanks for any help

Russ Holmes






 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread