我制作了一个使用 msxml:script 与 XMLCompiledTransform 一起使用的 XSL 脚本,但需要它的人说该脚本无法在他们的 Linux/Perl 环境中运行(这就是我所知道的他们如何使用 XSL ) 因为它“使用 Microsoft 特定的扩展”。所以我试图通过使用 xsl:script 使 XSL 更加中立。但是,我很难让它工作。
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:theScript="urn:CustomScript" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="xsl theScript fo xs fn">
<xsl:output method="xml" indent="yes" version="1.0" encoding="utf-8" omit-xml-declaration="no"/>
<xsl:script language="javascript" implements-prefix="theScript">
<![CDATA[
function test() {return "test"; }
]]>
</xsl:script>
<xsl:template match="/">
<test>
<xsl:value-of select="theScript:test()" />
</test>
</xsl:template>
</xsl:stylesheet>
上面给了我错误“找不到实现前缀'urn:CustomScript'的脚本或外部对象。”
如果我摆脱xmlns:theScript="urn:CustomScript"
它会给我错误“前缀'theScript'未定义。”
我还尝试删除所有“theScript”前缀的痕迹并仅使用implements-prefix="local"
,但这也不起作用。它告诉我test
是一个未知的 XSLT 函数。
那么我只是在这里做错了什么,还是 XMLCompiledTransform 不支持xsl:script
?