ph-schematron/src/main/java/com/helger/schematron/saxon/SchematronTransformerFactory.java
@Nonnull
  public static TransformerFactory createTransformerFactorySaxonFirst (@Nullable final ClassLoader aClassLoader,
                                                                       @Nullable final ErrorListener aErrorListener,
                                                                       @Nullable final URIResolver aURIResolver)
  {
    TransformerFactory aFactory;
    try
    {
      // Try Saxon first
      final ClassLoader aEffectiveClassLoader = aClassLoader != null ? aClassLoader
                                                                     : ClassLoaderHelper.getContextClassLoader ();
      aFactory = TransformerFactory.newInstance (SAXON_TRANSFORMER_FACTORY_CLASS, aEffectiveClassLoader);

      // Debug/testing only
      if (false)
        aFactory.setFeature (FeatureKeys.TRACE_OPTIMIZER_DECISIONS, true);
      if (false)
        aFactory.setFeature (FeatureKeys.COMPILE_WITH_TRACING, true);
      if (false)
        aFactory.setAttribute (FeatureKeys.XSLT_VERSION, "2.0");
    }
    catch (final TransformerFactoryConfigurationError | TransformerConfigurationException ex)
    {
      try
      {
        // Try default afterwards
        aFactory = TransformerFactory.newInstance ();
      }
      catch (final TransformerFactoryConfigurationError ex2)
      {
        throw new InitializationException ("Failed to create XML TransformerFactory", ex2);
      }
    }

    if (aErrorListener != null)
      aFactory.setErrorListener (aErrorListener);
    if (aURIResolver != null)
      aFactory.setURIResolver (aURIResolver);
    return aFactory;
  }
@Nonnull
  public static TransformerFactory createTransformerFactorySaxonFirst (@Nullable final ClassLoader aClassLoader,
                                                                       @Nullable final ErrorListener aErrorListener,
                                                                       @Nullable final URIResolver aURIResolver)
  {
    TransformerFactory aFactory;
    try
    {
      // Try Saxon first
      final ClassLoader aEffectiveClassLoader = aClassLoader != null ? aClassLoader
                                                                     : ClassLoaderHelper.getContextClassLoader ();
      aFactory = TransformerFactory.newInstance (SAXON_TRANSFORMER_FACTORY_CLASS, aEffectiveClassLoader);

      // Debug/testing only
      if (false)
        aFactory.setFeature (FeatureKeys.TRACE_OPTIMIZER_DECISIONS, true);
      if (false)
        aFactory.setFeature (FeatureKeys.COMPILE_WITH_TRACING, true);
      if (false)
        aFactory.setAttribute (FeatureKeys.XSLT_VERSION, "2.0");
    }
    catch (final TransformerFactoryConfigurationError | TransformerConfigurationException ex)
    {
      try
      {
        // Try default afterwards
        aFactory = TransformerFactory.newInstance ();
      }
      catch (final TransformerFactoryConfigurationError ex2)
      {
        throw new InitializationException ("Failed to create XML TransformerFactory", ex2);
      }
    }

    if (aErrorListener != null)
      aFactory.setErrorListener (aErrorListener);
    if (aURIResolver != null)
      aFactory.setURIResolver (aURIResolver);
    return aFactory;
  }
Create a new {@link TransformerFactory} trying to invoke the Saxon
implementation first using the class
{@value #SAXON_TRANSFORMER_FACTORY_CLASS}.

@param aClassLoader
The optional class loader to be used. May be <code>null</code>.
@param aErrorListener
An optional XSLT error listener to be used. May be
<code>null</code>.
@param aURIResolver
An optional XSLT URI resolver to be used. May be <code>null</code>.
@return A new {@link TransformerFactory} and not <code>null</code>.
@throws InitializationException
In case initialization fails.