public async Task <string> ConvertXml2Html(string OriginalxmlFile, string ToLanguage) { string translatedXSLT = ""; if (FileExistsInBlob(ToLanguage + "-stylesheet-ubl.xslt")) { translatedXSLT = DownloadFileFromBlob(ToLanguage + "-stylesheet-ubl.xslt"); } else { string originalxsltFile = DownloadFileFromBlob("stylesheet-ubl v2.xslt"); string labels2Translate = DownloadFileFromBlob("Labels2Translate.txt"); translatedXSLT = await GetXsltTranslated4Labels(originalxsltFile, ToLanguage, "English", labels2Translate); translatedXSLT = await GetXsltTranslated4CountryID(OriginalxmlFile, translatedXSLT, ToLanguage); UploadFileToBlob(translatedXSLT, ToLanguage + "-stylesheet-ubl.xslt" /*, connectionString, containerName*/); //File.WriteAllText(ToLanguage + "-stylesheet-ubl.xslt", result); } string translatedXmlNote = await GetXmlTranslated4Note(OriginalxmlFile, ToLanguage, "English"); string translatedXmlNames = await GetXmlTranslated4Names(translatedXmlNote, ToLanguage, "English"); UploadFileToBlob(translatedXmlNames, ToLanguage + "TranslatedFile.xml" /*, connectionString, containerName*/); // File.WriteAllText(ToLanguage + "-" + "TranslatedFile.xml", translatedXmlNames); string HTMLstring = new XSLTLibrary.SaxonUtils().Transform(GenerateStreamFromString(translatedXmlNames), GenerateStreamFromString(translatedXSLT));// "";// XSLThelper.SaxonTransform(ToLanguage + "-stylesheet-ubl.xslt", ToLanguage + "-" + FileName); // get rid of the xslt bugs HTMLstring = HTMLstring.Replace("<div class=\"col-md-5\" />", ""); HTMLstring = HTMLstring.Replace("<div class=\"col-sm-4\" />", ""); HTMLstring = HTMLstring.Replace("<div />", ""); HTMLstring = HTMLstring.Replace("style=\"width: 20%;\"", "class=\"text-right\""); HTMLstring = HTMLstring.Replace("linesupport{background-color:#eee", "linesupport{"); HTMLstring = HTMLstring.Replace("<div class=\"col-sm-9\">Price</div>", ""); return(HTMLstring); }
public void TestSaxonTransform() { string xsltFilePath = @"..\..\..\MSTranslatordemo\stylesheet-ubl v2.xslt"; string xmlFilePath = @"..\..\..\MSTranslatordemo\cleaning services.xml"; MemoryStream xsltStream = new MemoryStream(); using (FileStream fileStream = File.OpenRead(xsltFilePath)) { xsltStream.SetLength(fileStream.Length); fileStream.Read(xsltStream.GetBuffer(), 0, (int)fileStream.Length); } MemoryStream xmlStream = new MemoryStream(); using (FileStream fileStream = File.OpenRead(xmlFilePath)) { xmlStream.SetLength(fileStream.Length); fileStream.Read(xmlStream.GetBuffer(), 0, (int)fileStream.Length); } //string htmlstring = LanguageService.XSLThelper.SaxonTransform(xsltFilePath, xmlFilePath); string htmlstring = new XSLTLibrary.SaxonUtils().Transform(xmlStream, xsltStream); Assert.AreEqual("<html", htmlstring.Substring(0, 5)); }