We're using Saxonee- to perform schema-aware xslt transformations and are very pleased with the results so far. In some cases however, our xslt fails to produce a result document that validates against the supplied schema, causing saxon to terminate the transformation and not produce output. Since having access to the invalid output would make manual correction/debugging a lot easier, I would like to be able to instruct saxon to treat validation errors as non-fatal.

In the javadoc I found a couple of methods (setConfigurationProperty(FeatureKeys.VALIDATION_WARNINGS, Boolean.TRUE); and setValidationWarnings(true); on net.sf.saxon.Configuration) that look useful. Unfortunately configuring saxon (either directly or via FeatureKeys) does not seem to have the desired effect. Validation errors still cause the transformation to be halted without producing output. Could it be that we're overlooking a setting somewhere?  I've included some sample code with this mail.


package test;

import java.io.File;
import java.io.FileInputStream;

import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;

import net.sf.saxon.lib.FeatureKeys;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.Serializer;
import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltTransformer;

import org.xml.sax.InputSource;

public class SchemaAwareTransformer {

    public static void main(String[] args) throws Exception {
        if (args.length < 4) {
            System.err.println("[input] [output] [stylesheet] [schemaURL]");

        transform(new File(args[0]), new File(args[1]), new File(args[2]),args[3]);

    public static void transform(File input, File output, File stylesheet,String schemaURL) throws Exception {
        Processor processor = new Processor(true);

        Serializer serializer = new Serializer();

        XsltCompiler compiler = processor.newXsltCompiler();
        XsltTransformer transformer = compiler.compile(new StreamSource(stylesheet)).load();

        transformer.setSource(new SAXSource(new InputSource(new FileInputStream(input))));

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="

    <xsl:output indent="yes" encoding="UTF-8" />

    <xsl:template match="/">
        <xsl:document validation='lax'>
            <xsl:next-match />

    <xsl:template match="*">
        <xsl:element name="{name()}" namespace="{namespace-uri()}">