本文介绍了使用JavaScript的XSL参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个html页面,例如:

 < html> 
< head>
< script>
函数loadXMLDoc(dname)
{
if(window.XMLHttpRequest)
{
xhttp = new XMLHttpRequest();
}
else
{
xhttp = new ActiveXObject(Microsoft.XMLHTTP);
}
xhttp.open(GET,dname,false);
xhttp.send();
return xhttp.responseXML;
}

函数displayResult()
{
xml = loadXMLDoc(1.xml);
xsl = loadXMLDoc(2.xsl);
//代码为IE
if(window.ActiveXObject)
{
xml.addParameter(rss,test);
ex = xml.transformNode(xsl);
document.getElementById(example)。innerHTML = ex;
}
// Mozilla,Firefox,Opera等的代码
else if(document.implementation&&document.implementation.createDocument)
{
xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml,document);
document.getElementById(example)。appendChild(resultDocument);
}
}
< / script>
< / head>
< body onload =displayResult()>
< div id =example/>
< / body>
< / html>

现在我想将一个变量(javascript)传递给XSL,例如course_name在XSL中,我可以像使用它一样

 < xsl:param name =course_name/> 
< xsl:value-of select =$ course_name/>

任何帮助解决这个问题的方法都会受到高度赞赏。

  xsltProcessor。  setParameter(null,course_name,无论名字是什么); 

对于IE,您需要根据,但命令是:

  xslproc.addParameter(param1,Hello); 

...但由于您添加了xslt-2.0作为标签,您应该知道内置的浏览器支持XSLT只支持XSL 1.0。

ul>




  • I have a html page like:

    <html>
    <head>
    <script>
    function loadXMLDoc(dname)
    {
    if (window.XMLHttpRequest)
      {
      xhttp=new XMLHttpRequest();
      }
    else
      {
      xhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xhttp.open("GET",dname,false);
    xhttp.send("");
    return xhttp.responseXML;
    }
    
    function displayResult()
    {
    xml=loadXMLDoc("1.xml");
    xsl=loadXMLDoc("2.xsl");
    // code for IE
    if (window.ActiveXObject)
      {
      xml.addParameter("rss", test); 
      ex=xml.transformNode(xsl);
      document.getElementById("example").innerHTML=ex;
      }
    // code for Mozilla, Firefox, Opera, etc.
    else if (document.implementation && document.implementation.createDocument)
      {
      xsltProcessor=new XSLTProcessor();
      xsltProcessor.importStylesheet(xsl);
      resultDocument = xsltProcessor.transformToFragment(xml,document);
      document.getElementById("example").appendChild(resultDocument);
      }
    }
    </script>
    </head>
    <body onload="displayResult()">
    <div id="example" />
    </body>
    </html>
    

    Now I would like to pass a variable (javascript) to the XSL like for example "course_name" so that in the XSL I can use it like

    <xsl:param name="course_name" />
    <xsl:value-of select="$course_name" />
    

    Any help with the approach to solve this problem is highly appreciated.

    解决方案

    You can do it like this:

    xsltProcessor.setParameter(null, "course_name", "whatever the name is");
    

    and for IE, you will need to change your code as per http://msdn.microsoft.com/en-us/library/windows/desktop/ms762312%28v=vs.85%29.aspx , but the command is:

    xslproc.addParameter("param1", "Hello");
    

    ...but given that you added "xslt-2.0" as a tag, you should know that built-in XSLT support in browsers only goes up to XSL 1.0.

    The following may be of additional help:

    这篇关于使用JavaScript的XSL参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    10-29 07:32