0

I have this code in xslt,

    <xsl:template match="/">
                    // some truncated js code here
                    for (var i=0 ; i &lt; arrIdentifiers.length ; i++) { 
                        $("#list").append('<li class="ui-widget-content"><span class="sort-handle">&#9776;</span>'+arrIdentifiers[i]+'</li>');
                        }
                    // some truncated js code here
</xsl:template>

for some reason the the output is breaking to new line (see how span is in new line)

this is causing a JS Error..

                    for (var i=0 ; i &lt; arrIdentifiers.length ; i++) { 
                        $("#list").append('<li class="ui-widget-content">
                        <span class="sort-handle">&#9776;</span>'+arrIdentifiers[i]+'</li>');
                        }

anyway I can instruct the template not to process the internal html?

JavaSheriff
  • 7,074
  • 20
  • 89
  • 159
  • Put the content in a [CDATA](http://stackoverflow.com/q/2784183/5221149): `<![CDATA[ ... text here ... ]]>` – Andreas Oct 21 '16 at 21:22

1 Answers1

0

You don't say which XSLT processor you are using (the keyword xerces is surely irrelevant). You also don't say what your xsl:output options are but I would suspect that either explicitly or implicitly you are using method=html and indent=yes.

With these serialization options, the serializer is allowed to add whitespace (including newlines) in particular contexts. It's not allowed to add it inside a script element: it's not clear whether your code ends up within a script element or not. But if you are going to include HTML elements within Javascript literals in this way, you're going to hit problems like this. It would be safer to escape it, or to use pure Javascript DOM methods (or jQuery or whatever).

Michael Kay
  • 156,231
  • 11
  • 92
  • 164