Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

base-uri function in Schematron compiled with schxslt and saxonCS

i have an xml file and .sch file to validate this xml file. But there are some rules calls <xsl:param name="dosyaAdi" select="base-uri()"/>. base-uri() function returns null and all the controls according to this function are failing.

I have compiled my sch file with schxslt’s compile-for-svrl.xsl Then I pass my xml and xslt to Saxon to transform. It transforms well. But I guess some how base-uri() function in sch returns null and 2 rules depending on it, fails. here is my code sample.

    string schxsltSvrlXsltResource = @"SchematronSchxsltSaxonCSValidator/schxslt195/compile-for-svrl.xsl";
    var schxsltResourceUri = UriUtils.GetLocationUri(schxsltSvrlXsltResource, Assembly.GetExecutingAssembly());

    var resolver = new Resolver();

    var settings = new XmlReaderSettings() { XmlResolver = resolver };

    var processor = new Processor(true);
    var xsltCompiler = processor.NewXsltCompiler();

    using var schxsltReader = XmlReader.Create(schxsltResourceUri.AbsoluteUri, settings);


    var transformer = xsltCompiler.Compile(schxsltReader).Load30();
    //var compiledSchxslt = xsltCompiler.Compile(schxsltReader).Load30();

    var compiledSchematron = new XdmDestination();
    compiledSchematron.BaseUri = new Uri(new FileInfo(inputSch).FullName);

    using var schemaStream = File.OpenRead(inputSch);

    transformer.Transform(schemaStream, compiledSchematron);

    var xsltCompiler2 = processor.NewXsltCompiler();

    var schematronValidator = xsltCompiler2.Compile(compiledSchematron.XdmNode).Load30();

    var svrlResult = new XdmDestination(); 
    using var instanceStream = File.OpenRead(inputXml);
    //schematronValidator.Run(svrlResult);
    schematronValidator.Transform(instanceStream, svrlResult);

    XmlDocument doc = new XmlDocument();
    doc.LoadXml(svrlResult.XdmNode.OuterXml);

    var failedNodes = doc.GetElementsByTagName("svrl:failed-assert");
    foreach (System.Xml.XmlNode node in failedNodes)
    {

    }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There is an overload of the Transform method https://www.saxonica.com/html/documentation12/dotnetdoc/Saxon/Api/Xslt30Transformer.html#Transform(Stream,Uri,IDestination) that allows you to set the base Uri so instead of

schematronValidator.Transform(instanceStream, svrlResult);

try

schematronValidator.Transform(instanceStream, new Uri(new FileInfo(inputXml).FullName),  svrlResult);

If that doesn’t work then consider to show a stack trace and the exact line where you get the error.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading