0

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? :-)

Anders Marzi Tornblad
  • 18,896
  • 9
  • 51
  • 66
Maestro13
  • 3,656
  • 8
  • 42
  • 72
  • Try deleting the space between ``function`` and ``(x)`` so it just reads ``function(x)``. The ``Expected identifier`` makes me think the parser expects a form of either ``function funcName(x)`` or ``function(x)`` -- that is, whitespace being significant. –  Mar 26 '12 at 19:06
  • no luck - same error :-( I also tried removing the spaces around the `=`, just in case. – Maestro13 Mar 26 '12 at 19:09
  • Well, Javascript allows named functions to be assigned to variables. What about ``this['node-set'] = function nodeSet(x) {``? –  Mar 26 '12 at 19:13
  • @DavidEllis no that does not work either. I am just guessing but it may have something to do with XML Spy itself - I searched for javascript settings but could not find these... – Maestro13 Mar 26 '12 at 19:41
  • Maestro13, What browser uses XML SPY as its XSLT processor? AFAIK none. – Dimitre Novatchev Mar 27 '12 at 01:57
  • Maestro13, (Continued): Therefore no problem at all. Just stop using Altova. – Dimitre Novatchev Mar 27 '12 at 03:47
  • @DimitreNovatchev I use Altova XML Spy 2011 which uses the installed IE version as a default - IE9 for me. This is used for displaying html results or XML+associated stylesheet. It has a separate built-in xslt 1.0/2.0 processor for debugging purposes. – Maestro13 Mar 27 '12 at 06:26
  • @DimitreNovatchev and one can choose a different available xslt processor (saxon, xalan, whatever) when debugging by supplying the command line call format. – Maestro13 Mar 27 '12 at 06:32
  • @Maestro13: This is what I am saying -- the XSLT code is OK, you can just use a different XSLT processor for testing this code. – Dimitre Novatchev Mar 27 '12 at 12:37

1 Answers1

0

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.

Maestro13
  • 3,656
  • 8
  • 42
  • 72