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))); }
internal static XsltInvoker With(IXPathNavigable stylesheet, IXsltProcessor processor, Assembly callingAssembly, out int hashCode) { if (stylesheet == null) { throw new ArgumentNullException("stylesheet"); } if (processor == null) { processor = Processors.Xslt.DefaultProcessor; } hashCode = XPathNavigatorEqualityComparer.Instance.GetHashCode(stylesheet.CreateNavigator()); ConcurrentDictionary <int, XsltExecutable> cache = inlineCache.GetOrAdd(processor, p => new ConcurrentDictionary <int, XsltExecutable>()); XsltExecutable exec = cache.GetOrAdd(hashCode, i => { var resolver = new XmlDynamicResolver(callingAssembly); return(processor.Compile(stylesheet, new XsltCompileOptions { XmlResolver = resolver })); }); return(new XsltInvoker(exec, callingAssembly)); }
public static decimal GetXsltVersion(this IXsltProcessor processor) { return(versions.GetOrAdd(processor, p => { string stylesheet = @"<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:output method='text'/> <xsl:template match='/' name='main'> <xsl:value-of select=""system-property('xsl:version')""/> </xsl:template> </xsl:stylesheet>"; using (var writer = new StringWriter(CultureInfo.InvariantCulture)) { processor .Compile(new StringReader(stylesheet), new XsltCompileOptions()) .Run(writer, new XsltRuntimeOptions { InitialTemplate = new XmlQualifiedName("main"), Serialization = { Method = XPathSerializationMethods.Text } }); return Decimal.Parse(writer.ToString(), CultureInfo.InvariantCulture); } })); }
static XsltInvoker With(Uri stylesheetUri, IXsltProcessor processor, Assembly callingAssembly) { if (stylesheetUri == null) { throw new ArgumentNullException("stylesheetUri"); } var resolver = new XmlDynamicResolver(callingAssembly); if (!stylesheetUri.IsAbsoluteUri) { stylesheetUri = resolver.ResolveUri(null, stylesheetUri.OriginalString); } if (processor == null) { processor = Processors.Xslt.DefaultProcessor; } ConcurrentDictionary <Uri, XsltExecutable> cache = uriCache.GetOrAdd(processor, p => new ConcurrentDictionary <Uri, XsltExecutable>()); XsltExecutable executable = cache.GetOrAdd(stylesheetUri, u => { using (var stylesheetSource = (Stream)resolver.GetEntity(stylesheetUri, null, typeof(Stream))) { return(processor.Compile(stylesheetSource, new XsltCompileOptions { BaseUri = stylesheetUri, XmlResolver = resolver })); } }); return(new XsltInvoker(executable, callingAssembly)); }
public void OnInstructionExecute(IXsltProcessor xsltProcessor) { if (_onExecute != null) { _onExecute.Invoke(_unknownDebugger, new object[] { xsltProcessor }); } }
static SchematronInvoker With(Uri schemaUri, IXsltProcessor processor, Assembly callingAssembly) { if (schemaUri == null) { throw new ArgumentNullException("schemaUri"); } var resolver = new XmlDynamicResolver(callingAssembly); if (!schemaUri.IsAbsoluteUri) { schemaUri = resolver.ResolveUri(null, schemaUri.OriginalString); } if (processor == null) { processor = Processors.Xslt.DefaultProcessor; } ConcurrentDictionary <Uri, SchematronValidator> cache = uriCache.GetOrAdd(processor, p => new ConcurrentDictionary <Uri, SchematronValidator>()); SchematronValidator validator = cache.GetOrAdd(schemaUri, u => { using (var schemaSource = (Stream)resolver.GetEntity(schemaUri, null, typeof(Stream))) { IXPathNavigable schemaDoc = processor.ItemFactory.CreateNodeReadOnly(schemaSource, new XmlParsingOptions { BaseUri = schemaUri, XmlResolver = resolver }); return(processor.CreateSchematronValidator(schemaDoc)); } }); return(new SchematronInvoker(validator, resolver)); }
internal static XsltInvoker With(int stylesheetHashCode, IXsltProcessor processor) { if (processor == null) { processor = Processors.Xslt.DefaultProcessor; } return(new XsltInvoker(inlineCache[processor][stylesheetHashCode], null)); }
public XPathItem Compile(XPathItem stylesheet, string processor) { CompiledStylesheetReference reference; if (stylesheet.IsNode) { IXsltProcessor proc = (processor != null) ? Processors.Xslt[processor] : this.CurrentXsltProcessor ?? Processors.Xslt.DefaultProcessor; int hashCode; XsltInvoker.With((XPathNavigator)stylesheet, proc, null, out hashCode); if (processor == null) { return(this.ItemFactory.CreateAtomicValue(hashCode, XmlTypeCode.Integer)); } reference = new CompiledStylesheetReference { HashCode = hashCode, Processor = processor }; } else { Uri stylesheetUri = StylesheetAsUri(stylesheet); if (processor == null || processor == Processors.Xslt.Default) { return(this.ItemFactory.CreateAtomicValue(stylesheetUri.ToString(), XmlTypeCode.String)); } XsltInvoker.With(stylesheetUri, processor); reference = new CompiledStylesheetReference { Uri = stylesheetUri.AbsoluteUri, Processor = processor }; } return(this.ItemFactory .CreateDocument(reference) .CreateNavigator()); }
public override void GenerateCode(AssemblyBuilder assemblyBuilder) { base.GenerateCode(assemblyBuilder); // test compilation XsltPageParser pageParser = (XsltPageParser)this.Parser; IXsltProcessor proc = Processors.Xslt[pageParser.ProcessorName]; using (Stream source = OpenStream(pageParser.XsltVirtualPath)) { try { proc.Compile(source, new XsltCompileOptions(baseUri: pageParser.XsltPhysicalUri)); } catch (ProcessorException ex) { throw CreateCompileException(ex); } } }
static SchematronInvoker With(IXPathNavigable schema, IXsltProcessor processor, Assembly callingAssembly) { if (schema == null) { throw new ArgumentNullException("schema"); } if (processor == null) { processor = Processors.Xslt.DefaultProcessor; } int hashCode = XPathNavigatorEqualityComparer.Instance.GetHashCode(schema.CreateNavigator()); ConcurrentDictionary <int, SchematronValidator> cache = inlineCache.GetOrAdd(processor, p => new ConcurrentDictionary <int, SchematronValidator>()); SchematronValidator validator = cache.GetOrAdd(hashCode, i => processor.CreateSchematronValidator(schema)); var resolver = new XmlDynamicResolver(callingAssembly); return(new SchematronInvoker(validator, resolver)); }
static SchematronInvoker With(Uri schemaUri, IXsltProcessor processor, Assembly callingAssembly) { if (schemaUri == null) throw new ArgumentNullException("schemaUri"); var resolver = new XmlDynamicResolver(callingAssembly); if (!schemaUri.IsAbsoluteUri) { schemaUri = resolver.ResolveUri(null, schemaUri.OriginalString); } if (processor == null) { processor = Processors.Xslt.DefaultProcessor; } ConcurrentDictionary<Uri, SchematronValidator> cache = uriCache.GetOrAdd(processor, p => new ConcurrentDictionary<Uri, SchematronValidator>()); SchematronValidator validator = cache.GetOrAdd(schemaUri, u => { using (var schemaSource = (Stream)resolver.GetEntity(schemaUri, null, typeof(Stream))) { IXPathNavigable schemaDoc = processor.ItemFactory.CreateNodeReadOnly(schemaSource, new XmlParsingOptions { BaseUri = schemaUri, XmlResolver = resolver }); return processor.CreateSchematronValidator(schemaDoc); } }); return new SchematronInvoker(validator, resolver); }
public static XsltInvoker With(Uri stylesheetUri, IXsltProcessor processor) { return(With(stylesheetUri, processor, Assembly.GetCallingAssembly())); }
static XsltInvoker With(string stylesheetUri, IXsltProcessor processor, Assembly callingAssembly) { return(With(new Uri(stylesheetUri, UriKind.RelativeOrAbsolute), processor, callingAssembly)); }
static SchematronInvoker With(IXPathNavigable schema, IXsltProcessor processor, Assembly callingAssembly) { if (schema == null) throw new ArgumentNullException("schema"); if (processor == null) { processor = Processors.Xslt.DefaultProcessor; } int hashCode = XPathNavigatorEqualityComparer.Instance.GetHashCode(schema.CreateNavigator()); ConcurrentDictionary<int, SchematronValidator> cache = inlineCache.GetOrAdd(processor, p => new ConcurrentDictionary<int, SchematronValidator>()); SchematronValidator validator = cache.GetOrAdd(hashCode, i => processor.CreateSchematronValidator(schema)); var resolver = new XmlDynamicResolver(callingAssembly); return new SchematronInvoker(validator, resolver); }
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); } } } }
static XsltInvoker With(Uri stylesheetUri, IXsltProcessor processor, Assembly callingAssembly) { if (stylesheetUri == null) throw new ArgumentNullException("stylesheetUri"); var resolver = new XmlDynamicResolver(callingAssembly); if (!stylesheetUri.IsAbsoluteUri) { stylesheetUri = resolver.ResolveUri(null, stylesheetUri.OriginalString); } if (processor == null) { processor = Processors.Xslt.DefaultProcessor; } ConcurrentDictionary<Uri, XsltExecutable> cache = uriCache.GetOrAdd(processor, p => new ConcurrentDictionary<Uri, XsltExecutable>()); XsltExecutable executable = cache.GetOrAdd(stylesheetUri, u => { using (var stylesheetSource = (Stream)resolver.GetEntity(stylesheetUri, null, typeof(Stream))) { return processor.Compile(stylesheetSource, new XsltCompileOptions { BaseUri = stylesheetUri, XmlResolver = resolver }); } }); return new XsltInvoker(executable, callingAssembly); }
internal static XsltInvoker With(int stylesheetHashCode, IXsltProcessor processor) { if (processor == null) { processor = Processors.Xslt.DefaultProcessor; } return new XsltInvoker(inlineCache[processor][stylesheetHashCode], null); }
public static SchematronInvoker With(IXPathNavigable schema, IXsltProcessor processor) { return With(schema, processor, Assembly.GetCallingAssembly()); }
public static XsltInvoker With(Uri stylesheetUri, IXsltProcessor processor) { return With(stylesheetUri, processor, Assembly.GetCallingAssembly()); }
public static SchematronInvoker With(Uri schemaUri, IXsltProcessor processor) { return(With(schemaUri, processor, Assembly.GetCallingAssembly())); }
static SchematronInvoker With(string schemaUri, IXsltProcessor processor, Assembly callingAssembly) { return(With(new Uri(schemaUri, UriKind.RelativeOrAbsolute), processor, callingAssembly)); }
public static SchematronInvoker With(IXPathNavigable schema, IXsltProcessor processor) { return(With(schema, processor, Assembly.GetCallingAssembly())); }
static SchematronInvoker With(string schemaUri, IXsltProcessor processor, Assembly callingAssembly) { return With(new Uri(schemaUri, UriKind.RelativeOrAbsolute), processor, callingAssembly); }
public static XsltInvoker With(IXPathNavigable stylesheet, IXsltProcessor processor) { return(With(stylesheet, processor, Assembly.GetCallingAssembly())); }
internal static XsltInvoker With(IXPathNavigable stylesheet, IXsltProcessor processor, Assembly callingAssembly, out int hashCode) { if (stylesheet == null) throw new ArgumentNullException("stylesheet"); if (processor == null) { processor = Processors.Xslt.DefaultProcessor; } hashCode = XPathNavigatorEqualityComparer.Instance.GetHashCode(stylesheet.CreateNavigator()); ConcurrentDictionary<int, XsltExecutable> cache = inlineCache.GetOrAdd(processor, p => new ConcurrentDictionary<int, XsltExecutable>()); XsltExecutable exec = cache.GetOrAdd(hashCode, i => { var resolver = new XmlDynamicResolver(callingAssembly); return processor.Compile(stylesheet, new XsltCompileOptions { XmlResolver = resolver }); }); return new XsltInvoker(exec, callingAssembly); }
static XsltInvoker With(IXPathNavigable stylesheet, IXsltProcessor processor, Assembly callingAssembly) { int hashCode; return(With(stylesheet, processor, callingAssembly, out hashCode)); }
static XsltInvoker With(string stylesheetUri, IXsltProcessor processor, Assembly callingAssembly) { return With(new Uri(stylesheetUri, UriKind.RelativeOrAbsolute), processor, callingAssembly); }
public static SchematronInvoker With(Uri schemaUri, IXsltProcessor processor) { return With(schemaUri, processor, Assembly.GetCallingAssembly()); }
static XsltInvoker With(IXPathNavigable stylesheet, IXsltProcessor processor, Assembly callingAssembly) { int hashCode; return With(stylesheet, processor, callingAssembly, out hashCode); }
XPathNavigator ExecuteStylesheet(XPathItem stylesheet, XsltRuntimeOptions options) { XsltInvoker invoker; IXsltProcessor currentOrDefaultProc = this.CurrentXsltProcessor ?? Processors.Xslt.DefaultProcessor; if (stylesheet.IsNode) { XPathNavigator node = ((XPathNavigator)stylesheet).Clone(); if (node.NodeType == XPathNodeType.Root) { node.MoveToChild(XPathNodeType.Element); } if (node.NodeType != XPathNodeType.Element) { throw new ArgumentException("if stylesheet is a node() it must be either a document-node(element()) or an element() node.", "stylesheet"); } if (node.NamespaceURI == Namespace) { XmlSerializer serializer = XPathItemFactory.GetSerializer(typeof(CompiledStylesheetReference)); var reference = (CompiledStylesheetReference)serializer.Deserialize(node.ReadSubtree()); IXsltProcessor specifiedProcessor = (reference.Processor != null) ? Processors.Xslt[reference.Processor] : null; invoker = (reference.HashCode > 0) ? XsltInvoker.With(reference.HashCode, specifiedProcessor ?? currentOrDefaultProc) : XsltInvoker.With(reference.Uri, specifiedProcessor); } else { invoker = XsltInvoker.With((XPathNavigator)stylesheet, currentOrDefaultProc); } } else { object value = stylesheet.TypedValue; if (value.GetType().IsPrimitive) { int hashCode = Convert.ToInt32(value, CultureInfo.InvariantCulture); invoker = XsltInvoker.With(hashCode, currentOrDefaultProc); } else { Uri stylesheetUri = StylesheetAsUri(stylesheet); invoker = XsltInvoker.With(stylesheetUri); } } return(invoker.Transform(options) .Result() .CreateNavigator()); }
public static XsltInvoker With(IXPathNavigable stylesheet, IXsltProcessor processor) { return With(stylesheet, processor, Assembly.GetCallingAssembly()); }
public void OnInstructionExecute(IXsltProcessor xsltProcessor) { if (_onExecute != null) { _onExecute.Invoke(_unknownDebugger, new object[] { xsltProcessor }); } }