2

I have to have an inline script in an xsl stylesheet file but the problem is that the xsl tries to transform the script and causes errors.

<script id="template-upload" type="text/x-tmpl">
             {% for (var i=0, file; file=o.files[i]; i++) { %}
                 <tr class="template-upload fade">
                     <td class="preview"><span class="fade"></span></td>
                     <td class="name"><span>{%=file.name%}</span></td>
                     <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
                     {% if (file.error) { %}
                         <td class="error" colspan="2"><span class="label label-important">Error</span> {%=file.error%}</td>
                     {% } else if (o.files.valid && !i) { %}
                         <td>
                             <div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="bar" style="width:0%;"></div></div>
                         </td>
                         <td class="start">{% if (!o.options.autoUpload) { %}
                             <button class="btn">
                                 <i class="icon-upload icon-white"></i>
                                 <span>Start</span>
                             </button>
                         {% } %}</td>
                     {% } else { %}
                         <td colspan="2"></td>
                     {% } %}
                     <td class="cancel">{% if (!i) { %}
                         <button class="btn btn-danger">
                             <i class="icon-ban-circle icon-white"></i>
                             <span>Cancel</span>
                         </button>
                     {% } %}</td>
                 </tr>
             {% } %}
          </script>

Is there a way to have inline script in xsl?

0

1 Answer 1

5

Your javascript part is not valid xml because of the ampersand (&). To avoid interpretation you can use CDATA and disable-output-escaping to avoid escaping.

<xsl:template match="/">
        <script id="template-upload" type="text/x-tmpl">
            <xsl:text disable-output-escaping="yes" >
            <![CDATA[
     ...

        ]]>
        </xsl:text>
        </script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.