我现在需要向XSL传递一个param,让后获取此param位置的数据
param 名为 pageNum
以下为代码:
javascript:
function loadDocument(fileName)
{
var xmlDoc = window.ActiveXObject ? new ActiveXObject("MSXML2.DOMDocument.3.0") :
document.implementation.createDocument("","",null);
xmlDoc.async = false;
xmlDoc.load(fileName);
return xmlDoc;
}
function getTransformedHTML(xmlDoc, xslDoc) {
var html = "";
if (window.XSLTProcessor)
{
var num = 1 ;
var xmlDom=new ActiveXObject('Msxml2.DOMDocument.3.0');
var docStyle = new ActiveXObject('MSXML2.FreeThreadedDOMDocument');
//var xsltProc = new XSLTProcessor();
//xsltProc.importStylesheet(xslDoc);
//xsltProc.addParameter("pageNum", num);
var docTemplate = new ActiveXObject("Msxml2.XSLTemplate");
docTemplate.stylesheet = docStyle;
var processor = docTemplate.createProcessor();
processor.input = xmlDom;
---------------------------------- 此处为问题关键处-----------------------
processor.addParameter("pageNum",num);
-------------------------------------------
processor.transform();
html = processor.output;
//var fragment = xsltProc.transfrmToDocument(xmlDoc);
//html = new XMLSerializer().serializeToString(fragment);
}
else if (window.ActiveXObject)
{
html = xmlDoc.transformNode(xslDoc);
}
return html;
}
function GenerateCart()
{
var xmlDoc = loadDocument("cart.xml");
var xslDoc = loadDocument("cart.xsl");
var content = getTransformedHTML(xmlDoc, xslDoc);
document.getElementById("cart").innerHTML = getTransformedHTML(xmlDoc, xslDoc);
alert(content);
}
function AddRemoveItem() {}
xsl:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
method="html"
indent="yes"
version="4.0"
doctype-public="-//W3C//DTD HTML 4.01//EN"
doctype-system="http://www.w3.org/TR/html4/strict.dtd"/>
<xsl:param name="pageNum">undefined</xsl:param>
<xsl:template match="/">
<table id="shoppingcart">
<xsl:call-template name="DisplayCart"></xsl:call-template>
</table>
</xsl:template>
<xsl:template name="DisplayCart">
<xsl:param name="pageNum"/>
<tr class="head">
<td colspan="4" align="center">Shopping Basket <img src="sbasket.gif"></img>
</td>
</tr>
<xsl:if test="string($pageNum) = '' ">
<tr>
<td colspan="4" align="center">error