0

I have access to Schematron xsl files and a Schematron sch file. How can I transform this into an XSLT stylesheet using C# ?

xsl + sch --> [??? XSLT Processor ??? ] --> xslt stylesheet

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
jlo-gmail
  • 4,453
  • 3
  • 37
  • 64

1 Answers1

0

To answer my own question... This works, unfortunately the Schematron files only support a very simple syntax using XslCompiledTransform. On to SAXON to see it that works :(

        string xmlFile = @"sch\patient.sch";
        string xslFile = @"xsl\conformance1-5.xsl";
        XslCompiledTransform xsltransform = new XslCompiledTransform();
        xsltransform.Load(xslFile);

        XmlDocument doc = new XmlDocument();
        doc.Load(xmlFile);
        XPathNavigator nav = doc.CreateNavigator();

        System.IO.MemoryStream st = new System.IO.MemoryStream();
        xsltransform.Transform(nav, null, st);
        st.Position = 0;
        System.IO.StreamReader rd = new System.IO.StreamReader(st);
        string xslt = rd.ReadToEnd();

        System.Diagnostics.Debug.WriteLine(xslt);

        XmlReader reader = XmlReader.Create(new System.IO.StringReader(xslt));
        xsltransform.Load(reader);

        var patient = PatientFactory.GeneratePatientBySOAPClasses();
        patient.identifier[0].period.end.value = DateTime.Now.ToString("yyyy-MM-dd");
        patient.identifier[0].period.start.value = DateTime.Now.AddYears(15).ToString("yyyy-MM-dd");
        patient.identifier[0].period.start = null;

        string xml = Serialization.SerializeXML(patient, "http://hl7.org/fhir");

        xml = xml.Replace("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://hl7.org/fhir\"", "");
        doc.LoadXml(xml);
        nav = doc.CreateNavigator();

        st = new System.IO.MemoryStream();
        xsltransform.Transform(nav, null, st);
        st.Position = 0;
        rd = new System.IO.StreamReader(st);
        string scematronresult = rd.ReadToEnd();
jlo-gmail
  • 4,453
  • 3
  • 37
  • 64