Exemple #1
0
 internal int getNonWSCount(XsltContext context)
 {
     if (NonWSCount == 0)
     {
         for (int i = 0; i < _Stk.Count; i++)
         {
             XPathNavigator nav = _Stk[i] as XPathNavigator;
             if (nav.NodeType != XPathNodeType.Whitespace || context.PreserveWhitespace(nav))
             {
                 NonWSCount++;
             }
         }
     }
     return(NonWSCount);
 }
        public override object Evaluate(XPathNodeIterator context)
        {
            XPathNavigator argVal;

            switch (_funcType)
            {
            case FT.FuncPosition:
                return((double)context.CurrentPosition);

            case FT.FuncLast:
                return((double)context.Count);

            case FT.FuncNameSpaceUri:
                argVal = EvaluateArg(context);
                if (argVal != null)
                {
                    return(argVal.NamespaceURI);
                }
                break;

            case FT.FuncLocalName:
                argVal = EvaluateArg(context);
                if (argVal != null)
                {
                    return(argVal.LocalName);
                }
                break;

            case FT.FuncName:
                argVal = EvaluateArg(context);
                if (argVal != null)
                {
                    return(argVal.Name);
                }
                break;

            case FT.FuncCount:
                _arg.Evaluate(context);
                int count = 0;
                if (_xsltContext != null)
                {
                    XPathNavigator nav;
                    while ((nav = _arg.Advance()) != null)
                    {
                        if (nav.NodeType != XPathNodeType.Whitespace || _xsltContext.PreserveWhitespace(nav))
                        {
                            count++;
                        }
                    }
                }
                else
                {
                    while (_arg.Advance() != null)
                    {
                        count++;
                    }
                }
                return((double)count);
            }
            return(string.Empty);
        }
Exemple #3
0
 /// <summary>
 /// When overridden in a derived class, evaluates whether to preserve white space nodes or strip them for the given context.
 /// </summary>
 /// <param name="node">The white space node that is to be preserved or stripped in the current context.</param>
 /// <returns>
 /// Returns true if the white space is to be preserved or false if the white space is to be stripped.
 /// </returns>
 public override bool PreserveWhitespace(XPathNavigator node)
 {
     return(_baseContext.PreserveWhitespace(node));
 }
Exemple #4
0
        internal override object getValue(IQuery qyContext)
        {
            XPathNavigator eNext;

            switch (_FType)
            {
            case FT.FuncPosition:
                if (qyContext != null)
                {
                    return((double)qyContext.Position);
                }
                break;

            case FT.FuncLast:
                if (qyContext != null)
                {
                    if (checkWhitespace)
                    {
                        return((double)((PositionQuery)qyContext).getNonWSCount(context));
                    }
                    try {
                        return((double)((PositionQuery)qyContext).getCount());
                    }
                    catch (Exception) {
                        if (last == -1)
                        {
                            last = 0;
                            IQuery temp = qyContext.Clone();
                            while (temp.advance() != null)
                            {
                                last++;
                            }
                        }
                        return(last);
                    }
                }
                break;

            case FT.FuncCount:
                int i = 0;
                _Opnd.setContext(qyContext.peekElement());
                if (checkWhitespace)
                {
                    XPathNavigator nav;
                    while ((nav = _Opnd.advance()) != null)
                    {
                        if (nav.NodeType != XPathNodeType.Whitespace || context.PreserveWhitespace(nav))
                        {
                            i++;
                        }
                    }
                    return((double)i);
                }
                while (_Opnd.advance() != null)
                {
                    i++;
                }
                return((double)i);

            case FT.FuncNameSpaceUri:
                if (_Opnd != null)
                {
                    _Opnd.setContext(qyContext.peekElement());
                    if ((eNext = _Opnd.advance()) != null)
                    {
                        return(eNext.NamespaceURI);
                    }
                    else
                    {
                        return(String.Empty);
                    }
                }
                return(qyContext.peekElement().NamespaceURI);

            case FT.FuncLocalName:
                if (_Opnd != null)
                {
                    _Opnd.setContext(qyContext.peekElement().Clone());
                    if ((eNext = _Opnd.advance()) != null)
                    {
                        return(eNext.LocalName);
                    }
                    else
                    {
                        return(String.Empty);
                    }
                }
                return(qyContext.peekElement().LocalName);

            case FT.FuncName:
                if (_Opnd != null)
                {
                    _Opnd.setContext(qyContext.peekElement().Clone());
                    if ((eNext = _Opnd.advance()) != null)
                    {
                        return(eNext.Name);
                    }
                    else
                    {
                        return(String.Empty);
                    }
                }
                return(qyContext.peekElement().Name);
            }
            return(String.Empty);
        }