Solved

Parameters in XML

Posted on 2002-06-13
4
283 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

695 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