Transform Large Document
Added by Burak Ozkan over 10 years ago
Hi all,
I want to transfom my xml file with xsl file. I am running exe file Transform.exe -s:data.xml -xsl:data.xsl -o:data.csv, My xsl file template;
My xml file is;
I got this .csv file
I attached 3 file. Can give any solution for my problem?
Thanks all,
Replies (3)
Please register to reply
RE: Transform Large Document - Added by Michael Kay over 10 years ago
Since you have no JournalList element in the output, it suggests you haven't invoked template "main". I suspect you are invoking the transformation incorrectly. The arguments you need on the command line are
-it:main -xsl:data.xsl
RE: Transform Large Document - Added by Burak Ozkan over 10 years ago
Thanks Michael,
I did it with your solution so how can i do it via API?
My sample c# code is;
Main.cs
var schematron = new Schematron.Schematron(); schematron.Validate(xml, schema)
Schematron.cs
private bool Validate(Stream xmlstream, Stream schematronstream) { Uri schematronxsl = new Uri(@"file:\\xsl_2.0\iso_svrl_for_xslt2.xsl"); Stream schematrontransform = new Schematron.XSLTransform().Transform(schematronstream, schematronxsl); /////////////////////////////////////////////////// /// Do I need one more transform for streaming??? /////////////////////////////////////////////////// Stream results = new Schematron.XSLTransform().Transform(xmlstream, schematrontransform); return true; }
Transform.cs
public Stream Transform(Stream xmlstream, Uri xsluri) { Processor processor = new Processor(); var documentbuilder = processor.NewDocumentBuilder(); documentbuilder.BaseUri = new Uri("file://c:/"); XdmNode input = documentbuilder.Build(xmlstream); // Create a transformer for the stylesheet. var compiler = processor.NewXsltCompiler(); compiler.ErrorList = new System.Collections.Generic.List(); XsltTransformer transformer = compiler.Compile(xsluri).Load(); if (compiler.ErrorList.Count != 0) throw new Exception("Exception loading xsl!"); // 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 results = new MemoryStream(); serializer.SetOutputStream(results); // Transform the source XML to System.out. transformer.Run(serializer); return results; }
RE: Transform Large Document - Added by Michael Kay over 10 years ago
Don't set the InitialContextItem on the Transformer. Instead, set the InitialTemplateName property to the QName of the initial template.
Please register to reply