Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending Parameter to XSLT file

Status
Not open for further replies.

xtremeLogic

Programmer
Dec 19, 2003
53
CA
Hi,

I have a xml file which I would like transformed into an html file. I have made a basic xslt file for the transformation. I would like the html file to have a dropdown of sort values which onclick would reload the html page in the correct sort.

I am quite new to xml so I would appreciate it if anyone can suggest how I can send a parameter (which would be my dropdown select value) back to the xslt file and cause it to reload the html page in the correct sort. Also, what modifications would I have to make to my xsl file to accomodate a parameterized order by.

Thanks.
 
I used this code to provide an HTML sort mechanism. In my XSL file, the sort is an xsl:if tag with test="booksearch". JavaScript changes this "booksearch" to "contains(title, \""+document.forms[0].book.value+"\")", which provides the XSL sort. Shouldn't be too much hassle to change it for your purposes.

Jon

<?xml version="1.0" encoding="utf-8"?>
<html>

<head>
<title>Find a Book</title>
<script language="JavaScript1.1">
function xslt() {
var XMLDocument = new ActiveXObject('MSXML2.DOMDocument.3.0');
var XSLDocument = new ActiveXObject('MSXML2.DOMDocument.3.0');
var HTMLtarget = document.all['targetDIV'];
XMLDocument.validateOnParse = true;
XMLDocument.load('SortedBooks.xml');
if (XMLDocument.parseError.errorCode != 0) {
HTMLtarget.innerHTML = 'Error';
return false;
}
XSLDocument.validateOnParse = true;
XSLDocument.load ('FindBook.xsl');
if (XSLDocument.parseError.errorCode != 0) {
HTMLtarget.innerHTML = 'Error';
return false;
}
var x = XSLDocument.getElementsByTagName("xsl:if")
for(i=0 ; i < x.length ; i++ ) {
if( x.item(i).getAttribute("test") == "booksearch" ) {
x.item(i).setAttribute("test", "contains(title, \""+document.forms[0].book.value+"\")");
}
}
HTMLtarget.innerHTML = XMLDocument.transformNode(XSLDocument);
return true;
}
</script>
</head>
<body>
<div id="targetDIV">
<form onsubmit="xslt()">
<p>
Please enter a book title to locate (case sensitive): <input type="text" size="40" name="book" /><input type="submit" value="Locate it!" />
</p>
</form>
</div>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top