Archive

Posts Tagged ‘XML’

Using jQuery to call a Web Service in XSLT

June 18, 2010 1 comment

Transforming XML into HTML or the like using XSL Transforms is a powerful tool.  The biggest problem I faced when I began transforming certain XML tags into HTML controls is that the controls don’t do ANYTHING!  Fortunately I figured out a way to use jQuery inside of the XSL transform to call an .asmx web service.  I started by taking some XML, maybe something like:

<highlight>yellow</highlight>

In the XSLT when I find the <highlight> tag, you can do something like this:

This gives you a drop down style box, with the appropriate option selected, of course there will be a few more xsl:when options, and a an otherwise option that acts as a try:finally.  Now that you have a functionless drop down, its time to add the code behind that you want the drop down to execute on, say a change of selection.  So make yourself a Web Service (.asmx)  maybe something like the following:

Now for the trick: calling this web service using jQuery.  Of course, this jQuery must be in your XSLT, making it even more tricky to trouble shoot.  I used the jQuery.ajax() function.  It will looks something like this:

Now you have a fully function Control generated by XSLT. Enjoy!

Categories: C# Tags: , , , ,