phax / ph-schematron

Java Schematron library that supports XSLT and native application
Apache License 2.0
115 stars 36 forks source link

XInclude support #86

Closed nkutsche closed 2 years ago

nkutsche commented 5 years ago

Hi,

...and another issue I'm working on right now. :blush:

Currently I'm using a hack to support XInclude in my source files. By adding this templates:

<sch:let name="include" value="false()"/>

<xsl:template match="/" priority="100000000">
    <xsl:param name="xi:xinclude" select="$include" tunnel="yes"/>
    <xsl:variable name="xi:xincluded">
        <xsl:apply-templates select="." mode="xi:xinclude"/>
    </xsl:variable>
    <xsl:choose>
        <xsl:when test="not($xi:xinclude)">
            <xsl:next-match/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:apply-templates select="$xi:xincluded">
                <xsl:with-param name="xi:xinclude" select="false()" tunnel="yes"/>
            </xsl:apply-templates>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template match="xi:include[not(@parse = 'text')]" mode="xi:xinclude" priority="100000000">
    <xsl:apply-templates select="doc(resolve-uri(@href, base-uri(.)))/*" mode="#current"/>
</xsl:template>

<!-- 
    copies all nodes:
-->
<xsl:template match="node() | @*" mode="xi:xinclude">
    <xsl:copy>
        <xsl:apply-templates select="@*" mode="#current"/>
        <xsl:apply-templates select="node()" mode="#current"/>
    </xsl:copy>
</xsl:template>

it works at least with the Schematron engine (in ant). But it is a hack and will lead maybe to other issues.

It would be much cleaner if I just could pass a Saxon config file to activate the XInclude support of the Saxon. But as far as I can see there is no such option here, is there?

Thanks!

phax commented 3 years ago

As I am using JAXP to instantiate Saxon (TransformerFactory.newInstance (SAXON_TRANSFORMER_FACTORY_CLASS, aEffectiveClassLoader);) I don't know how to pass a configuration file. Instead I enabled XInclude by default now. Does that help (better late than never ;-) ) - would be part of 6.0.2