我可以访问Schematron xsl文件和Schematron sch文件。如何使用C#将其转换为XSLT样式表?
xsl + sch - > [??? XSLT处理器??? ] - > xslt stylesheet
答案 0 :(得分: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();