Exemple #1
0
      public static void BuildSchematronValidatorStylesheet(this IXsltProcessor processor, IXPathNavigable schemaDoc, XmlWriter output) {

         if (processor == null) throw new ArgumentNullException("processor");
         if (schemaDoc == null) throw new ArgumentNullException("schemaDoc");
         if (output == null) throw new ArgumentNullException("output");

         XPathNavigator nav = schemaDoc.CreateNavigator();
         nav.MoveToChild(XPathNodeType.Element);

         string queryBinding = nav.GetAttribute("queryBinding", "");

         string xsltVersion = String.IsNullOrEmpty(queryBinding)
            || queryBinding.Equals("xslt2", StringComparison.OrdinalIgnoreCase)
            || queryBinding.Equals("xpath2", StringComparison.OrdinalIgnoreCase) ? 
            "xslt2" : "xslt1";

         Assembly assembly = Assembly.GetExecutingAssembly();
         
         Uri baseUri = new UriBuilder {
            Scheme = XmlEmbeddedResourceResolver.UriSchemeClires,
            Host = null,
            Path = String.Concat(assembly.GetName().Name, "/schematron/", xsltVersion, "/")
         }.Uri;

         XsltCompileOptions compileOptions = new XsltCompileOptions();
         compileOptions.BaseUri = baseUri;

         string[] stages = { "iso_dsdl_include.xsl", "iso_abstract_expand.xsl", String.Concat("iso_svrl_for_", xsltVersion, ".xsl") };

         IXPathNavigable input = schemaDoc;

         for (int i = 0; i < stages.Length; i++) {

            Uri stageUri = new Uri(baseUri, stages[i]);

            using (Stream stageDoc = (Stream)compileOptions.XmlResolver.GetEntity(stageUri, null, typeof(Stream))) {

               XsltExecutable executable = processor.Compile(stageDoc, compileOptions);

               XsltRuntimeOptions runtimeOptions = new XsltRuntimeOptions {
                  InitialContextNode = input
               };

               if (i < stages.Length - 1) {
                  // output becomes the input for the next stage
                  input = executable.Run(runtimeOptions);
               } else {
                  // last stage is output to writer
                  executable.Run(output, runtimeOptions);
               }
            }
         }
      }
      public IXPathNavigable Validate(IXPathNavigable source, string phase, IEnumerable<XPathNavigator> parameters) {

         XsltExecutable exec = this.Executable;

         if (exec == null)
            throw new InvalidOperationException("Executable cannot be null");

         XsltRuntimeOptions runtimeContext = new XsltRuntimeOptions {
            InitialContextNode = source
         };

         if (!String.IsNullOrEmpty(phase))
            runtimeContext.Parameters.Add(new XmlQualifiedName("phase"), phase);

         if (parameters != null) {
            foreach (XPathNavigator p in parameters)
               runtimeContext.Parameters.Add(new XmlQualifiedName(p.Name, p.NamespaceURI), p.TypedValue);
         }

         IXPathNavigable result = exec.Run(runtimeContext);

         return result;
      }
Exemple #3
0
 public abstract IXPathNavigable Run(XsltRuntimeOptions options);
Exemple #4
0
 public abstract void Run(XmlWriter output, XsltRuntimeOptions options);
Exemple #5
0
 public abstract void Run(Stream output, XsltRuntimeOptions options);