我正在运行此代码:
string path = AppDomain.CurrentDomain.BaseDirectory;
// Uri schemaUri = new Uri(@"file:\\" + path + @"\sch\patient.sch");
Uri totransformEE = new Uri(@"file:\\" + path + @"\po\po-schema.sch");
Uri transformER = new Uri(@"file:\\" + path + @"\xsl\conformance1-5.xsl");
///////////////////////////////
// Crate Schemtron xslt to be applied
///////////////////////////////
// Create a Processor instance.
Processor processor = new Processor();
// Load the source document
XdmNode input = processor.NewDocumentBuilder().Build(totransformEE);
// Create a transformer for the stylesheet.
XsltTransformer transformer = processor.NewXsltCompiler().Compile(transformER).Load();
// Set the root node of the source document to be the initial context node
transformer.InitialContextNode = input;
// Create a serializer
Serializer serializer = new Serializer();
MemoryStream st = new MemoryStream();
serializer.SetOutputStream(st);
// Transform the source XML to System.out.
transformer.Run(serializer);
st.Position = 0;
System.IO.StreamReader rd = new System.IO.StreamReader(st);
string xsltSchematronStylesheet = rd.ReadToEnd();
System.Diagnostics.Debug.WriteLine(xsltSchematronStylesheet);
// Load the source document
Uri transformEE2 = new Uri(@"file:\\" + path + @"\po\po-bad.xml");
var documentbuilder2 = processor.NewDocumentBuilder();
XdmNode input2 = documentbuilder2.Build(transformEE2);
////// Create a transformer for the stylesheet.
StringReader sr2 = new StringReader(xsltSchematronStylesheet);
XsltTransformer transformer2 = processor.NewXsltCompiler().Compile(sr2).Load();
// Set the root node of the source document to be the initial context node
transformer2.InitialContextNode = input2;
// Create a serializer
Serializer serializer2 = new Serializer();
MemoryStream st2 = new MemoryStream();
serializer.SetOutputStream(st2);
transformer2.MessageListener = new MyMessageListener();
// Transform the source XML to System.out.
transformer2.Run(serializer2);
st2.Position = 0;
System.IO.StreamReader rd2 = new System.IO.StreamReader(st2);
string xsltSchematronResult = rd2.ReadToEnd();
System.Diagnostics.Debug.WriteLine(xsltSchematronResult);
在检查 xsltSchematronStylesheet 时,我得到了一个 XSLT 文件。然而,st2 末尾的流的长度为 0。此外, MyMessageListener.Message 没有收到任何呼叫(我使用了断点)。
我不确定我是否有错误的代码、错误的示例文件等。我相信我的示例文件是正确的,但也许我有错误的文件或遗漏了一些。
有谁知道为什么没有数据返回到流 st2。如果不能,你能指导我找到一个包含所有文件和作品的简单示例吗?