Passing dynamic parameters to an XSLT document in real-time with a Javascript HTML combination
The Entire Solution
XSLT: In the XSLT file you will need to specify the names of the parameters that will be passed in. For this example, the user can select a maximum of five fruits, so I have to ensure that my XSLT document accepts at least 5 parameters.
See Figure 1
Figure 1: XSLT Parameters
JavaScript: The JavaScript will instantiate the XSLT processor and set the parameters so think about what needs to be passed into this function. For this case I will need to pass in the URL to the XML document, XSL Document, the ID of the DIV I want to update, and the List of Fruits selected.
The way it works is that the processor will be created, the parameters will be set (i.e. the fruits), the transformation will take place and a DIV element on the page will be set to the output of the transformation.
The part that you're probably interested in is the addParameter for IE and the setParameter for Mozilla browsers. In this case the script will loop through the fruitList which is an array and set the parameters in the XSLT document accordingly.
When the transformation is done you can see that the content for the divID you pass in will be set to the transformation output. See Figure 2. You can download the script here.
Figure 2: XSLT Processor in JavaScript
Figure 2: XSLT Processor in JavaScript (continued)