javascriptxsltxmlspy

xslt javascript: error when trying to define function with a name including a dash


Following David Carlisle blogspot exslt node-set function I added the below to my stylesheet:

...xmlns:msxsl="urn:schemas-microsoft-com:xslt"...

<msxsl:script language="jscript" implements-prefix="exslt">
    this['node-set'] = function (x) {
        return x;
    }
</msxsl:script>

If I understand correctly, this way of defining a function in javascript (using this) is necessary because of the dash in the function name; defining it as function node-set(){...} will not work and this['z'] is equivalent to this.z.
The problem is that this script is rejected by the script-validator in XML Spy.

Script Compile Error(s) (relative to script begin):

Line 1, Character 3: Syntax error

Line 1, Character 31: Expected identifier " this['node-set'] = function (x) { return x; } "

No problem at all when I define function nodeset(){...} but somehow it does not allow me to use the construct this['...'], not even this['nodeset'] where a function name without dashes is used.

Anyone know what I should do about this? David, perhaps? :-)


Solution

  • I checked this with Altova support desk, asking about the error when using "this", and they replied as follows:

    The code in question is non-standard for XSLT 1.0, using MSXML-only features.

    Not a clear answer, but I deduce that this implies that XML Spy's javascript version does not support "this".
    I will thus include the code where I need it and just check the code by opening the XML + referred stylesheet in a list of browsers, not bothering about the javascript error that XML Spy mentions during xslt edit or save.