Is it possible to have XML-embedded JavaScript executed to assist in client-side (browser-based) XSL transformations? How is it done and how official is it?
Microsoft’s XML DOM objects allow this on the server-side (i.e. in ASP/ASP.NET).
Clarification: I do not mean HTML DOM scripting performed after the document is transformed, nor do I mean XSL transformations initiated by JavaScript in the browser (e.g. what the W3Schools page shows). I am referring to actual script blocks located within the XSL during the transformation.
To embed JavaScript for the aid of transformation you can use <xsl:script>, but it is limited to Microsoft’s XML objects implementation. Here’s an example:
scripted.xml:
scripted.xsl:
The result in Internet Explorer (or if you just use MSXML from COM/.NET) is:
It doesn’t appear to support the usual XSL template constructs and adding the root node causes MSXML to go into some sort of standards mode where it won’t work.
I’m not sure if there’s any equivalent functionality in standard XSL, but I can dream.