lema
lema

Reputation: 480

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

I want to have multiple file output with xsl so I'm using xsl:result-document and I'm having this error

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

It seems that I need to enable the external functions so that it works. But the problem is that I am not using command line, I can't just put -ext:on. Here I am calling xslt with camel and spring XML. If I understood well, I need to change the configuration properties of xslt so that the allow-external-functions is set to true.

Here is what I tried to fix it :

<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>

And then when I call xslt-saxon :

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

But it doesn't work, the error is :

No component found with scheme: xslt-saxon

Even if I add dependency to saxon in my pom.xml it doesn't work. I don't know what to try next, do you have any idea ?

EDIT :

Now there is no more error when using xslt-saxon, but the first error is still there. It is as the map for allow-external-functions didn't work.

Upvotes: 0

Views: 911

Answers (1)

burki
burki

Reputation: 7005

I am able to run an XSL transformation with Saxon through Camel by just sending a message with an XML body to

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

No Spring XML needed or enabling of external functions, it just works when I add the dependency

<artifactId>camel-saxon</artifactId>

By the way, I am on Camel 2.17.


My example input XML

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

My 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>

This gives me two new files, notice the dynamic filename defined as test-{position()}.txt

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

Both files are created in the same path where my transformation stylesheet is saved since I just provide a filename and no path.

Upvotes: 1

Related Questions