javascript块内的XSL标签

时间:2009-03-14 20:15:12

标签: javascript xslt scripting

我需要我的XSL将动态内容添加到javascript块。我想知道这是否可行。这是我想要做的一个例子。以下代码不起作用:

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

当我添加标记<xsl:value-of select="MediaUrlFolder"/>的XSL值时,解析器会中断。

有解决方案吗?您好,我可以安全地添加这种代码吗?谢谢!

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

现在有一个奇怪的问题(之前确实存在,但我没有查看源代码)。 <script>块根本没有呈现,内部没有任何内容,甚至不是<script></script>标记。你知道为什么会这样吗?感谢。

2 个答案:

答案 0 :(得分:1)

您似乎缺少MediaUrlFolder和ImageUrlFileName之间的/,尽管您的文件夹可能已经有一个尾随/。你似乎还有一个没有转义的&amp;应该是&amp;

我可能更喜欢这种方法: -

<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 :(得分: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>