gpt4 book ai didi

javascript - 如何在 xsl 文档中使用 javascript 函数?

转载 作者:行者123 更新时间:2023-11-30 16:38:23 25 4
gpt4 key购买 nike

我的 xsl 文档中有以下代码:我尝试应用它,但它返回以下错误:错误:XSLTProcessor::transformToXml() [xsltprocessor.transformtoxml]:XPath 评估未返回任何结果。有人有想法吗??

 <xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:user="http://mycompany.com/mynamespace"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0">
<xsl:output method="text" encoding="UTF-8" />

<xsl:template match="/">
<xsl:value-of select="CARRIERNAME"/>
<xsl:value-of select="user:FormatescapeEmbeddedCommas()"/>
</xsl:template>

<msxsl:script language="javascript" implements-prefix="user">

function FormatescapeEmbeddedCommas() {

return "ABC";
}

</msxsl:script>

</xsl:stylesheet>

最佳答案

<msxsl:script language="javascript" implements-prefix="user">

支持Microsoft extension for scripting in XSL在 Chrome 中不可用。

如果您希望 XSL 在浏览器中工作,请查看此 XSLT browser comparison chart ,不幸的是,跨浏览器支持非常有限。

最好的办法是使用仅限 XSLT 1.0 的结构,而不是使用外部文档(xsl:importdocument() 函数),因为它们被默认在 Chrome 中,如果你需要函数,请使用命名模板,因为创建跨浏览器扩展函数会很棘手(我不确定 Chrome 是否支持这个,但绝对不支持 MS 命名空间)。

如果您确实需要使用特定于 vendor 的扩展,请确保使用 system-property('xsl:vendor') 在这些指令周围添加 xsl:if 并使用测试子句,它将检查您使用的浏览器。

我发现给定的错误很奇怪,我原以为它会是“找不到函数”之类的东西。

请注意,默认情况下,即使在 Internet Explorer 中,XSLT scripts are disabled by default .

如果您有任何机会在浏览器之外运行您的样式表,您可能会为自己省去很多麻烦和宝贵的时间,并且它可能使您能够使用 XSLT 2.0 或 3.0 而不仅仅是 XSLT 1.0。撒克逊有一个 JS-powered version of their XSLT 2.0 processor称为 Saxon-CE,和 Frameless is a cross-browser implementation of a large part of the XSLT 2.0 specification并声称是轻量级的。 XSLT 2.0 对使用扩展函数或指令的要求要少得多,因为它更灵活并允许您使用 xsl:function 创建自己的样式表函数.

关于javascript - 如何在 xsl 文档中使用 javascript 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32372948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com