xsl-list
[Top] [All Lists]

[xsl] Passing parameters through javascript: what does or doesn't work

2006-04-24 16:31:31
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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>
  • [xsl] Passing parameters through javascript: what does or doesn't work, Davide Girlando <=