Page 1 of 1

javascript wrapping after value-of on format

Posted: Mon Nov 02, 2020 7:48 pm
by wilsonjr
When formatting this code in XML Editor 22.1:

<script>
var serverName = '<xsl:value-of select="/data/serverName"/>';
</script>


the single quote and semicolon wrap resulting in broken javascript:

<script>
var serverName = '<xsl:value-of select="/data/serverName"/>
';
</script>


How can the wrapping after the value-of be prevented?

Re: javascript wrapping after value-of on format

Posted: Tue Nov 03, 2020 10:18 am
by tavy
Hello,

Thanks for your feedback.
I think your document is an XHTML (has the namespace "http://www.w3.org/1999/xhtml" set on root ), or it is an HTML document opened in the XHTML editor.
You can verify the content type of the opened document in the Properties view (Help menu->Show View->Properties). If the content type value is "application/xhtml+xml", it means that is an XHTML document, if is "text/html" it means that is an HTML document.

In case you have an XHTML document ( the namespace "http://www.w3.org/1999/xhtml" is set on root), you need to add the script content in a CDATA. Something like this:

Code: Select all

<script>
//<![CDATA[
    var serverName = '<xsl:value-of select="/data/serverName"/>';
//]]>
</script>
If you document does not have the XHTML namespace set on root, probably you opened the file with the XHTML editor. You can close the file and use the Open With->Internal Editor action from the Project view contextual menu. Then select HTML editor from the list in order to be opened as an HTML.

Best Regards,
Octavian