Wrox Programmer Forums
|
BOOK: Beginning XSLT and XPath : Transforming XML Documents and Data
This is the forum to discuss the Wrox book Beginning XSLT and XPath : Transforming XML Documents and Data by Ian Williams ISBN: 978-0-470-47725-0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning XSLT and XPath : Transforming XML Documents and Data section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 25th, 2012, 12:27 AM
Registered User
 
Join Date: Jan 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pagination using xsl, xml and javascript

Hi Stanev,
I created the files as suggested in your post and tried to execute it. But I am getting the following error.
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; MS-RTC LM 8)
Timestamp: Wed, 25 Apr 2012 04:14:04 UTC

Message: Number parameter expected.
.*<--
Line: 33
Char: 5
Code: 0
URI: file:///C:/Test/driver.html


The xml file is mylist.xml
===============================
<list>
<item>
<element1>item 1 - element 1</element1>
<element2>item 1 - element 2</element2>
</item>
<item>
<element1>item 2 - element 1</element1>
<element2>item 2 - element 2</element2>
</item>
<item>
<element1>item 3 - element 1</element1>
<element2>item 3 - element 2</element2>
</item>
<item>
<element1>item 4 - element 1</element1>
<element2>item 4 - element 2</element2>
</item>
<item>
<element1>item 5 - element 1</element1>
<element2>item 5 - element 2</element2>
</item>
<item>
<element1>item 6 - element 1</element1>
<element2>item 6 - element 2</element2>
</item>
<item>
<element1>item 7 - element 1</element1>
<element2>item 7 - element 2</element2>
</item>
<item>
<element1>item 8 - element 1</element1>
<element2>item 8 - element 2</element2>
</item>
<item>
<element1>item 9 - element 1</element1>
<element2>item 9 - element 2</element2>
</item>
<item>
<element1>item 10 - element 1</element1>
<element2>item 10 - element 2</element2>
</item>
</list>


XSLT file is mylist.xslt
===================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/xml-controller/xml-doc-name">
<xsl:variable name="xml-doc-name" select=".*"/>
<xsl:variable name="start" select="@start"/>
<xsl:variable name="limit" select="@limit"/>
<xsl:variable name="end" select="$start + $limit - 1"/>
<xsl:variable name="xml-doc" select="document($xml-doc-name)/list/item[position() >= $start and position() '&lt;= $end]"/>
<html>
<body>
<h2>dynamic XML+XSL example</h2>
<table>
<tr>
<td>
<xsl:if test="$start - $limit >= 1">
<a href="?start={$start - $limit}&amp;limit={$limit}">prev</a>
</xsl:if>
</td>
<td align="right">
<a href="?start={$end + 1} &amp;limit={$limit}">next</a>
</td>
</tr>
<tr bgcolor="#CCCCCC">
<th>Element 1</th>
<th>Element 2</th>
</tr>
<xsl:for-each select="$xml-doc">
<tr>
<td><xsl:value-of select="element1"/></td>
<td><xsl:value-of select="element1"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


html file is : driver.html
====================================
<html>
<head>
<title>Paging mechanism using XML+XSLT</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!-- get the URL upto the page name .pop.split("?")[0] >
url_root = this.document.location.href
alert("url_root is : " + url_root);
page_name = url_root.split("/").pop().split("?")[0];
url_root = url_root.substring(0, url_root.indexOf(page_name));
<!-- get URL argements, have defaults if arguments are missing >
var args=getURLArguments(document.location.href);
var start = args['start'] ? args['start'] : 1;
var limit = args['limit'] ? args['limit'] : 3;
<!-- build the XML controller >
xml_text = '<?xml version="1.0"?>';
xml_text += '<xml-controller>';
xml_text += ' <xml-doc-name start="' + start + '" limit="' + limit + '">' + url_root + 'c:/Test/mylist.xml</xml-doc-name>';
xml_text += '</xml-controller>';
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async=false;
xml.loadXML(xml_text);
<!-- load the XSL >
var xsl = new ActiveXObject("Microsoft.XMLDOM");
xsl.async = false;
xsl.load("c:/Test/mylist.xsl");

<!-- XSL transform >
document.write(xml.transformNode(xsl));

<!-- return a map of URL's arguments >
function getURLArguments(url) {
alert("URL is :" +url);
var args = {};
query_str = url.substring(url.indexOf('?') + 1);
var args_arr = query_str.split('&');
for(var i = 0; i < args_arr.length; i++) {
var arg_arr = args_arr[i].split('=');
args[arg_arr[0]] = unescape(arg_arr[1]);
}
return args;
}
</script>
</body>
</html>
Regards
Suprakash





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL: How to get javascript function return SELECT value in xsl ojoker XSLT 5 May 24th, 2011 11:52 AM
Converting Source Xml into Target Xml Using XSL. alapati.sasi XSLT 3 May 14th, 2007 10:54 AM
how to use javascript in pagination vijayanmsc XSLT 5 June 8th, 2006 07:22 AM
how to use pagination in xsl or xlst vijayanmsc XSLT 1 June 6th, 2006 06:07 AM
xml and xsl templates as input to xslt gives xml rameshnarayan XSLT 5 August 3rd, 2005 01:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.