XSL tags inside javascript block

I need XSL to add dynamic content to a javascript block. I am wondering if this is possible. Here is an example of what I want to do. The following code does NOT work:

<script>
    // Loads the video.
    var s1 = new SWFObject("player-viral.swf","ply","670","350","9","#ffffff");
    s1.addParam("allowfullscreen","true");
    s1.addParam("allownetworking","all");
    s1.addParam("allowscriptaccess","always");
    s1.addParam("flashvars","file=/Portals/0/<xsl:value-of select="MediaUrlFolder"/><xsl:value-of select="ImageUrlFileName"/>&image=/Portals/0/<xsl:value-of select="ImageUrlFolder"/><xsl:value-of select="ImageUrlFileName"/>");
    s1.write("container");
</script>

The parser breaks when I add the value of an XSL tag <xsl:value-of select="MediaUrlFolder"/>.

Is there a solution for this? Hi, can I add this code in a safe way? Thanks!

=======================================

Now there is a strange problem (it was before, but I did not look at the source code). A block is <script>not displayed at all, nothing inside it, even tags <script></script>. Do you know why this could happen? Thanks.

+3
source share
2 answers

, MediaUrlFolder ImageUrlFileName, , , /. , unescaped &;

: -

<script>
    // Loads the video.
    var mediaUrlFolder = '<xsl:value-of select="MediaUrlFolder"/>'
    var imageUrlFileName = '<xsl:value-of select="ImageUrlFileName"/>'
    var imageUrlFolder = '<xsl:value-of select="ImageUrlFolder"/>'
    var s1 = new SWFObject("player-viral.swf","ply","670","350","9","#ffffff");
    s1.addParam("allowfullscreen","true");
    s1.addParam("allownetworking","all");
    s1.addParam("allowscriptaccess","always");
    s1.addParam("flashvars","file=/Portals/0/" + mediaUrlFolder  + "/" + imageUrlFileName + "&amp;image=/Portals/0/" + imageUrlFolder + "/" + imageUrlFileName);
    s1.write("container");
</script>
+1
<xsl:comment>//<![CDATA[
<script>        // Loads the video.        var s1 = new SWFObject("player-viral.swf","ply","670","350","9","#ffffff");        s1.addParam("allowfullscreen","true");        s1.addParam("allownetworking","all");        s1.addParam("allowscriptaccess","always");        s1.addParam("flashvars","file=/Portals/0/<xsl:value-of select="MediaUrlFolder"/><xsl:value-of select="ImageUrlFileName"/>&image=/Portals/0///]]><xsl:value-of select="ImageUrlFolder"/><xsl:value-of select="ImageUrlFileName"/><![CDATA[");        s1.write("container");</script>
//]]></xsl:comment>
+1

Source: https://habr.com/ru/post/1704773/


All Articles