Cemal Çelik
Cemal Çelik

Reputation: 11

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)
    {

    }

Upvotes: 0

Views: 35

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167716

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.

Upvotes: 0

Related Questions