I have an XML file that holds 100 records. I only want to display 10
at a
time. So I would display the first 10 and then provide links (11-20,
21-30,31-40,41-50, ...91-100) on the page. So lets say the user
clicks on
41-50 then I want to take them directly to those records. I have no
key
fields or any other fields that will hold the numbering in the XML
file.
Here's a client-side example of how to do it. I don't know if it's the
best way. Put things.xml, things.xsl, and things.html in the same folder
and open things.html in IE with MSXML4 installed.
things.xml
----------
<things>
<thing id="1"/>
<thing id="2"/>
<thing id="3"/>
<thing id="4"/>
<thing id="5"/>
<thing id="6"/>
<thing id="7"/>
<thing id="8"/>
<thing id="9"/>
<thing id="10"/>
<thing id="11"/>
<thing id="12"/>
<thing id="13"/>
<thing id="14"/>
<thing id="15"/>
<thing id="16"/>
<thing id="17"/>
<thing id="18"/>
<thing id="19"/>
<thing id="20"/>
</things>
things.xsl
----------
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" indent="yes"/>
<xsl:param name="startPosition" select="1"/>
<xsl:variable name="thingsPerPage" select="3"/>
<xsl:template match="/">
<xsl:apply-templates select="things/thing" mode="pagenumbers"/>
<br/><br/>
<xsl:apply-templates select="things/thing[position() >=
$startPosition and position() < ($startPosition + $thingsPerPage)]"/>
</xsl:template>
<xsl:template match="thing">
<xsl:value-of select="concat( name(), @id )"/><br/>
</xsl:template>
<xsl:template match="thing" mode="pagenumbers">
<xsl:for-each select="self::thing[(count(preceding-sibling::thing) + 1)
mod $thingsPerPage = 1]">
<xsl:variable name="pageNumber">
<xsl:value-of select="ceiling( (count(preceding-sibling::thing) + 1)
div $thingsPerPage )"/>
</xsl:variable>
<input type="button" value="{concat( 'page ', $pageNumber )}">
<xsl:attribute name="onclick">page( <xsl:value-of
select="($pageNumber - 1) * $thingsPerPage + 1"/> )</xsl:attribute>
</input>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
things.html (with msxml4 installed)
-----------------------------------
<html>
<head>
<script language="jscript">
function page( iStart ){
var xml = new ActiveXObject( 'msxml2.DOMDocument.4.0' );
xml.async = false;
xml.load( 'things.xml' );
var xsl = new ActiveXObject( 'msxml2.FreeThreadedDOMDocument.4.0' );
xsl.async = false;
xsl.load( 'things.xsl' );
var xslt = new ActiveXObject( 'msxml2.XSLTemplate.4.0' );
xslt.stylesheet = xsl;
var proc = xslt.createProcessor( );
proc.input = xml;
proc.addParameter( "startPosition", iStart );
proc.transform( );
document.getElementById('things').innerHTML = proc.output;
}
</script>
</head>
<body onload="page( 1 );">
<div id="things"> </div>
</body>
</html>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list