tags:

views:

13

answers:

2

Hi,

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 Javascript 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.

A: 

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.

Nigel Thorne
Thanks for the link Nigel, I tried with that as well, however, got the following error- "org.apache.xalan.extensions.ObjectFactory$ConfigurationError: Provider org.apache.bsf.BSFManager not found".I am not sure that which XALAN Version I am using, not even sure that which XSLT processor it is using. where could i find all these informations? I am running it on IBM RAD 7.0.
A: 

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

FK82