apache / camel-quarkus

Apache Camel Quarkus
https://camel.apache.org
Apache License 2.0
251 stars 186 forks source link

Support `<xsl:include>` in native mode #4472

Open ppalaga opened 1 year ago

ppalaga commented 1 year ago

An idea: We could maybe support XSLT includes in native mode by inlining them before passing to the build time XSLT compiler.

There is a test that is disabled in native mode right now

https://github.com/apache/camel-quarkus/blob/029a620733a9e5a8c1cd3aa34a3d6fd43ba5b9dd/integration-test-groups/xml/native/xslt-classpath/src/test/java/org/apache/camel/quarkus/component/xml/it/XsltTest.java#L142-L154

zhfeng commented 1 year ago

I'm not very sure what is inlining ? are you suggesting to expand the include files ?

ppalaga commented 1 year ago

I'm not very sure what is inlining ? are you suggesting to expand the include files ?

Yes, if there is <xsl:include href="my-include.xsl"> and if the content of my-include.xsl is

<xsl:stylesheet
        xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
        version='1.0'>

    <xsl:output method="xml" indent="yes" encoding="ISO-8859-1"/>

    <xsl:template match="/">
        <classpath-xsl subject="{/mail/subject}">
            <cheese>
                <xsl:apply-templates select="*|@*"/>
            </cheese>
        </classpath-xsl>
    </xsl:template>

    <xsl:template match="*">
        <xsl:copy>
            <xsl:copy-of select="attribute::*"/>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

then the <xsl:include> element would be replaced by something like

    <xsl:template match="/">
        <classpath-xsl subject="{/mail/subject}">
            <cheese>
                <xsl:apply-templates select="*|@*"/>
            </cheese>
        </classpath-xsl>
    </xsl:template>

    <xsl:template match="*">
        <xsl:copy>
            <xsl:copy-of select="attribute::*"/>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

Not sure myself how well this can work. At least line refs in error messages will be skewed.