[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: XSL Question.

Subject: RE: XSL Question.
From: "Kevin Collins" <kcollins@xxxxxxx>
Date: Thu, 10 Apr 2003 15:32:44 -0400
xsl template 4.0
> 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() &gt;=
$startPosition and position() &lt; ($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


Current Thread
  • XSL Question.
    • Patel, Viral - Thu, 10 Apr 2003 12:16:43 -0400 (EDT)
      • <Possible follow-ups>
      • Kevin Collins - Thu, 10 Apr 2003 15:30:41 -0400 (EDT) <=

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.