XSLT already has a feature to to run different instructions based on the contents of your input document: templates. I believe it is far too bothersome to mess with Saxon's internal API if you are already running an XSLT, just compile this large XSLT once and re-use it.
Just take the time to get to know XSLT and it's functional nature and convert those functions to templates with the right match expression.
I'll give an example. Let's suppose we have two input XMLs:
<myxml>
<doctype>recipe</doctype>
<descr>Bread 'n jam sandwich</descr>
<var>jam</var>
<var>bread</var>
</myxml>
<myxml>
<doctype>shoppinglist</doctype>
<descr>Monday</descr>
<var>honey</var>
<var>butter</var>
<var>loaf of bread</var>
<var>jam</var>
</myxml>
Now let's say that we want to generate HTMLs for these XMLs with the right formatting. The first XML should generate an HTML with "Recipe: " and a list of ingredients. The second should contain a shopping list.
Here's the XSLT to generate both:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:saxon="http://saxon.sf.net/"
exclude-result-prefixes="xs saxon">
<xsl:output method="html" indent="yes"/>
<!-- Generate basic html -->
<xsl:template match="/">
<html>
<body><xsl:apply-templates /></body>
</html>
</xsl:template>
<!-- Only call template doctype element, not for vars -->
<xsl:template match="myxml">
<xsl:apply-templates select="doctype"/>
</xsl:template>
<xsl:template match="doctype[.='shoppinglist']">
<h1>Shopping list for <xsl:value-of select="../descr"/></h1>
<span><b>Stuff to bring:</b></span>
<ul>
<xsl:for-each select="../var">
<li><xsl:value-of select="."/></li>
</xsl:for-each>
</ul>
</xsl:template>
<xsl:template match="doctype[.='recipe']">
<h1>Recipe: <xsl:value-of select="../descr"/></h1>
<span><b>Ingredients:</b></span>
<ul>
<xsl:for-each select="../var">
<li><xsl:value-of select="."/></li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
Now look at the match argument of the last templates. In this case I picked based on the contents of an element, but you could just use any XPath filter expression you like (i.e. to choose based on an XML argument).