开发者

Can i use Javascript in XSL while converting an XML to another XML?

I've an XML document and I am creating another XML using XSL. I need to check some specific conditions and for that I want to use J开发者_开发百科avascript in my XSL. I tried it, however, couldn't get the desired result. I am not sure whether the Javascript will work in this XSL for checking the conditions or not. Please advise.


XSLT are XML transformation files. They are run via an XSLT transform engine. The only way I can see that javascript would work.. is if the XSLT transform engine understood Javascript somehow. I wouldn't expect it to. Which XSL transformation engine are you using?

Update: maybe this will help http://www.informit.com/articles/article.aspx?p=26881&seqNum=4

Note in this article he references a specific transformation engine (Xalan-Java 2 XSLT). Each one is open to implement extensions like this differently.


In Mozilla it seems an object is supplied to do just that: check, https://developer.mozilla.org/en/Using_the_Mozilla_JavaScript_interface_to_XSL_Transformations . (Below are some code excerpts from the MDC documentation).

You will need to specify a XSLT stylesheet and then create a XSLTProcessor object:

var processor = new XSLTProcessor();  

Doing that you may implement a new document and transform it according to the XSLT style specified:

var testTransform = document.implementation.createDocument("", "test", null);  
    testTransform.addEventListener("load", onload, false);  
    testTransform.load("test-transform.xml");  

    function onload() {  
        processor.importStylesheet(testTransform);  
    }  

HTH,

FK

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜