With the addition of static parameters , this is now possible in XSLT 3.0. Static parameters can be used in the use-when xsl:include attribute.
Now we can declare the parameters with the default values false() , and then override the ones we need at runtime ...
<xsl:param name="someparam" as="xs:boolean" select="false()" static="yes" required="no"/> <xsl:include href="include_me.xsl" use-when="$someparam"/>
Here is a complete working example tested with Saxon-HE v9.7 (also tested with Saxon-PE 9.5).
XML input (test.xml)
<doc> <foo/> </doc>
Core XSLT 3.0 (test_main.xsl)
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"> <xsl:output indent="yes"/> <xsl:strip-space elements="*"/> <xsl:param name="inc1" as="xs:boolean" select="false()" static="yes" required="no"/> <xsl:param name="inc2" as="xs:boolean" select="false()" static="yes" required="no"/> <xsl:include href="test_inc1.xsl" use-when="$inc1"/> <xsl:include href="test_inc2.xsl" use-when="$inc2"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
Perhaps the first inclusion of XSLT 3.0 (test_inc1.xsl)
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="foo"> <xsl:copy>INCLUDE FILE 1!!!</xsl:copy> </xsl:template> </xsl:stylesheet>
The second possible inclusion of XSLT 3.0 (test_inc2.xsl)
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="foo"> <xsl:copy>INCLUDE FILE 2!!!</xsl:copy> </xsl:template> </xsl:stylesheet>
Command line (set inc2 to true)
java -cp "saxon9he.jar" net.sf.saxon.Transform -s:"test.xml" -xsl:"test_main.xsl" inc2="true"
Exit
<doc> <foo>INCLUDE FILE 2!!!</foo> </doc>
source share