prepare.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections;
  3. using System.IO;
  4. using System.Text;
  5. using System.Xml;
  6. using System.Xml.Xsl;
  7. namespace XsltTest
  8. {
  9. public class XsltTest
  10. {
  11. public static void Main ()
  12. {
  13. XmlDocument whole = new XmlDocument ();
  14. string xalan = @"testsuite/TESTS/Xalan_Conformance_Tests/";
  15. whole.Load (xalan + "catalog.xml");
  16. foreach (XmlElement testCase in whole.SelectNodes ("test-suite/test-catalog/test-case")) {
  17. string stylesheetBase = null;
  18. try {
  19. string filePath = testCase.SelectSingleNode ("file-path").InnerText;
  20. string path = xalan + filePath + "/";
  21. foreach (XmlElement scenario in testCase.SelectNodes ("scenario")) {
  22. XslTransform trans = new XslTransform ();
  23. stylesheetBase = scenario.SelectSingleNode ("input-file[@role='principal-stylesheet']").InnerText;
  24. string stylesheet = path + stylesheetBase;
  25. string srcxml = path + scenario.SelectSingleNode ("input-file[@role='principal-data']").InnerText;
  26. string outfile = path + scenario.SelectSingleNode ("output-file[@role='principal']").InnerText;
  27. XmlTextReader stylextr = new XmlTextReader (stylesheet);
  28. XmlValidatingReader stylexvr = new XmlValidatingReader (stylextr);
  29. XmlDocument styledoc = new XmlDocument ();
  30. styledoc.Load (stylesheet);
  31. trans.Load (stylesheet);
  32. // trans.Load (styledoc);
  33. XmlTextReader xtr = new XmlTextReader (srcxml);
  34. XmlValidatingReader xvr = new XmlValidatingReader (xtr);
  35. xvr.ValidationType = ValidationType.None;
  36. XmlDocument input = new XmlDocument ();
  37. input.Load (xvr);
  38. // input.Load (xtr);
  39. // XPathDocument input = new XPathDocument (xtr);
  40. StringWriter sw = new StringWriter ();
  41. trans.Transform (input, null, sw);
  42. sw.Close ();
  43. StreamWriter fw = new StreamWriter (outfile);
  44. fw.Write (sw.ToString ());
  45. fw.Close ();
  46. }
  47. } catch (Exception ex) {
  48. Console.WriteLine ("\n\n\nException: " + testCase.GetAttribute ("id") + ": " + ex);
  49. }
  50. }
  51. }
  52. }
  53. }