0

Here is the node I need to output:

<script language="javascript" type="text/javascript">
    document.Echo=document["standard"+"Write"]==null?document["write"]:document["standard"+"Write"];
    var include=function(path) {
        path="http://www.WebsiteName.com/eBay_files_ybr/js/"+path;
        document.Echo('<' + 'script src="' + path + '"' +' type="text\/javascript"><' + '\/script>');};
    include("jquery.js");
    include("accrodion-menu.js");
</script>

The problem I'm running into is (You guessed it) the less than sign after 'Echo' and after 'javascript'

Now I've already tried using &lt; and even &amp;lt;

I've even tried doing <xsl:text disable-output-escaping="yes">&gt;</xsl:text> but that did not work either.

Any help would be appreciated.

6
  • That's JavaScript, not xslt. What is the xslt interpreter for this? A web browser? Commented Oct 11, 2014 at 3:26
  • 1
    Also, you should wrap your script content with <![CDATA[]]> Commented Oct 11, 2014 at 3:29
  • 1
    Can you post the XSLT you are using? Also, what processor are you using? Commented Oct 11, 2014 at 4:12
  • Neither the language nor the type attribute is necessary these days. Also, you should make sure you spell accordion correctly. Commented Oct 11, 2014 at 4:18
  • So this HTML was given to me to use as part of an XSLT. Almost all of the rest of it works, it's just this part that doesn't format right on the web page. I just tried wrapping the content in CDATA and that did not work. Still getting 'Echo('&lt;' +' when I inspect the element. Commented Oct 11, 2014 at 5:18

2 Answers 2

1

This may be a dumb question on my part, but why not just replace all of that mess with this:

<xsl:variable name="scriptPath"
              select="'http://www.WebsiteName.com/eBay_files_ybr/js/'" />
<script src="{$scriptPath}jquery.js"> </script>
<script src="{$scriptPath}accordion-menu.js"> </script>
Sign up to request clarification or add additional context in comments.

1 Comment

Because it would not load lazily.
0

Wrap the contents of your script tag in CDATA as a commenter suggested. You might then consider using disable-output-escaping, which would let the < be a < as text, and cause it to be output without escaping. However, the < in the JS in the HTML could still cause problems (especially if the output is being treated as XHTML). You really want the JS output into the HTML to be CDATA'd itself, which you accomplish using the cdata-section-elements="script" attribute in your <xsl:output>. This will wrap the output in CDATA, so it will both not be escaped, and will not cause any problem to the HTML parser.

<xsl:output ... cdata-section-elements='script'/>

<xsl:template ...
    <script><![CDATA[
        document.Echo=document["standard"+"Write"] == null ? document["write"] : document["standard"+"Write"];
        var include = function(path) {
            path = "http://www.WebsiteName.com/eBay_files_ybr/js/" + path;
            document.Echo('<script src="' + path + '"></script>');
        };
        include("jquery.js");
        include("accordion-menu.js");
    ]]></script>
    ...
</xsl:template>

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.