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

Passing parameters through javascript: what does or d

Subject: Passing parameters through javascript: what does or doesn't work
From: Davide Girlando <dado2_714@xxxxxxxx>
Date: Tue, 25 Apr 2006 01:31:11 +0200 (CEST)
javascript params
Hello everyone, I'm an XSLT novice and I tried out this technology to make a job for my apprentice
period in a firm, that is also my Bachelor Thesis. I'm using Javascript to pass parameters, with
some code I adapted from some research which uses ActiveX; I'm not so satisfied with this, but I'm
making it easy to eventually switch to PHP when everything will be transfered on a server.
Coming to the issue, I've written this code as a part of a template: it should provide links to a
dynamic item paging control.


>> fl.xsl

<xsl:param name="viewmethod" select="'js'"/>
<xsl:param name="itemsperpage" select="'50'"/>
<xsl:param name="page" select="'1'"/>
...
	<xsl:for-each select="/rdf:RDF/nm:flItem[(position() - 1) mod $itemsperpage = 0]">
		<xsl:call-template name="link">
			<xsl:with-param name="text">
				<xsl:value-of select="position()"/>
			</xsl:with-param>
			<xsl:with-param name="view">
				fl
			</xsl:with-param>
			<xsl:with-param name="param">
product=<xsl:value-of select="/rdf:RDF/nm:productName[1]"/>&amp;itemsperpage=<xsl:value-of
select="$itemsperpage"/>&amp;page=<xsl:value-of select="position()"/>
			</xsl:with-param>
		</xsl:call-template>
	</xsl:for-each>
...
<xsl:template name="link">
	<xsl:param name="text"/>
	<xsl:param name="view"/>
	<xsl:param name="param"/>
	<xsl:choose>
		<xsl:when test="$viewmethod = 'js'">
			<a>
				<xsl:attribute name="href">
javascript:match('<xsl:value-of select="$view"/>','<xsl:value-of select="$param"/>');
				</xsl:attribute>
				<xsl:value-of select="$text"/>
			</a>
		</xsl:when>
	</xsl:choose>
</xsl:template>


This is the javascript file that is automatically recalled by all the 
pages generated by the
template (with a <script> tag, omitted here):


>> nm.js

function match(view, param) {
	var params = param.split("&");
	var product;
	for (var i=0; i<params.length; i++) {
		if (params[i].split("=")[0]=="product") {
			product=params[i].split("=")[1];
			params.splice(i,1);
			i--;
		}
	}
	var xslt = new ActiveXObject("Msxml2.XSLTemplate");
	var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
	var xslProc;
	xslDoc.async = false;
	xslDoc.resolveExternals = false;
	xslDoc.load(view+".xsl");
    	xslt.stylesheet = xslDoc;
    	var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
    	xmlDoc.async = false;
    	xmlDoc.resolveExternals = false;
    	xmlDoc.load(product+".xml");
    	xslProc = xslt.createProcessor();
    	xslProc.input = xmlDoc;
	xslProc.addParameter("viewmethod","js");
	for (var i=0; i<params.length; i++) {
		xslProc.addParameter(params[i].split("=")[0],params[i].split("=")[1]);
	}
    	xslProc.transform();
    	document.write(xslProc.output);
}


Looks like the generated page ignores the parameters. I've verified that the function reads
correctly parameters names and values from the "param" string; I've also verified that typing
manually something like

	xslProc.addParameter("page","4");

unexpectedly works. This looks rally weird to me! Anybody has any idea what happens inside the IE
javascript interpreter?
Thanks

Davide Girlando


	

	
		
___________________________________ 
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB 
http://mail.yahoo.it

Current Thread

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.