Skip to main content

Troubleshooting: JavaScript – Not a Valid XSLT or XPath Function

If you have run into the “… is not a valid XSLT or XPath function” error, then chances are that you are messing with the Before Save or After Save properties on a form.

myEvolv uses XML to define forms and XSLT to transform the XML into HTML when displaying the form in the browser. When you export a form from myEvolv, you are downloading an XML document that defines the properties for all of the fields on the form and the form itself that you configured in the form designer. You can then upload that same file to another instance if myEvolv and the system will know how to create that form, generating all of the same fields and properties.

When you go to open a form to enter data, XSLT is used to take the XML ‘recipe’ for the form and convert it into HTML to display in the browser. This presents an issue when you try to store JavaScript code in the Before Save and After Save properties for a form because XSLT has some overlap with special characters in JavaScript and so unless you escape those in your JavaScript code, you XSLT will try to evaluate the code as an XSLT command rather than treat it as JavaScript code to pass along into the HTML.

When I got the error shown below, I was working on a snippet of JavaScript code for the Before Save property that would evaluate whether the start date of the service was before today’s date and if so, update the start date to be today’s date so that no service could be backdated. Part of my code included an if/then statement to check if start date was earlier than today’s date.

not-valid-xslt-function-error

Following JavaScript syntax, I wrote my conditional
if(start< today){setFormElement('udf_rx_4_svc_start', todaysDate())};
which caused the above error.

Turns out the problem was the curly brackets { and } because XSLT attempts to evaluate statements inside curly brackets and the XSLT did not contain a todaysDate() function. Luckily, there is a way to escape curly brackets in XML so that XSLT does not try to evaluate them and that is by using double curly brackets. So changing my code to
if(start< today){{setFormElement('udf_rx_4_svc_start', todaysDate())}};
did the trick. Error is gone and the form works as expected Before Save.

Troubleshooting: XML – A name was started with an invalid character

I was working on designing a form for a program and when I went to launch the form to test the changes that I had made, I received an XML error:

There was an error in the form XML file:  CONTACT_ther_ser_nodx.xml.

Error reason: A name was started with an invalid character.

Error line/position in file: 824 / 108

Source text: disable_rule_code=”(document.getElementById(‘serv_loca’).value != ‘569B4372-5F51-492E-87EB-D1927EE714D4’ && document.getElementById(‘serv_loca’).value != ‘E5AA86E2-C558-4423-9CE6-4D29B5489B76’ && document.getElementById(‘serv_loca’).value != ‘922BCDC4-DC91=4AC3-9949-3401AF509AE1’)”

 

xml-error-invalid-character

 

According to the error message, myEvolv was taking issue with some JavaScript that I was attempting to use to disable/enable a field based on the selected value of a picklist field.  Apparently I had an invalid character.  After scanning through my code looking for an error in my JavaScript and not finding any, I took a closer look at the error and noticed that it was actually a problem in the form XML that was throwing the error but ti was somehow related to the JavaScript code I had written.

It turns out that the problem relates to the XML standard and special characters.  In JavaScript, a double ampersand, &&, is used for the logical operator “and”.  In XML, the ampersand is a special character and myEvolv stores form data in XML so when my disable rule JavaScript was being parsed within the XML form document without the ampersands escaped, it caused an invalid character XML error.

To fix this, I just had to switch the && in my JavaScript to &amp;&amp; and the form rendered fine and the JavaScript still worked.

We are using cookies on our website

Please confirm, if you accept our tracking cookies. You can also decline the tracking, so you can continue to visit our website without any data sent to third party services.