Project

Profile

Help

Schematron/Xslt compiler/parser in .Net

Added by Mårten Sörliden over 4 years ago

I have made a schema compiler that builds an object model in primary memory that encapsulate the schema objects (element, attribute, choice, sequence, ...) using Microsoft System.Xml.Schema in .Net.

I now would like to complement the schema compiler with a schematron compiler. I have schematron files in both xslt (xsl:stylesheet) and schematron (schema xmlns="http://purl.oclc.org/dsdl/schematron" schemaVersion="iso"). These files have references to some code lists (gc:CodeList). I want to get all the validation information from these files into my object model by compiling/parsing the schematron.

I have started to look at Saxon-HE. But it seems to be useful for xml validation only. Can Saxon-PE or Saxon-EE maybe do the work?

Any suggestions of a schematron environment to choose to help me in this work is appreciated. Any sample code would also be very helpful.


Replies (7)

Please register to reply

RE: Schematron/Xslt compiler/parser in .Net - Added by Michael Kay over 4 years ago

I'm not optimistic that you'll get a useful reply unless you can express your requirements in more concrete terms. You say "I want to get all the validation information from these files into my object model by compiling/parsing the schematron". It would be good to have a more detailed description of what kind of transformation is involved here: what are the inputs and outputs, and what's the algorithm for generating the outputs from the inputs? Only when we know that can we examine the question of whether a particular tool is appropriate for the job.

The Saxon schema validator produces an XML representation of schema components in an SCM file. If you're aiming to use XML-based technologies to manipulate schema components, then that representation might be a better starting point than a collection of C# objects.

Even then, there are some significant difficulties. Schematron validation rules are defined against match patterns, and I've no idea how you correlate these match patterns with element declarations in the schema. If you know what the rules are, then implementing them in XSLT shouldn't be difficult; but I've no idea how you go about defining the rules.

RE: Schematron/Xslt compiler/parser in .Net - Added by Mårten Sörliden over 4 years ago

  • I want help to loop through every rule and maybe get the rule information in a little bit more comprehensible format. My object model support XPaths. When needed I want to connect dependent object (e.g. date1 < date2).
  • I want to provide element objects that are dependent on a code list with a compiled value list from the gc files.
  • My goal is to write the compiler/parser as generic as possible but I understand that I might not be able to support all types of schematron dependencies.

I'm not aiming at manipulating the schema. It's provided by an external party.

When I have the object model it will be used to create valid xml documents. The object model will also be used to create a dynamic form UI that stores the data in xml documents and make sure all input is valid.

RE: Schematron/Xslt compiler/parser in .Net - Added by Mårten Sörliden over 4 years ago

I'm testing Saxon-HE and create an XsltExecutable with this code:

            var processor = new Processor();
            var compiler = processor.NewXsltCompiler();
            var executable = compiler.Compile(new Uri(Path.Combine(Environment.CurrentDirectory, $"{formGroupUri}\\{xsltFile}")));

Is there any way to loop through all the templates and sub objects?

RE: Schematron/Xslt compiler/parser in .Net - Added by Michael Kay over 4 years ago

Sure, but you'll need to be prepared to hack a path into the jungle.

Start with

PreparedStylesheet pss = executable.getUnderlyingCompiledStylesheet()

then pss.getRuleManager()

then ruleManager.getDefaultMode() or ruleManager.getMode(name)

then mode.processRules(rule -> (your code here))

RE: Schematron/Xslt compiler/parser in .Net - Added by Mårten Sörliden over 4 years ago

Yes, I'm prepared. Thank you very much!

RE: Schematron/Xslt compiler/parser in .Net - Added by Mårten Sörliden over 4 years ago

'XsltExecutable' does not contain a definition for 'getUnderlyingCompiledStylesheet' and no accessible extension method 'getUnderlyingCompiledStylesheet'. I'm using Saxon-HE 9.9.1.7 in .Net. Do I need another Saxon version or is this method only available in Java?

RE: Schematron/Xslt compiler/parser in .Net - Added by O'Neil Delpratt over 4 years ago

Hi,

On .NET the XsltExecutable class has a property name Implementation which gives you the underlying Java implementation XsltExecutable. From there you can get to the Compiledstylesheet and other internal objects.

    (1-7/7)

    Please register to reply