Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSL tags inside javascript block

I need my 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 XSL value-of tag <xsl:value-of select="MediaUrlFolder"/>.

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

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

Now there is a weird problem (that was there before for sure, but I wasn't looking at the source code). The <script> block isn't being rendered at all, nothing inside it, not even the <script></script> tags. Do you know why this could be happening? Thanks.

like image 991
Marcos Buarque Avatar asked Dec 05 '25 17:12

Marcos Buarque


2 Answers

You seem to be missing a / between MediaUrlFolder and ImageUrlFileName although perhaps your folders already have a trailing /. Also you appear to have an unescaped & which should be &amp;

I would probably prefer this approach:-

<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>
like image 167
AnthonyWJones Avatar answered Dec 08 '25 08:12

AnthonyWJones


<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>

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!