public override object Evaluate(BaseIterator iter)
        {
            XsltContext xsltContext = iter.NamespaceManager as XsltContext;

            if (xsltContext == null)
            {
                throw new XPathException(string.Format("XSLT context is required to resolve variable. Current namespace manager in current node-set '{0}' is '{1}'", iter.GetType(), (iter.NamespaceManager == null) ? null : iter.NamespaceManager.GetType()));
            }
            IXsltContextVariable xsltContextVariable;

            if (this.resolvedName)
            {
                xsltContextVariable = xsltContext.ResolveVariable(this._name);
            }
            else
            {
                xsltContextVariable = xsltContext.ResolveVariable(new XmlQualifiedName(this._name.Name, this._name.Namespace));
            }
            if (xsltContextVariable == null)
            {
                throw new XPathException("variable " + this._name.ToString() + " not found");
            }
            object            obj = xsltContextVariable.Evaluate(xsltContext);
            XPathNodeIterator xpathNodeIterator = obj as XPathNodeIterator;

            if (xpathNodeIterator != null)
            {
                return((!(xpathNodeIterator is BaseIterator)) ? new WrapperIterator(xpathNodeIterator, iter.NamespaceManager) : xpathNodeIterator);
            }
            return(obj);
        }
        internal override void SetXsltContext(XsltContext context)
        {
            if (context == null)
            {
                throw new XPathException(Res.Xp_UndefinedXsltContext, Prefix, Name);
            }

            if (xsltContextVariable == null)
            {
                xsltContextVariable = context.ResolveVariable(Prefix, Name);
                Debug.Assert(xsltContextVariable != null, "XSLT has to resolve it or throw exception");
            }
            else
            {
                Debug.Assert(xsltContextVariable == context.ResolveVariable(Prefix, Name), "ResolveVariable supposed to return the same VariableAction each time");
            }
            Object result = xsltContextVariable.Evaluate(context);

            if (result is double)
            {
                _VarQuery = new OperandQuery(result, XPathResultType.Number);
            }
            else if (result is String)
            {
                _VarQuery = new OperandQuery(result, XPathResultType.String);
            }
            else if (result is Boolean)
            {
                _VarQuery = new OperandQuery(result, XPathResultType.Boolean);
            }
            else if (result is XPathNavigator)
            {
                _VarQuery = new NavigatorQuery((XPathNavigator)result);
            }
            else if (result is ResetableIterator)
            {
                ResetableIterator it = result as ResetableIterator;
                _VarQuery = new XmlIteratorQuery((ResetableIterator)it.Clone());
            }
            else if (result is XPathNodeIterator)
            {
                Debug.Assert(false, "Unexpected type of XPathNodeIterator");
                throw new NotSupportedException(Res.GetString(Res.XmlUnsupportedType, result.GetType().FullName));
            }
            else if (result is int)
            {
                _VarQuery = new OperandQuery(XmlConvert.ToXPathDouble(result), XPathResultType.Number);
            }
            else
            {
                if (result == null)
                {
                    throw new XPathException(Res.Xslt_InvalidVariable, Name);
                }
                Debug.Assert(false, "Unexpected variable type");
                throw new NotSupportedException(Res.GetString(Res.XmlUnsupportedType, result.GetType().FullName));
            }
            Debug.Assert(_VarQuery != null);
        }
 public override IXsltContextVariable ResolveVariable(string prefix, string name)
 {
     if (m_AdditionalContext != null)
     {
         return(m_AdditionalContext.ResolveVariable(prefix, name));
     }
     else
     {
         return(null);
     }
 }
Exemple #4
0
        /// <summary>
        /// When overridden in a derived class, resolves a variable reference and returns an
        /// <see cref="T:System.Xml.Xsl.IXsltContextVariable"/> representing the variable.
        /// </summary>
        /// <param name="prefix">The prefix of the variable as it appears in the XPath expression.</param>
        /// <param name="name">The name of the variable.</param>
        /// <returns>
        /// An <see cref="T:System.Xml.Xsl.IXsltContextVariable"/> representing the variable at runtime.
        /// </returns>
        public override IXsltContextVariable ResolveVariable(string prefix, string name)
        {
            if (_variableResolver != null)
            {
                var variable = _variableResolver.ResolveVariable(prefix, name);
                if (variable != null)
                {
                    return(variable);
                }
            }

            return(_baseContext.ResolveVariable(prefix, name));
        }
Exemple #5
0
        public override void SetXsltContext(XsltContext context)
        {
            if (context == null)
            {
                throw XPathException.Create(SR.Xp_NoContext);
            }

            if (this.xsltContext != context)
            {
                xsltContext = context;
                _variable   = xsltContext.ResolveVariable(prefix, name);
                // Since null is allowed for ResolveFunction, allow it for ResolveVariable as well
                if (_variable == null)
                {
                    throw XPathException.Create(SR.Xp_UndefVar, QName);
                }
            }
        }
Exemple #6
0
 public override IXsltContextVariable ResolveVariable(string prefix, string name)
 {
     return(context.ResolveVariable(prefix, name));
 }