最好放到<head>中,放到<body>中的JS有可能执行不到。

解决方案 »

  1.   

    多谢楼上提醒……
    不过其实叙述问题很复杂,我将它简单化下如
    test.xml
    <pagehome>
    <profili><sp>2</sp></profile>
    </pagehome>2.js
    alert(1);test.xsl
    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl">
        <xsl:template match="text()">
            <xsl:value-of />
        </xsl:template>
        <xsl:template match="/">
    <html>
    <head>
    <xsl:element name="script">
    <xsl:attribute name="language">javascript</xsl:attribute>
    <xsl:attribute name="src">/weblog/blogjs/<xsl:value-of select="home/profile/sp"/>.js</xsl:attribute>
    </xsl:element>
    <META http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    </head>
    <body>
    </body>
    </heml>
    </xsl:template>
    </xsl:stylesheet>这样是可以执行的但
    test.xsl
    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl">
        <xsl:template match="text()">
            <xsl:value-of />
        </xsl:template>
        <xsl:template match="/">
    <html>
    <head>
    <META http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    </head>
    <body>
    <xsl:element name="script">
    <xsl:attribute name="language">javascript</xsl:attribute>
    <xsl:attribute name="src">/weblog/blogjs/<xsl:value-of select="home/profile/sp"/>.js</xsl:attribute>
    </xsl:element></body>
    </heml>
    </xsl:template>
    </xsl:stylesheet>
    这样不能执行
    我必须将js在body间调用,因为里面有操作body的语句