Код:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtm...sitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>book info</title>
</head>
<body>
<table width="100%" border="1">
<tr>
<td onclick="loadXML('01')">book 1</td>
<td onclick="loadXML('02')">book 2</td>
</tr>
</table>
<div id="example"></div>
<script type="text/javascript">
function loadXML(id)
{
var isIE;
var isOpera;
var isNav;
isIE = (navigator.appName == "Microsoft Internet Explorer");
isNav = (navigator.appName == "Netscape");
isOpera = (navigator.appName == "Opera");
if (isIE)
{// Load your XSL
var objXSLT = new ActiveXObject("MSXML2.FreeThreadedDomDocument")
objXSLT.async = false
objXSLT.load("stats.xsl")
// create a compiled XSL-object
var objCompiled = new ActiveXObject("MSXML2.XSLTemplate")
objCompiled.stylesheet = objXSLT.documentElement
// create XSL-processor
var objXSLProc = objCompiled.createProcessor()
// Load your XML
var objXML = new ActiveXObject("MSXML2.FreeThreadedDomDocument")
objXML.async = false
objXML.load("stats.xml")
// input for XSL-processor
objXSLProc.input = objXML
objXSLProc.addParameter("book_id", id)
// etc.
// transform
objXSLProc.transform()
// display
document.getElementById('example').innerHTML=objXSLProc.output;
}
if (isNav)
{//for mozilla/netscape
var xslStylesheet;
var xsltProcessor = new XSLTProcessor();
// load the xslt file, example1.xsl
var myXMLHTTPRequest = new XMLHttpRequest();
myXMLHTTPRequest.open("GET", "stats.xsl", false);
myXMLHTTPRequest.send(null);
// get the XML document and import it
xslStylesheet = myXMLHTTPRequest.responseXML;
xsltProcessor.importStylesheet(xslStylesheet);
// load the xml file, example1.xml
myXMLHTTPRequest = new XMLHttpRequest();
myXMLHTTPRequest.open("GET", "stats.xml", false);
myXMLHTTPRequest.send(null);
var xmlSource = myXMLHTTPRequest.responseXML;
xsltProcessor.setParameter(null,"book_id",id);
var resultDocument = xsltProcessor.transformToFragment(xmlSource, document);
document.getElementById('example').innerHTML="";
document.getElementById('example').appendChild(resultDocument);
}
}
</script>
</body>
</html>
Ето това е цялата борба. Отваря ги в същия файл, за момента реших че ще е по-удобно...иначе в xsl файла имаш параметър book_id, който го използваш като:
Код:
<xsl:for-each select="book[@id=$book_id]">