public XslCompiledTransform XslTransforms;
XslTransforms = new XslCompiledTransform();
XslTransforms.Load(@"D:DocEditorMicrosoft OfficeOffice14MML2OMML.xsl");
// The MML2OMML.xsl file is located under
// %ProgramFiles%Microsoft OfficeOffice12
/// <summary>
/// 获取键值hash
/// </summary>
/// <param name="Docurl"></param>
/// <param name="MathMl"></param>
/// <returns></returns>
public IDictionary<String,OpenXmlElement> GetOMMLHash(IDictionary<string, string> MathML)
{
IDictionary<String, OpenXmlElement> Currentresult=new Dictionary<string,OpenXmlElement>();
foreach (var MMLname in MathML.Keys)
{
// Load the file containing your MathML presentation markup.
using (XmlReader reader = XmlReader.Create(new StringReader(MathML[MMLname])))
{
using (MemoryStream ms = new MemoryStream())
{
XmlWriterSettings settings = XslTransforms.OutputSettings.Clone();
// Configure xml writer to omit xml declaration.
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.OmitXmlDeclaration = true;
XmlWriter xw = XmlWriter.Create(ms, settings);
// Transform our MathML to OfficeMathML
XslTransforms.Transform(reader, xw);
ms.Seek(0, SeekOrigin.Begin);
StreamReader sr = new StreamReader(ms, Encoding.UTF8);
string officeML = sr.ReadToEnd();
// Create a OfficeMath instance from the
// OfficeMathML xml.
DocumentFormat.OpenXml.Math.OfficeMath omml = new DocumentFormat.OpenXml.Math.OfficeMath(officeML);
Currentresult[MMLname] = omml;
}
}
}
return Currentresult;
}