This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: passing parameter via asp
- From: "Agnes kielen" <a dot kielen at home dot nl>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Thu, 21 Feb 2002 19:29:43 +0100
- Subject: Re: [xsl] passing parameter via asp
- References: <F251WpSWerOc0Ne0PaL00004d73@hotmail.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hello Kit,
I'm not using asp, but do the transformation on the client-side. Anyway
maybe I can help. I solved the same kind of problem entirely with
javascript.
function getParameters () {
var i= 0; //iterator
var field = null; //fieldname
var value = null; //fieldvalue
var pair = null; //pair name-value
var pairs = null; // array with pairs
var form= null; //form object
var length=null; //number of elements at the form
form = document.forms[0];
length = form.elements.length;
pairs = new Array((length-1));
// -1 because last form element is a button
for (i=0; i<(length-1); i++){
field = form.elements[i].name;
value = form.elements[i].value;
pair = new Array(2);
pair[0] = field;
pair[1] = value;
pairs[i] = pair;
pair = null;
}
return pairs;
}
This code retrieves all values from a form and sets it in an array of pairs.
Each pair contains one field name and one value. I added the values to the
xsl with the help of the code I send you earlier.
function doTransform (xmlDom, xslDom, pairs, skip){
var template = new ActiveXObject ("MSXML2.XSLTemplate");
template.stylesheet=xslDom;
var processor=template.createProcessor();
processor.input=xmlDom;
//add Parameters first skip and then search parameters
processor.addParameter("skipnr", skip);
if (pairs != ''){
var length = pairs.length;
//alert ("length of pairs is: " + length);
for (var i=0; i<length; i++) {
var pair = pairs[i];
if (pair[1] != ''){
//alert ("Fieldname of pair" + i + " is: " + pair[0] + ", value is: " +
pair[1]);
processor.addParameter(pair[0], pair[1]);
}
pair = '';
}
}
As you can see the parameters are added to the processor just before the
transformation is done.
If you want more code or explanation. Please let me know, but not on this
list, because it is not really the topic of this list.
Good luck,
Agnes
----- Original Message -----
From: "林 子芯" <minikittygo@hotmail.com>
To: <xsl-list@lists.mulberrytech.com>
Sent: Thursday, February 21, 2002 6:08 PM
Subject: [xsl] passing parameter via asp
> Hi, i guess this is a question asked by millions of people already,
> however, i couldn't find the right one for my problem. how do a pass a
> parameter set by the end-user (via the form element in HTML) to a xsl
> stylesheet and return the transformed result to the user.
>
> i.e.
> 1. user enter values in the HTML form and sents it to an asp page
> 2. the asp uses the information recieve and converted into a string
> 3. pass parameter to the xsl
> 4. perform the transformation to an HTML file (where the xml file is in
the
> server)
> 5. return the HTML to the user
>
> to do so, do i have to perform task 2-5 (or write all the code) within the
> same asp pages? can somebody give me a slight hint how it should be done?
> please tell me is that how i should approach this problem? if not please
> tell me know how it should be treated.
>
> Thanks for your time
>
> Regards
> Kit
>
>
>
> _________________________________________________________________
> 在 http://explorer.msn.com.hk/intl.asp 免費下載 MSN Explorer。
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list