A.xsl imports B.xsl, which contains a function used in A.xsl. A.xsl contains the identity template. B.xsl's function needs to apply template rules to a variable; however, the identity template in A.xsl is overriding them.
My thought was to xsl:apply-imports
to the variable in B, but unlike xsl:apply-templates
there is no way to select=
to point it to a variable. The original functions can't be replaced with template rules. Is there a way to do this without xsl:include
-ing B.xsl?
A.xsl:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:my="http://me"
version="2.0">
<xsl:import href="B.xsl"/>
<xsl:template match="X">
<xsl:sequence select="my:do-stuff(.)"/>
</xsl:template>
<xsl:template match="@*|node()" mode="#all" priority="-1">
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="#current"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
B.xsl:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:my="http://me"
version="2.0">
<xsl:template match="X" mode="cleanup">
<clean><xsl:apply-templates/></clean>
</xsl:template>
<xsl:function name="my:do-other-stuff">
<xsl:param name="x" as="element(X)"/>
...
</xsl:function>
<xsl:function name="my:do-stuff">
<xsl:param name="x" as="element(X)"/>
<xsl:variable name="x-updated" select="my:do-other-stuff($x)"/>
<xsl:apply-templates select="$x-updated" mode="cleanup"/>
</xsl:function>
</xsl:stylesheet>
One option is to prevent the identity template from overriding by changing
mode="#all"
to list all modes exceptcleanup
: