示例#1
0
        public XsltExecutable Compile(Stream module, XsltCompileOptions options)
        {
            XsltCompiler compiler = CreateCompiler(options);

             try {
            return WrapExecutable(compiler.Compile(module), options, default(Uri));
             } catch (Exception ex) {
            throw WrapCompileException(ex, compiler);
             }
        }
示例#2
0
        public XsltExecutable Compile(XmlReader module, XsltCompileOptions options)
        {
            XslCompiledTransform transform = CreateTransform();

             try {
            transform.Load(module, this.Settings, options.XmlResolver);
             } catch (XsltException ex) {
            throw new SystemXsltException(ex);
             }

             return CreateExecutable(transform, options, module.BaseURI);
        }
示例#3
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();

             if (nav.NodeType != XPathNodeType.Root) {
            throw new ArgumentException("The schema must be a document node.", "schemaDoc");
             }

             string queryBinding = nav.GetAttribute("queryBinding", "");
             decimal procXsltVersion = processor.GetXsltVersion();

             string xsltVersion;

             if (String.IsNullOrEmpty(queryBinding)) {

            int maxMajorVersion = (procXsltVersion >= 3m) ? 2
               : (int)Decimal.Floor(procXsltVersion);

            xsltVersion = "xslt" + maxMajorVersion.ToStringInvariant();

             } else {

            string qbLower = queryBinding.ToLowerInvariant();

            switch (qbLower) {
               case "xslt":
               case "xslt1":
               case "xpath":
               case "xpath1":
                  xsltVersion = "xslt1";
                  break;

               case "xslt2":
               case "xpath2":

                  if (procXsltVersion < 2) {
                     throw new ArgumentException(
                        "The queryBinding '{0}' is not supported by this processor. Lower the language version or use a different processor.".FormatInvariant(queryBinding),
                        "schemaDoc"
                     );
                  }

                  xsltVersion = "xslt2";
                  break;

               default:
                  throw new ArgumentException(
                     "The queryBinding '{0}' is not supported. Valid values are: {1}.".FormatInvariant(queryBinding, String.Join(", ", GetQueryBindings())),
                     "schemaDoc"
                  );
            }
             }

             Assembly assembly = Assembly.GetExecutingAssembly();

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

             var compileOptions = new XsltCompileOptions(baseUri) {
            XmlResolver = new XmlDynamicResolver() // use calling assembly as default
             };

             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++) {

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

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

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

               var runtimeOptions = new XsltRuntimeOptions {
                  InitialContextNode = input,
                  InputXmlResolver = compileOptions.XmlResolver
               };

               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);
               }
            }
             }
        }
示例#4
0
        public static SchematronValidator CreateSchematronValidator(this IXsltProcessor processor, IXPathNavigable schemaDoc)
        {
            if (processor == null) throw new ArgumentNullException("processor");
             if (schemaDoc == null) throw new ArgumentNullException("schemaDoc");

             IXPathNavigable stylesheetDoc = processor.ItemFactory.BuildNode();

             XmlWriter builder = stylesheetDoc.CreateNavigator().AppendChild();

             processor.BuildSchematronValidatorStylesheet(schemaDoc, builder);

             builder.Close();

             var compileOptions = new XsltCompileOptions();

             XPathNavigator schemaNav = schemaDoc.CreateNavigator();

             if (!String.IsNullOrEmpty(schemaNav.BaseURI)) {
            compileOptions.BaseUri = new Uri(schemaNav.BaseURI);
             }

             return new XsltSchematronValidator(processor.Compile(stylesheetDoc, compileOptions));
        }
示例#5
0
        public XsltExecutable Compile(IXPathNavigable module, XsltCompileOptions options)
        {
            XslCompiledTransform transform = CreateTransform();

             XPathNavigator nav = module.CreateNavigator();

             try {
            transform.Load(nav, this.Settings, options.XmlResolver);
             } catch (XsltException ex) {
            throw new SystemXsltException(ex);
             }

             return CreateExecutable(transform, options, nav.BaseURI);
        }
示例#6
0
 public XsltExecutable Compile(TextReader module, XsltCompileOptions options)
 {
     return Compile(this.ItemFactory.CreateNodeReadOnly(module, new XmlParsingOptions { BaseUri = options.BaseUri, XmlResolver = options.XmlResolver }), options);
 }
示例#7
0
 XsltExecutable CreateExecutable(XslCompiledTransform transform, XsltCompileOptions options, Uri baseUri)
 {
     return new SystemXsltExecutable(transform, this, baseUri ?? options.BaseUri);
 }
示例#8
0
        XsltExecutable CreateExecutable(XslCompiledTransform transform, XsltCompileOptions options, string baseUri)
        {
            Uri parsedBaseUri = null;

             if (!String.IsNullOrEmpty(baseUri)) {
            try {
               parsedBaseUri = new Uri(baseUri);
            } catch (UriFormatException) { }
             }

             return CreateExecutable(transform, options, parsedBaseUri);
        }
示例#9
0
 XsltExecutable WrapExecutable(SaxonApiXsltExecutable xsltExecutable, XsltCompileOptions options, Uri baseUri)
 {
     return new SaxonXsltExecutable(xsltExecutable, this, baseUri ?? options.BaseUri);
 }
示例#10
0
        XsltExecutable WrapExecutable(SaxonApiXsltExecutable xsltExecutable, XsltCompileOptions options, string baseUri)
        {
            Uri parsedBaseUri = null;

             if (!String.IsNullOrEmpty(baseUri)) {
            try {
               parsedBaseUri = new Uri(baseUri);
            } catch (UriFormatException) { }
             }

             return WrapExecutable(xsltExecutable, options, parsedBaseUri);
        }
示例#11
0
        XsltCompiler CreateCompiler(XsltCompileOptions options)
        {
            XsltCompiler compiler = this.processor.NewXsltCompiler();
             compiler.ErrorList = new ArrayList();
             compiler.BaseUri = options.BaseUri;

             if (options.XmlResolver != null) {
            compiler.XmlResolver = options.XmlResolver;
             }

             return compiler;
        }
示例#12
0
        public XsltExecutable Compile(IXPathNavigable module, XsltCompileOptions options)
        {
            XsltCompiler compiler = CreateCompiler(options);

             XPathNavigator nav = module.CreateNavigator();
             XdmNode node;

             if (SaxonExtensions.TryGetXdmNode(nav, out node)) {

            Uri baseUri = null;

            try {
               baseUri = node.BaseUri;
            } catch (ArgumentNullException) {
            } catch (UriFormatException) { }

            try {
               return WrapExecutable(compiler.Compile(node), options, baseUri);
            } catch (Exception ex) {
               throw WrapCompileException(ex, compiler);
            }
             } else {
            return Compile(nav.ReadSubtree(), options);
             }
        }
示例#13
0
        public XsltExecutable Compile(XmlReader module, XsltCompileOptions options)
        {
            XsltCompiler compiler = CreateCompiler(options);

             string baseUri = module.BaseURI;

             try {
            return WrapExecutable(compiler.Compile(module), options, baseUri);
             } catch (Exception ex) {
            throw WrapCompileException(ex, compiler);
             }
        }