Hi,
I am having trouble running an XSL transformation with embedded javascript. It works fine under the Visual Studio XSLT debugger but when run in my application, it fails with E_FAIL. There may be better solutions than Javascript but I want to learn why it doesn't work, and what to do about it.
Following the samples I found in the Internet (and after some trial-and-error), I wrote this:
<xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:js="http://something.org"><msxsl:script language="JavaScript" implements-prefix="js">
function myfunc(tm) {...}
</msxsl:script>...
<xsl:template ...>
<xsl:value-of select="js:formatted_time(js:myfunc(string(MyTag)))" />
</xsl:template>
xmlns:msxsl="urn:schemas-microsoft-com:xslt" comes directly from example XSLT code.
I put it xmlns:js="http://something.org" because otherwise, the XSL processor would complain that namespace js is not declared. I don't know whether this is the right way to do it but it works.
I tested the transformation in Visual Studio 2012, using its built-in XSLT debugger, and it worked. Then I fed it into my application.
The application is written in non-managed C++ and uses the COM interface to msxml, instantiating three MSXML2::DOMDocument60 objects for input, transformation, and output. After loading input and transformation with data, it calls the transformNodeToObject
method of the input document, supplying the transformation object and the IDispatch interface of the output document as arguments.
The operation returns E_FAIL and this error text: "Security settings do not allow the execution of script code within this stylesheet." Research led me to some places on the Internet saying I should insert this call:
setProperty(L"AllowXsltScript", VARIANT_TRUE);
I am unsure for which of my DOMDocument60 objects I should use this call; to be on the safe side, I do it for all of them. Now the error code is still E_FAIL but the description text is empty.
What am I doing wrong?