8,906
社区成员
发帖
与我相关
我的任务
分享
var root = xml.createElement("root");
var node = xml.createElement("p1");
node.text = "11111111";
root.appendChild(node);
xsl = loadXMLDoc(params.xslDocURL);
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
xsltProcessor.setParameter(null,"paramVal1", root);
//alert(xsltProcessor.getParameter(null, "paramVal1"));
//resultDocument = xsltProcessor.transformToDocument(xml);
resultDocument = xsltProcessor.transformToFragment(xml, document);
var xslt = new ActiveXObject("Msxml2.XSLTemplate.4.0");
var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
var xslProc;
xslDoc.async = false;
xslDoc.resolveExternals = false;
xslDoc.load("c:\\a.xsl");
xslt.stylesheet = xslDoc;
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
xmlDoc.async = false;
xmlDoc.resolveExternals = false;
xmlDoc.load("c:\\a.xml");
if (xmlDoc.parseError.errorCode != 0) {
var myErr = xmlDoc.parseError;
alert("You have error " + myErr.reason);
} else {
var root = xmlDoc.createElement("root");
var node = xmlDoc.createElement("p1");
node.text = "111111";
root.appendChild(node)
xslProc = xslt.createProcessor();
xslProc.input = xmlDoc;
xslProc.addParameter("paramVal", root);
xslProc.transform();
alert(xslProc.output);
}
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ms="urn:schemas-microsoft-com:xslt">
<xsl:output method="html"/>
<xsl:param name="paramVal"/>
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="$paramVal//p1"/>
<h2>My CD Collection</h2>
</body>
</html>
</xsl:template>
<xsl:template match="cd">
<p>
<xsl:apply-templates select="title"/>
<xsl:apply-templates select="artist"/>
</p>
</xsl:template>
<xsl:template match="title">
Title: <span style="color:#ff0000">
<xsl:value-of select="."/>
</span>
<br/>
</xsl:template>
<xsl:template match="artist">
Artist: <span style="color:#00ff00">
<xsl:value-of select="."/>
</span>
<br/>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy? -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:param name="paramVal"/>
<html>
<body>
<h2>My CD Collection</h2>
<xsl:value-of select="$paramVal/p1">
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="cd">
<p>
<xsl:apply-templates select="title"/>
<xsl:apply-templates select="artist"/>
</p>
</xsl:template>
<xsl:template match="title">
Title: <span style="color:#ff0000">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
<xsl:template match="artist">
Artist: <span style="color:#00ff00">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
</xsl:stylesheet>