views:

546

answers:

2

Hi, 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.

+1  A: 

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>
AnthonyWJones
Hey, thanks, I will try this. Regarding your first question, yes, the folder variable already holds the last folder slash so the URL should be OK. Thks.
Marcos Buarque
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. Do you know why this could be happening? Thanks.
Marcos Buarque
+1  A: 
<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>
Hey, thanks, seems 2 be a good idea. In my case, I found out the software I was using blocked javascripts for security purposes.
Marcos Buarque