public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext) { string baseUri = null; if (args.Length == 2) { XPathNodeIterator it = ToIterator(args[1]); if (it.MoveNext()) { baseUri = it.Current.BaseURI; } else { // http://www.w3.org/1999/11/REC-xslt-19991116-errata (E14): // It is an error if the second argument node-set is empty and the URI reference is relative; the XSLT processor may signal the error; // if it does not signal an error, it must recover by returning an empty node-set. baseUri = string.Empty; // call to Document will fail if args[0] is reletive. } } try { return(((XsltCompileContext)xsltContext).Document(args[0], baseUri)); } catch (Exception e) { if (!XmlException.IsCatchableException(e)) { throw; } return(XPathEmptyIterator.Instance); } }
/// <summary> /// Trace ILGen optimizations and log them to "fileName". /// </summary> public static void TraceOptimizations(QilExpression qil, string fileName) { if (!IsEnabled) { return; } XmlWriter w = XmlWriter.Create(s_dirName + "\\" + fileName); w.WriteStartDocument(); w.WriteProcessingInstruction("xml-stylesheet", "href='qilo.xslt' type='text/xsl'"); w.WriteStartElement("QilOptimizer"); w.WriteAttributeString("timestamp", DateTime.Now.ToString(CultureInfo.InvariantCulture)); WriteQilRewrite(qil, w, null); try { // Then, rewrite the graph until "done" or some max value is reached. for (int i = 1; i < MAX_REWRITES; i++) { QilExpression qilTemp = (QilExpression)(new QilCloneVisitor(qil.Factory).Clone(qil)); XmlILOptimizerVisitor visitor = new XmlILOptimizerVisitor(qilTemp, !qilTemp.IsDebug); visitor.Threshold = i; qilTemp = visitor.Optimize(); // In debug code, ensure that QIL after N steps is correct QilValidationVisitor.Validate(qilTemp); // Trace the rewrite WriteQilRewrite(qilTemp, w, OptimizationToString(visitor.LastReplacement)); if (visitor.ReplacementCount < i) { break; } } } catch (Exception e) { if (!XmlException.IsCatchableException(e)) { throw; } w.WriteElementString("Exception", null, e.ToString()); throw; } finally { w.WriteEndElement(); w.WriteEndDocument(); w.Flush(); w.Close(); } }
/// <summary> /// Fetch the data source specified by "uriRelative" and "uriBase" from the XmlResolver that the user provided. /// If the resolver returns a stream or reader, create an instance of XPathDocument. If the resolver returns an /// XPathNavigator, return the navigator. Throw an exception if no data source was found. /// </summary> public XPathNavigator GetDataSource(string uriRelative, string uriBase) { object input; Uri uriResolvedBase, uriResolved; XPathNavigator nav = null; try { // If the data source has already been retrieved, then return the data source from the cache. uriResolvedBase = (uriBase != null) ? _dataSources.ResolveUri(null, uriBase) : null; uriResolved = _dataSources.ResolveUri(uriResolvedBase, uriRelative); if (uriResolved != null) { nav = _dataSourceCache[uriResolved] as XPathNavigator; } if (nav == null) { // Get the entity from the resolver and ensure it is cached as a document input = _dataSources.GetEntity(uriResolved, null, null); if (input != null) { // Construct a document from the entity and add the document to the cache nav = ConstructDocument(input, uriRelative, uriResolved); _dataSourceCache.Add(uriResolved, nav); } } } catch (XslTransformException) { // Don't need to wrap XslTransformException throw; } catch (Exception e) { if (!XmlException.IsCatchableException(e)) { throw; } throw new XslTransformException(e, SR.XmlIl_DocumentLoadError, uriRelative); } return(nav); }
/// <summary> /// Convert the incoming arguments to an array of CLR objects, and then invoke the external function on the "extObj" object instance. /// </summary> public object Invoke(object extObj, object[] args) { Debug.Assert(this.meth != null, "Must call Bind() before calling Invoke."); Debug.Assert(args.Length == this.argClrTypes.Length, "Mismatched number of actual and formal arguments."); try { return(this.meth.Invoke(extObj, this.flags, null, args, CultureInfo.InvariantCulture)); } catch (TargetInvocationException e) { throw new XslTransformException(e.InnerException, Res.XmlIl_ExtensionError, this.name); } catch (Exception e) { if (!XmlException.IsCatchableException(e)) { throw; } throw new XslTransformException(e, Res.XmlIl_ExtensionError, this.name); } }