开发者

XSL in script tags

I need to output XSL in between script tags to dynamically output values into JavaScript.

Here is the code, but I can't get it to work. I want to add the position() into the script so it outputs something like o.write("flash1"); and increments the number per each flash file e开发者_高级运维mbedded. Any help appreciated.

<div>
  <xsl:attribute name="id">iframe-content<xsl:value-of select="position()"/></xsl:attribute>
  <div id="flash"></div><!--/flash-->
  <script type="text/javascript">
    // <![CDATA[ 
    var so = new SWFObject("swf/video2.swf", "showreel", "720", "484", "8", "#ffffff");
    so.addParam("quality", "high");
    so.addParam("allowScriptAccess", "always");
    so.addParam("wmode", "transparent");
    so.addVariable("videoURL", "http://www.masterseries.co.uk/public/TempFiles/Concrete1.flv");
    so.write("flash");
    // ]]>
  </script>
</div>


You were close (you just can't easily use CDATA the way you did):

<!-- note that you don't need xsl:attribute here -->
<div id="iframe-content-{position()}">
  <div id="flash"></div><!--/flash-->
  <script type="text/javascript">
    var so = new SWFObject("swf/video2.swf", "showreel", "720", "484", "8", "#ffffff");
    so.addParam("quality", "high");
    so.addParam("allowScriptAccess", "always");
    so.addParam("wmode", "transparent");
    so.addVariable("videoURL", "http://www.masterseries.co.uk/public/TempFiles/Concrete1.flv");
    so.write("flash<xsl:value-of select='position()' />");
  </script>
</div>

You can use

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

to create CDATA sections in the output. However, you must make sure the input script source is correctly XML-encoded, i.e. does not have bare <, &, > characters but their &lt;, &amp;, &gt; equivalents.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜