FreeThreadedDOMDocument、XSLTemplate的使用

pt Syntax

var objXSLProcessor = objXSLTemplate.createProcessor();

Example

var xslt = new ActiveXObject("Msxml2.XSLTemplate.4.0");
var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
var xslProc;
xslDoc.async = false;
xslDoc.load("sample.xsl");
xslt.stylesheet = xslDoc;
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
xmlDoc.async = false;
xmlDoc.load("books.xml");
xslProc = xslt.createProcessor();
xslProc.input = xmlDoc;
xslProc.addParameter("param1", "Hello");
xslProc.transform();
alert(xslProc.output);

File Name: Sample.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   <xsl:output method="html"/>
   <xsl:param name="param1"/>
  <xsl:template match="/">
      The parameter value was: <xsl:value-of select="$param1"/>
  </xsl:template>
</xsl:stylesheet>

 

 

Js代码   收藏代码
  1. function loaderXml(xmlSrc,xslsrc,params){  
  2.     var xmlDoc=new ActiveXObject("Msxml2.DOMDocument.4.0");  
  3.     xmlDoc.async=false;  
  4.     xmlDoc.load(xmlSrc);  
  5.   
  6.     var xslDoc=new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");  
  7.     xslDoc.async = false;  
  8.     xslDoc.load(xslsrc);  
  9.   
  10.     var xslt = new ActiveXObject("Msxml2.XSLTemplate.4.0");  
  11.     xslt.stylesheet = xslDoc;  
  12.   
  13.     var xslProc = xslt.createProcessor();  
  14.     xslProc.input = xmlDoc;  
  15.     if(params){  
  16.         $.each(params,function(name,val){  
  17.             xslProc.addParameter(name, val);  
  18.         });  
  19.     }  
  20.     xslProc.transform();  
  21.     return xslProc.output;  


你可能感兴趣的:(FreeThreadedDOMDocument、XSLTemplate的使用)