Inheritance: System.Xml.XmlNamespaceManager
 internal XPathParser(string xpath, XmlNamespaceManager namespaces, IFunctionLibrary[] functionLibraries)
 {
     this.functionLibraries = functionLibraries;
     this.namespaces = namespaces;
     this.lexer = new XPathLexer(xpath);
     this.context = namespaces as XsltContext;
 }
Example #2
0
        internal override void SetXsltContext(XsltContext context){
            System.Diagnostics.Debug.Assert(context != null);
            m_URN = context.LookupNamespace(m_Prefix);
            if (m_qyInput != null)
                m_qyInput.SetXsltContext(context);

        }
Example #3
0
        public object Invoke(System.Xml.Xsl.XsltContext xsltContext, object[] args,
                             XPathNavigator docContext)
        {
            var nodes = args[0] as XPathNodeIterator;

            return(string.Concat(nodes.OfType <XPathNavigator>().Select(xp => xp.Value)));
        }
 /// <summary>
 /// Provides the method to invoke the function with the given arguments in the given context.
 /// </summary>
 /// <returns>
 /// An <see cref="T:System.Object"/> representing the return value of the function. 
 /// </returns>
 /// <param name="xsltContext">
 /// The XSLT context for the function call. 
 /// </param>
 /// <param name="args">
 /// The arguments of the function call. Each argument is an element in the array. 
 /// </param>
 /// <param name="docContext">
 /// The context node for the function call. 
 /// </param>
 public object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
 {
     string sep = Template.ResultToString(args[1]);
     XPathNodeIterator nodeIter = (XPathNodeIterator)args[0];
     string ret = string.Join(sep, nodeIter.Cast<XPathNavigator>().Select(n => n.ToString()));
     return ret;
 }
 public override void SetXsltContext(XsltContext context)
 {
     if (this.arg != null)
     {
         this.arg.SetXsltContext(context);
     }
 }
		public XsltDebuggerContext (XsltDebuggerSession session, XPathNodeIterator currentNodeset, XPathNavigator stylesheetElement, XsltContext xsltContext)
		{
			this.session = session;
			this.nodes = currentNodeset;
			this.style = stylesheetElement;
			this.xsltctx = xsltContext;
		}
            // Function to execute a specified user-defined XPath extension
            // function at run time.
            public object Invoke(System.Xml.Xsl.XsltContext xsltContext,
                                 object[] args, System.Xml.XPath.XPathNavigator docContext)
            {
                if (FunctionName == "CountChar")
                {
                    return((Object)CountChar((XPathNodeIterator)args[0],
                                             Convert.ToChar(args[1])));
                }
                if (FunctionName == "FindTaskBy")
                {
                    return(FindTaskBy((XPathNodeIterator)args[0],
                                      Convert.ToString(args[1])));
                }

                if (FunctionName == "Left")
                {
                    return((Object)Left(Convert.ToString(args[0]),
                                        Convert.ToInt16(args[1])));
                }

                if (FunctionName == "Right")
                {
                    return((Object)Right(Convert.ToString(args[0]),
                                         Convert.ToInt16(args[1])));
                }

                return(null);
            }
Example #8
0
 public override void SetXsltContext(XsltContext context)
 {
     if (context == null)
     {
         throw XPathException.Create(SR.Xp_NoContext);
     }
     if (this.xsltContext != context)
     {
         xsltContext = context;
         foreach (Query argument in _args)
         {
             argument.SetXsltContext(context);
         }
         XPathResultType[] argTypes = new XPathResultType[_args.Count];
         for (int i = 0; i < _args.Count; i++)
         {
             argTypes[i] = _args[i].StaticType;
         }
         _function = xsltContext.ResolveFunction(prefix, name, argTypes);
         // KB article allows to return null, see http://support.microsoft.com/?kbid=324462#6
         if (_function == null)
         {
             throw XPathException.Create(SR.Xp_UndefFunc, QName);
         }
     }
 }
Example #9
0
        public object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext) {
            bool result = false;
            try {
                Navigator nav = null;
                string toTypeName = null;

                if (args.Length == 2) {
                    XPathNodeIterator it = (XPathNodeIterator)args[0];
                    if (it.MoveNext()) {
                        toTypeName = (string)args[1];
                        nav = (Navigator)it.Current;
                    }
                } else {
                    toTypeName = (string)args[0];
                    nav = (Navigator)docContext;
                }

                if (nav.Current is Mono.Cecil.TypeReference) {
                    Mono.Cecil.TypeReference reference = (Mono.Cecil.TypeReference)nav.Current;
                    Type fromType = Type.GetType(reference.FullName);
                    Type toType = Type.GetType(toTypeName);

                    if (fromType != null && toType != null)
                        result = toType.IsAssignableFrom(fromType);
                }

            } catch (Exception e) {
                Console.WriteLine("CanCastTo function failed : \n" + e);
            }
            return result;
        }
Example #10
0
 public override void SetXsltContext(XsltContext context)
 {
     for (int i = 0; i < _argList.Count; i++)
     {
         _argList[i].SetXsltContext(context);
     }
 }
Example #11
0
		public void SetContext(XsltContext context)
		{
			path.SetContext(context);

			if (firstStep != null)
				firstStep.SetContext(context);
		}
        public object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
        {
            switch (function)
            {
                case "document":
                    string url = args.Any() ? (string) args[0] : string.Empty;

                    if (string.IsNullOrWhiteSpace(url)) // When document('') targeting local xsl
                    {
                        throw new ArgumentException("url");

                        //var secondNavigator = docContext.Clone();
                        //secondNavigator.MoveToRoot();
                        //return secondNavigator.Select(".");
                    }
                    // When Url is supplied in document(url)

                    XDocument xDoc =
                        XDocument.Load(Directory.GetCurrentDirectory() + "/SchematronFiles/" + (string) args[0]);
                    XElement rootElement = xDoc.XPathSelectElement("/*");
                    return rootElement.CreateNavigator().Select(".");
            }

            return null;
        }
        // REFACTOR, [....], make this a function on QueryValueModel
        internal XsltFunctionCallOpcode(XsltContext context, IXsltContextFunction function, int argCount)
            : base(OpcodeID.XsltFunction)
        {
            Fx.Assert(null != context && null != function, "");
            this.xsltContext = context;
            this.function = function;
            this.argCount = argCount;

            for (int i = 0; i < function.Maxargs; ++i)
            {
                if (function.ArgTypes[i] == XPathResultType.NodeSet)
                {
                    this.iterList = new List<NodeSequenceIterator>();
                    break;
                }
            }

            // Make sure the return type is valid
            switch (this.function.ReturnType)
            {
                case XPathResultType.String:
                case XPathResultType.Number:
                case XPathResultType.Boolean:
                case XPathResultType.NodeSet:
                    break;

                default:
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryCompileException(QueryCompileError.InvalidType, SR.GetString(SR.QueryFunctionTypeNotSupported, this.function.ReturnType.ToString())));
            }

        }
Example #14
0
 public virtual object Invoke(XsltContext xsltContext, object[] args, System.Xml.XPath.XPathNavigator docContext)
 {
     if (Function != null)
         return Function(xsltContext, args, docContext);
     else
         throw new NotImplementedException("Custom function not implemented. Supply a lamba, or override Invoke()");
 }
Example #15
0
 protected ExtensionQuery(ExtensionQuery other) : base(other)
 {
     this.prefix = other.prefix;
     this.name = other.name;
     this.xsltContext = other.xsltContext;
     _queryIterator = (ResetableIterator)Clone(other._queryIterator);
 }
Example #16
0
 internal override void SetXsltContext(XsltContext context){
     checkWhitespace = context.Whitespace;
     if (checkWhitespace) {
         this.context = context;
     }
     if (_Opnd != null)
         _Opnd.SetXsltContext(context);
 }
Example #17
0
 public override void SetXsltContext(XsltContext context)
 {
     _xsltContext = context.Whitespace ? context : null;
     if (_arg != null)
     {
         _arg.SetXsltContext(context);
     }
 }
 public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
 {
     string str = XPathMessageFunction.ToString(args[0]);
     string xpath = string.Format(CultureInfo.InvariantCulture, "/s11:Envelope/s11:Header/*[@s11:actor='{0}'] | /s12:Envelope/s12:Header/*[@s12:role='{1}']", new object[] { str, str });
     XPathExpression expr = docContext.Compile(xpath);
     expr.SetContext((XmlNamespaceManager) xsltContext);
     return docContext.Evaluate(expr);
 }
 public object Evaluate(XsltContext xsltContext)
 {
     if (this.Value is DateTime)
     {
         return string.Format("{0:u}", this.Value);
     }
     return this.Value;
 }
 public object Evaluate(XsltContext xsltContext){
     object val = null;
     if (tr != null)
         val = tr.GetParameter(name);
     else
         val = ext.GetType().GetProperty(name).GetValue(ext, null);
     return val == null ? "" : val;
 }
Example #21
0
		public override bool Matches (XPathNavigator node, XsltContext ctx)
		{
			XPathNavigator tmp = ((XsltCompiledContext) ctx).GetNavCache (this, node);
			for (int i = 0; i < ids.Length; i++)
				if (tmp.MoveToId (ids [i]) && tmp.IsSamePosition (node))
					return true;
			return false;
		}
 public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
 {
     SeekableMessageNavigator navigator = docContext as SeekableMessageNavigator;
     if (navigator != null)
     {
         return navigator.Message.Version.Envelope.Namespace;
     }
     return ExtractFromNavigator(docContext.Clone());
 }
 public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
 {
     XPathNodeIterator iterator = (XPathNodeIterator) args[0];
     if (!iterator.MoveNext())
     {
         return string.Empty;
     }
     return ExtractFromNavigator(iterator.Current.Clone());
 }
        public object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
        {
            AssetIdentifier aid = AssetIdentifier.Parse(Template.ResultToString(args[0]));

            if (this._ignoredVersionComponent.HasValue)
                return aid.Version.ToString((int)this._ignoredVersionComponent.Value);

            return aid.Version.ToString();
        }
 public override void SetXsltContext(XsltContext input) {
     base.SetXsltContext(input);
     cond.SetXsltContext(input);
     if (cond.StaticType != XPathResultType.Number && cond.StaticType != XPathResultType.Any && noPosition) {
         ReversePositionQuery query = qyInput as ReversePositionQuery;
         if (query != null) {
             qyInput = query.input;
         }
     }
 }
Example #26
0
 internal override void SetXsltContext(XsltContext input) {
     m_qyInput.SetXsltContext(input);
     _opnd.SetXsltContext(input);
     if (_opnd.ReturnType() != XPathResultType.Number) {
         ReversePositionQuery query = m_qyInput as ReversePositionQuery;
         if (query != null) {
             m_qyInput = query.m_qyInput;
         }
     }
 }
 public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
 {
     if (this.expr == null)
     {
         XPathExpression expression = docContext.Compile("(/s11:Envelope/s11:Body | /s12:Envelope/s12:Body)[1]");
         expression.SetContext(XPathMessageFunction.Namespaces);
         this.expr = expression;
     }
     return docContext.Evaluate(this.expr);
 }
    // Constructors

    public DefaultXsltContext(IXmlNamespaceResolver namespaceResolver, string defaultNamsepacePrefix = "",
      IEnumerable<XsltFunction> functions = null) 
    {
      DefaultNamespacePrefix = defaultNamsepacePrefix;
      var systemXmlAssembly = typeof (IXmlNamespaceResolver).Assembly;
      var type = systemXmlAssembly.GetType("MS.Internal.Xml.XPath.CompiledXpathExpr+UndefinedXsltContext", true);
      var ctor = type.GetConstructors().Single();
      baseContext = (XsltContext) ctor.Invoke(new object[] {namespaceResolver});
      this.functions = functions.ToDictionary(f => f.Name, f => f);
    }
 /// <summary>
 ///  Evaluates the expression. If the result is a node set, returns
 /// the first element of the node set.
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public override object ComputeValue( XsltContext context )
 {
     object value1 = fArgs[0].ComputeValue( context );
     object value2 = fArgs[1].ComputeValue( context );
     if ( value1 == null )
     {
         return value2 == null;
     }
     return value1.Equals( value2 );
 }
 public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
 {
     if (this.expr == null)
     {
         XPathExpression expression = docContext.Compile("(sm:header()/wsa10:FaultTo | sm:header()/wsaAugust2004:FaultTo)[1]");
         expression.SetContext((XmlNamespaceManager) new XPathMessageContext());
         this.expr = expression;
     }
     return docContext.Evaluate(this.expr);
 }
        /// <summary>
        /// Provides the method to invoke the function with the given arguments in the given context.
        /// </summary>
        /// <returns>
        /// An <see cref="T:System.Object"/> representing the return value of the function. 
        /// </returns>
        /// <param name="xsltContext">
        /// The XSLT context for the function call. 
        /// </param>
        /// <param name="args">
        /// The arguments of the function call. Each argument is an element in the array. 
        /// </param>
        /// <param name="docContext">
        /// The context node for the function call. 
        /// </param>
        public object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
        {
            //return args.FirstOrDefault(t => !string.IsNullOrEmpty(t as string));
            string s1 = args[0] as string;
            string s2 = args[1] as string;
            int ix = s1.LastIndexOf(s2, StringComparison.Ordinal);
            if (ix >= 0)
                return s1.Substring(ix + 1);

            return string.Empty;
        }
Example #32
0
        public object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
        {
            var input = GetXPathValue(args[0]);
            var pattern = GetXPathValue(args[1]);

            decimal number;
            if (decimal.TryParse(input, out number))
                return number.ToString(pattern);

            return null;
        }
Example #33
0
            public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
            {
                Debug.Assert(args.Length <= this.Minargs, "We cheking this on resolve time");
                for (int i = args.Length - 1; 0 <= i; i--)
                {
                    args[i] = ConvertToXPathType(args[i], this.ArgTypes[i], this.typeCodes[i]);
                }
                object          result    = method.Invoke(extension, args);
                IXPathNavigable navigable = result as IXPathNavigable;

                if (navigable != null)
                {
                    return(navigable.CreateNavigator());
                }
                return(result);
            }
 public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
 {
     if (args.Length > 0)
     {
         XPathNodeIterator it = ToIterator(args[0]);
         if (it.MoveNext())
         {
             return(((XsltCompileContext)xsltContext).GenerateId(it.Current));
         }
         else
         {
             // if empty nodeset, return empty string, otherwise return generated id
             return(string.Empty);
         }
     }
     else
     {
         return(((XsltCompileContext)xsltContext).GenerateId(docContext));
     }
 }
 protected void OnExecute(XPathNodeIterator currentNodeset, XPathNavigator style, XsltContext context)
 {
 }
 protected void OnExecute(XPathNodeIterator currentNodeset, XPathNavigator style, XsltContext context)
 {
     //ShowLocationInTrace (style);
 }
Example #37
0
            // Function to return the value of the specified user-defined variable.
            // The GetParam method of the XsltArgumentList property of the active
            // XsltContext object returns value assigned to the specified variable.
            public object Evaluate(System.Xml.Xsl.XsltContext xsltContext)
            {
                XsltArgumentList vars = ((CustomContext)xsltContext).ArgList;

                return(vars.GetParam(varName, prefix));
            }
 public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
 {
     return(((XsltCompileContext)xsltContext).Current());
 }
 public abstract object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext);
 public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
 {
     return(new XPathSingletonIterator(ToNavigator(args[0])));
 }
 public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
 {
     return(((XsltCompileContext)xsltContext).FormatNumber(ToNumber(args[0]), ToString(args[1]), args.Length == 3 ?ToString(args[2]):null));
 }
 public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
 {
     return(((XsltCompileContext)xsltContext).FunctionAvailable(ToString(args[0])));
 }
 public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
 {
     return(((XsltCompileContext)xsltContext).SystemProperty(ToString(args[0])));
 }
 // Function to return the value of the specified user-defined variable.
 // The GetParam method of the XsltArgumentList property of the active
 // XsltContext object returns value assigned to the specified variable.
 public object Evaluate(System.Xml.Xsl.XsltContext xsltContext)
 {
     return(this.Let.Value);
 }
Example #45
0
 public object Evaluate(System.Xml.Xsl.XsltContext xsltContext)
 {
     return(counter++);
 }
 public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
 {
     throw new XsltException(Res.Xslt_UnsuppFunction, "unparsed-entity-uri");
 }
Example #47
0
 public void OnExecute(XPathNodeIterator currentNodeSet, XPathNavigator style, XsltContext xsltContext)
 {
     Console.Write("Executing: ");
     PrintXPathNavigator(style);
     Console.WriteLine(" / NodeSet: (type {1}) {0} / XsltContext: {2}", currentNodeSet, currentNodeSet.GetType(), xsltContext);
 }
Example #48
0
 object IXsltContextVariable.Evaluate(XsltContext xsltContext)
 {
     return(((XsltCompileContext)xsltContext).EvaluateVariable(this));
 }