2008年10月25日星期六

embed and run javascript in xslt in MSIE;在MSIE平台XML/XSLT中嵌入并运行javascript

we can embed javascript in XSLT and run it after transform on Mircrosoft IE platform.

the trick is put javascript code in a seperate procedure template, and let transform engine treat content as html code.

then, we must escape the javascript code, this means we use "&lt;" to replace "<" and "&gt;" to replace ">", otherwise the xslt file will be illformed.

afte this, we use <xsl:call-template name=""/> to call the javascript template.



<!--in main template-->
....
<xsl:call-template name="jsproc"/>
....

<!--javascript template-->
<xsl:template name="jsproc">
<xsl:text disable-output-escaping="yes">
&lt;script type="text/javascript"&gt;
......
&lt;/script&gt;
</xsl:text>
</xsl:template>

没有评论: