Hi,

We're using Saxonee-9.3.0.4j 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.

Daan

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]");
            System.exit(-1);
        }

        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);
        processor.setConfigurationProperty(FeatureKeys.VALIDATION_WARNINGS,Boolean.TRUE);
        processor.getUnderlyingConfiguration().addSchemaSource(newStreamSource(schemaURL));
        //processor.getUnderlyingConfiguration().setConfigurationProperty(FeatureKeys.VALIDATION_WARNINGS,Boolean.TRUE);

        Serializer serializer = new Serializer();
        serializer.setOutputFile(output);

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

        transformer.setSource(new SAXSource(new InputSource(new FileInputStream(input))));
        transformer.setDestination(serializer);
        transformer.transform();
    }
}


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform">

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

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

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