calling javascript from XSLT

Posted on 2008-11-18
Last Modified: 2013-11-18

I need to call webservice from xslt in HTTP POST Method. The MSXML should be used. I am using javascript.

I have an XML File which is having Integer Node.....Shown Below
<?xml version="1.0" encoding="utf-8" ?>

XSLT will call javascript and pass "Integer" node to javascript. The javascript will create the SOAP message and call webservice.
The soap message is....

  <?xml version="1.0" encoding="utf-8" ?>
    - <soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap="">
   <AddTwoNumbers xmlns="http://localhost/wwwroot/addnumbers/Service1">

Please tell me how to write the code in xslt.



The Web method is......

using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;

/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {

    public WebService () {
        //Uncomment the following line if using designed components

    //public string HelloWorld()
    //    return "Hello World";
    public int WebAdd(int x, int y)
        return x + y;
    public int WebMultiply(int x, int y)
        return x * y;
    public void testmethod(XmlDocument xd)

Question by:smaranika_sikdar
    LVL 75

    Expert Comment

    by:Michel Plungjan
    LVL 60

    Accepted Solution

    well, let me start by saying that I STRONGLY recommend that you don't try it this way.
    SOAP messages from within XSLT is the other away round

    - you cannot rely on the fact that the JavaScript (or JScript in this case) engine in the XSLT will allow exactly what the scripting engine outside the XSLT allows, not all libraries will be loaded. So it might be possible in one architecture and not possible in another. This is all highly undocumented
    - XSLT has no predefined flow order of the programm... if you will be trying very procedural stuff inside an XSLT, you might get unpredictable behaviour (variables not being set when you expect them to be set, etc...)
    - main point: you would not be able to report back to the XSLT. Grabbing Error messages from the Soap connection and putting the message in the output tree will fail because of the previous point.
    This will lead to programms that will be very hard to debug and maintain

    I would do this the other way round.
    Call the XSLT from the JavaScript and use the XSLT results in the SOAP call!

    I can imagine a three step to do what you need to do.
    - transform the XML using XSLT, resulting in a small and easy XML snippet containing the a and b value (might not be necessary in this case)
    - pull the a and b value out the XML using simple DOM methods, call the SOAP with the extracted values
    - push the result as a parameter in a new XSLT transformation (the one where you wanted to use the result from the soap call)

    This would work if you only intended to do one soap call in the XSLT

    If you need the soap calls on multiple nodes:
    - transform the XML collecting the multiple nodes in a simplyfied XML,
    - make a nodeset from the simplified XML, loop over the nodeset and call the soap server for each node
    - Make the real transformation XSLT, put identifiable placeholders in the XSLT result, where you expected the soap results
    - merge the soap call results with the XSLT results by streaming trought the serialised XSLT result and replacing the placeholders

    just a thought



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now