xsl:result-禁用扩展功能时文档被禁用

xsl:result-document is disabled when extension functions are disabled

我想用 xsl 输出多个文件,所以我正在使用 xsl:result-document,我遇到了这个错误

xsl:result-禁用扩展功能时文档被禁用

看来我需要启用外部功能才能正常工作。但问题是我没有使用命令行,我不能只输入 -ext:on。这里我用camel和springXML调用xslt。如果我理解得很好,我需要更改 xslt 的配置属性,以便将 allow-external-functions 设置为 true。

这是我试图修复它的方法:

<bean id="xslt-saxon" class="org.apache.camel.component.xslt.saxon.XsltSaxonComponent">
        <property name="saxonConfiguration">
          <bean class="net.sf.saxon.Configuration"/>
        </property>
        <property name="saxonConfigurationProperties">
          <map>
            <entry key="http://saxon.sf.net/feature/allow-external-functions" value="true" value-type="java.lang.Boolean"/>
          </map>
        </property>
    </bean>

然后当我调用 xslt-saxon 时:

<to uri="xslt-saxon:file://{{format.transformer.file}}"/>

但是不行,错误是:

No component found with scheme: xslt-saxon

即使我在 pom.xml 中添加对 saxon 的依赖,它也不起作用。 我不知道接下来要尝试什么,你有什么想法吗?

编辑 :

现在使用xslt-saxon时没有更多的错误,但第一个错误仍然存​​在。这是因为 allow-external-functions 的映射不起作用。

我可以 运行 通过 Camel 与 Saxon 进行 XSL 转换,只需将带有 XML 正文的消息发送到

.to("xslt:transformation.xsl?saxon=true")

不需要Spring XML 或启用外部功能,它只在我添加依赖项时起作用

<artifactId>camel-saxon</artifactId>

顺便说一下,我正在使用 Camel 2.17。


我的示例输入XML

<?xml version="1.0" encoding="UTF-8"?>
<Camel>
    <Component>
        <XSL>The XSL component</XSL>
        <File>The file component</File>
    </Component>
</Camel>

我的transformation.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    <xsl:template match="/">
        <Camel-Components>
            <xsl:for-each select="Camel/Component/*">
                <xsl:result-document href="test-{position()}.txt">
                    <xsl:value-of select="."/>
                </xsl:result-document>
            </xsl:for-each>
        </Camel-Components>
    </xsl:template>
</xsl:stylesheet>

这给了我两个新文件,注意 动态文件名 定义为 test-{position()}.txt

  • test-1.txt => 包含 The XSL component
  • test-2.txt => 包含 The file component

这两个文件都是在保存我的转换样式表的相同路径中创建的,因为我只提供了一个文件名而没有提供路径。