gpt4 book ai didi

.net - 可以 xsl :script be used with XMLCompiledTransform?

转载 作者:行者123 更新时间:2023-12-04 06:20:37 24 4
gpt4 key购买 nike

我制作了一个 XSL 脚本,它使用 msxml:script 与 XMLCompiledTransform 一起使用,但是需要它的人说该脚本无法在他们的 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 ?

最佳答案

xsl:script仅在 XSLT1.1 中定义,但该标准被取消以支持 XSLT2.0,因此实际上如果您正在寻找可移植性,我不建议使用它。

XSLT 最便携的形式肯定是 XSLT1.0,因为对它的支持要多得多。尽管在 XSLT2.0 中有些事情肯定更容易,但您可能会发现您可能想要执行的大多数“脚本”代码都可以仅在 XSLT 中完成。 XSLT2.0 可以定义函数,但在 XSLT1.0 中可以使用命名模板来模拟函数,只是比较麻烦。

XSLT2.0:

<xsl:template match="/">
<xsl:value-of select="test('param')" />
</xsl:template>

<xsl:function name="test" as="xs:string">
<xsl:param name="param" as="xs:string" />
<xsl:text>Test</xsl:text>
</xsl:function>

XSLT1.0:
<xsl:template match="/">
<xsl:call-template name="test">
<xsl:with-param name="param" select="'param'" />
</xsl:call-template>
</xsl:template>

<xsl:template name="test">
<xsl:param name="param" />
<xsl:text>Test</xsl:text>
</xsl:template>

但是,此示例中未使用该参数,但您明白了。

关于.net - 可以 xsl :script be used with XMLCompiledTransform?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6629328/

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