星期二, 六月 29, 2004

在XSL/XSLT中如何嵌入大段Javascript 的方法

如下:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<!-- Javascript example 1: using CDATA sections -->
<!-- Example 1 ishould be used when embedding javascript snippets that don't make use of XML data during the transform -->
<xsl:text disable-output-escaping="yes">
<![CDATA[
<script>
alert("Generic hello world")
</script>
]]>
</xsl:text>
<!-- Javascript example 2: using xsl:text and disable-output-escaping -->
<!-- Example 2 should be used when embedding javascript snippets that need to make use of XML data during the transform -->
<xsl:text disable-output-escaping="yes"><</xsl:text>script<xsl:text disable-output-escaping="yes">></xsl:text>
alert("<xsl:value-of select="root/node" />")
<xsl:text disable-output-escaping="yes"><</xsl:text>/script<xsl:text disable-output-escaping="yes">></xsl:text>

<!-- the rest of your XSL transformation logic here -->
<xsl:value-of select="root/node" />
</xsl:template>
</xsl:stylesheet>