Project

Profile

Help

Support #6300

closed

Howto correctly validate a xml-file against a xslt file in Saxon version 10

Added by Michael Eriksen 11 months ago. Updated 9 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2023-12-20
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
10
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

Description

I am new to Saxon, and have tried to validate a xml-file against a xslt file (based on the samples that comes with Saxon 10) - but I can't understand why a non valid xml-file gives no errors with the following code - even I have expected some errors reported:

        String xmlFile = "C:\\InvoiceStor_v2p2.xml";
        String styleFile = "C:\\OIOUBL_Invoice_Schematron.xsl";
        Processor processor = new Processor();
        DocumentBuilder builder = processor.NewDocumentBuilder();
        builder.BaseUri = new Uri(xmlFile);
        XdmNode input = builder.Build(File.OpenRead(xmlFile));
        XsltCompiler compiler = processor.NewXsltCompiler();
        compiler.BaseUri = new Uri(styleFile);
        Xslt30Transformer transformer = compiler.Compile(File.OpenRead(styleFile)).Load30();
        transformer.GlobalContextItem = input;
        Serializer serializer = processor.NewSerializer();
        serializer.SetOutputWriter(Console.Out);
        transformer.ApplyTemplates(input, serializer);
        try
        {
            compiler.Compile(new Uri(styleFile));
            Console.WriteLine("Stylesheet compilation succeeded");
        }
        catch (Exception)
        {
            IList<XmlProcessingError> xmlProcessingErrors = compiler.GetErrorList();
            Console.WriteLine("Stylesheet compilation failed with " + xmlProcessingErrors.Count + " errors");
            for (int i = 0; i <= xmlProcessingErrors.Count - 1; i++)
            {
                Console.WriteLine("Stylesheet compilation failed with " + xmlProcessingErrors.Count + " errors");
            }
        }

I really hope that it is okay to ask this question in this forum. The main reason is that I am new to Saxon - and I want to validate a xml-file against a xslt-file. Maybe it is not the right way to do the coding - but honestly, I do not know how to do it :-(

Thanks in advance.

Regards Michael


Files

MCE-Invoice.xml (277 KB) MCE-Invoice.xml Michael Eriksen, 2023-12-21 15:13
OIOUBL_Invoice_Schematron.xsl (2.06 MB) OIOUBL_Invoice_Schematron.xsl Michael Eriksen, 2023-12-21 15:14

Please register to edit this issue

Also available in: Atom PDF