XSL sorting/filtering

admin

Administrator
Staff member
Hope someone in here can help me with this one, its got me stumped.

I have XML data for a CD collection and a stylesheet that I have setup to sort it as need be (i.e. by artist, by album name, etc). However, since the library is rather large I want the stylesheet to be able to accept parameters for a range of items to return (say the first 100, or the last 50, or whatever). How can I accomplish this in conjunction with my sorting?

Here is some sample XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<library>
<album>
<ID>1234</ID>
<Name><![CDATA[Paul's Boutique]]></Name>
<Artist><![CDATA[The Beastie Boys]]></Artist>
<Genre><![CDATA[Rap/Hip-Hop]]></Genre>
<Rating>8.5</Rating>

</album>

<album>
<ID>5678</ID>
<Name><![CDATA[Document]]></Name>
<Artist><![CDATA[R.E.M]]></Artist>
<Genre><![CDATA[Rock]]></Genre>
<Rating>7</Rating>

</album>

<album>
<ID>9988</ID>
<Name><![CDATA[Kind Of Blue]]></Name>
<Artist><![CDATA[Miles Davis]]></Artist>
<Genre><![CDATA[Jazz]]></Genre>
<Rating>8.9</Rating>

</album>

</library>


And my stylesheet (note the variables I have declared for start and end index):

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output encoding="utf-8" method="xml" indent="yes"/>

<xsl:param name="startIndex" select="0" />
<xsl:param name="endIndex" select="10" />

<xsl:template match="library">

<xsl:copy>
<xsl:apply-templates>
<xsl:sort data-type="text" select="Artist" order="ascending"/>
</xsl:apply-templates>
</xsl:copy>

</xsl:template>

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

</xsl:stylesheet>
 
Back
Top