How to include Javascript in xml-document?

前端 未结 7 1620
醉酒成梦
醉酒成梦 2020-12-01 07:59

The task seems to be pretty easy: how to include a Javascript file in xml-document so that at least Opera and Firefox could actually parse it and execute the code?

7条回答
  •  盖世英雄少女心
    2020-12-01 08:53

    Similar to the above, but that could error because the and ]]> portions are not valid code. If you're putting it into an XSL script, you can just as well put a JS comment mark before these beginning and ending elements.

    I also have used the xsl:text element to output the portion. This portion may be a bit of cheat, but it results in well-formed XML. An example from within an xsl:choose block might be...

    ...
    
      
    
    ...
    

    Walking through the pieces...

    1. Detect a tag, of course.
    2. And, if you're using it in a xsl:choose block, close then xsl:when.

    Only steps 2, 3, 5, & 7 actually copy the script block. The rest is busywork to make it work.

    Transforming a block such as...

    ...
    
    ...
    

    Then becomes,

    ...
    
    

    Effectively preserved, and readable both by XML as well as a browser.

提交回复
热议问题