private static Saxon.Api.XsltTransformer LoadXsltDataInTransformer(Saxon.Api.XsltCompiler xslt, Stream stream) { XmlReader xml = XmlReader.Create(stream); xslt.BaseUri = new Uri(string.IsNullOrEmpty(xml.BaseURI) ? "http://NOT.SET" : xml.BaseURI); Saxon.Api.XsltExecutable executable = xslt.Compile(xml); Saxon.Api.XsltTransformer transformer = executable.Load(); return(transformer); }
private string TransformRecord(string stext, string sXSLT) { //use Saxon; which will be installed with MarcEdit; to allow xslt 1, 2, and 3 System.IO.StringReader sreader = new System.IO.StringReader(stext); System.Xml.XmlReader xreader = System.Xml.XmlReader.Create(sreader); Saxon.Api.Processor processor = new Saxon.Api.Processor(); Saxon.Api.XsltCompiler xsltCompiler = processor.NewXsltCompiler(); Saxon.Api.XdmNode input = processor.NewDocumentBuilder().Build(xreader); // Create a transformer for the stylesheet. Saxon.Api.XsltTransformer transformer = null; if (System.IO.File.Exists(sXSLT)) { System.IO.FileStream xstream = new System.IO.FileStream(sXSLT, System.IO.FileMode.Open); xsltCompiler.BaseUri = new Uri(System.IO.Path.GetDirectoryName(sXSLT) + System.IO.Path.DirectorySeparatorChar.ToString(), UriKind.Absolute); transformer = xsltCompiler.Compile(xstream).Load(); } else { lbStatus.Text = "ERROR applying the cutom rules file"; return(""); } // Set the root node of the source document to be the initial context node transformer.InitialContextNode = input; // Create a serializer Saxon.Api.Serializer serializer = new Saxon.Api.Serializer(); System.IO.TextWriter stringWriter = new System.IO.StringWriter(); serializer.SetOutputWriter(stringWriter); transformer.Run(serializer); string tmp = stringWriter.ToString(); //System.Windows.Forms.MessageBox.Show(tmp); //****Remove these lines because all the white space was being removed on translation*** //System.Text.RegularExpressions.Regex objRegEx = new System.Text.RegularExpressions.Regex(@"\n +=LDR ", System.Text.RegularExpressions.RegexOptions.None); //tmp = objRegEx.Replace(tmp, "\n" + @"=LDR "); return(tmp); }