Solved

Parameters in XML

Posted on 2002-06-13
4
282 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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 …
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 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