calling javascript from XSLT

Hi

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" ?>
<NumberSet>
  <integer>
    <a>10</a>
    <b>12</b>
  </integer>
</NumberSet>

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="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
   <AddTwoNumbers xmlns="http://localhost/wwwroot/addnumbers/Service1">
      <a>10</a>
      <b>12</b>
      </AddTwoNumbers>
      </soap:Body>

Please tell me how to write the code in xslt.

Regards,
Smaranika



   
</xsl:stylesheet>


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 = "http://www.tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {

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

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

    }
}
smaranika_sikdarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michel PlungjanIT ExpertCommented:
0
Geert BormansInformation ArchitectCommented:
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

cheers

Geert
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.