0

我可以访问 Schematron xsl 文件和 Schematron sch 文件。如何使用 C# 将其转换为 XSLT 样式表?

xsl + sch --> [???XSLT 处理器 ??? ] --> xslt 样式表

4

1 回答 1

0

回答我自己的问题......这很有效,不幸的是,Schematron 文件只支持使用 XslCompiledTransform 的非常简单的语法。到 SAXON 看看它的工作原理:(

        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();
于 2014-02-27T05:20:56.820 回答