Solved

Parameters in XML

Posted on 2002-06-13
4
279 Views
Last Modified: 2008-02-20
Hi,
On a web page, I have a menu.  Each option call a xml file but I want to pass a parameter to know witch option is selected.  I can I do that.
Example : Option 1 call the XSLT with parameter "1"
          Option 2 call the XSLT with parameter "2"
          Etc.  
I know the instruction <xsl:param name='year'/>  but how the xslt will know the value of the parameter ?
Thank you very much
0
Comment
Question by:frdep
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
b1xml2 earned 50 total points
ID: 7075993
excellent question! this is how it is done with scripted transforms and MSXML3+

<html>
<head>
<title>Using the IXSLProcessor Object</title>
<script language="javascript">
//using MSXML3
var oXML = new ActiveXObject("Msxml2.DOMDocument.3.0");
var oXSLT = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.3.0");
var oTemplate = new ActiveXObject("Msxml2.XSLTemplate.3.0");
oXML.async = oXSLT.async = false;
oXML.load("data.xml");
oXSLT.load("data.xsl");

//assign the stylesheet to the IXSLTemplate stylesheet object

oTemplate.stylesheet = oXSLT;

//now you can remove the XSLT Tree to save resources
delete oXSLT; oXSLT = null; CollectGarbage();

//create the IXSLProcessor now
var oProc = oTemplate.createProcessor();
oProc.input = oXML;

//we are now ready to do the stuff
window.onload = init;
function init() {
 //perform transformation
 oProc.transform();
 //get the transformed stream
 document.all.data.innerHTML = oProc.output;
}

function setAndTransform(vtName,vtValue) {
 oProc.addParameter("" + vtName, "" + vtValue);
 oProc.transform();
 document.all.data.innerHTML = oProc.output;
}

</script>
</head>
<body>
<input type="radio" name="vendor" value="1"
 onclick="setAndTransform('year',this.value);">Microsoft<br>
<input type="radio" name="vendor" value="2"
 onclick="setAndTransform('year',this.value);">IBM<br>
<div id="data"></div>
</body>
</html>

Notes
=====
1. MSIE 5+ Only
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7076003
the addParameter of the IXSLProcessor allows you to pass external values to the parameter inside the XSLT seamlessly.

addParameter(<name>,<value>);
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
illegal characters in XML using UTF-8 8 37
use node.js to convert JavaScript JSON array to xml 2 102
selectSingleNode in Access 2013 11 53
VB.Net and XML XSD Files 1 53
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now