Пример #1
0
        public BaseIterator SortedSelect(XslTransformProcessor p)
        {
            if (isSorterContextDependent)
            {
                for (int i = 0; i < sorters.Length; i++)
                {
                    if (sorterTemplates [i].IsContextDependent)
                    {
                        sorters [i] = sorterTemplates [i].ToXPathSorter(p);
                    }
                }
            }
            BaseIterator iter = (BaseIterator)p.Select(select);

            p.PushNodeset(iter);
            p.PushForEachContext();
            ArrayList list = new ArrayList(iter.Count);

            while (iter.MoveNext())
            {
                XPathSortElement item = new XPathSortElement();
                item.Navigator = iter.Current.Clone();
                item.Values    = new object [sorters.Length];
                for (int i = 0; i < sorters.Length; i++)
                {
                    item.Values [i] = sorters [i].Evaluate(iter);
                }
                list.Add(item);
            }
            p.PopForEachContext();
            p.PopNodeset();

            sortRunner.CopyFrom(sorters);
            return(sortRunner.Sort(list, iter.NamespaceManager));
        }
        public BaseIterator SortedSelect(XslTransformProcessor p)
        {
            if (this.isSorterContextDependent)
            {
                for (int i = 0; i < this.sorters.Length; i++)
                {
                    if (this.sorterTemplates[i].IsContextDependent)
                    {
                        this.sorters[i] = this.sorterTemplates[i].ToXPathSorter(p);
                    }
                }
            }
            BaseIterator baseIterator = (BaseIterator)p.Select(this.select);

            p.PushNodeset(baseIterator);
            p.PushForEachContext();
            ArrayList arrayList = new ArrayList(baseIterator.Count);

            while (baseIterator.MoveNext())
            {
                XPathSortElement xpathSortElement = new XPathSortElement();
                xpathSortElement.Navigator = baseIterator.Current.Clone();
                xpathSortElement.Values    = new object[this.sorters.Length];
                for (int j = 0; j < this.sorters.Length; j++)
                {
                    xpathSortElement.Values[j] = this.sorters[j].Evaluate(baseIterator);
                }
                arrayList.Add(xpathSortElement);
            }
            p.PopForEachContext();
            p.PopNodeset();
            this.sortRunner.CopyFrom(this.sorters);
            return(this.sortRunner.Sort(arrayList, baseIterator.NamespaceManager));
        }
        public override bool Matches(XPathNavigator node, XsltContext ctx)
        {
            if (!this.nodeTest.Match(ctx, node))
            {
                return(false);
            }
            if (this.nodeTest is NodeTypeTest && ((NodeTypeTest)this.nodeTest).type == XPathNodeType.All && (node.NodeType == XPathNodeType.Root || node.NodeType == XPathNodeType.Attribute))
            {
                return(false);
            }
            if (this.filter == null && this.patternPrevious == null)
            {
                return(true);
            }
            XPathNavigator navCache;

            if (this.patternPrevious != null)
            {
                navCache = ((XsltCompiledContext)ctx).GetNavCache(this, node);
                if (this.isAncestor)
                {
                    while (navCache.MoveToParent())
                    {
                        if (this.patternPrevious.Matches(navCache, ctx))
                        {
                            goto IL_D9;
                        }
                    }
                    return(false);
                }
                navCache.MoveToParent();
                if (!this.patternPrevious.Matches(navCache, ctx))
                {
                    return(false);
                }
            }
IL_D9:
            if (this.filter == null)
            {
                return(true);
            }
            if (!this.filter.IsPositional && !(this.filter.expr is ExprFilter))
            {
                return(this.filter.pred.EvaluateBoolean(new NullIterator(node, ctx)));
            }
            navCache = ((XsltCompiledContext)ctx).GetNavCache(this, node);
            navCache.MoveToParent();
            BaseIterator baseIterator = this.filter.EvaluateNodeSet(new NullIterator(navCache, ctx));

            while (baseIterator.MoveNext())
            {
                if (node.IsSamePosition(baseIterator.Current))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #4
0
        public override bool Matches(XPathNavigator node, XsltContext ctx)
        {
            if (!nodeTest.Match(ctx, node))
            {
                return(false);
            }

            if (nodeTest is NodeTypeTest)
            {
                // node () is different in xslt patterns
                if (((NodeTypeTest)nodeTest).type == XPathNodeType.All &&
                    (node.NodeType == XPathNodeType.Root ||
                     node.NodeType == XPathNodeType.Attribute)
                    )
                {
                    return(false);
                }
            }

            if (filter == null && patternPrevious == null)
            {
                return(true);
            }

            XPathNavigator tmpNav;

            if (patternPrevious != null)
            {
                tmpNav = ((XsltCompiledContext)ctx).GetNavCache(this, node);
                if (!isAncestor)
                {
                    tmpNav.MoveToParent();
                    if (!patternPrevious.Matches(tmpNav, ctx))
                    {
                        return(false);
                    }
                }
                else
                {
                    while (true)
                    {
                        if (!tmpNav.MoveToParent())
                        {
                            return(false);
                        }

                        if (patternPrevious.Matches(tmpNav, ctx))
                        {
                            break;
                        }
                    }
                }
            }


            if (filter == null)
            {
                return(true);
            }

            // Optimization for non-positional predicate
            if (!filter.IsPositional && !(filter.expr is ExprFilter))
            {
                return(filter.pred.EvaluateBoolean(new NullIterator(node, ctx)));
            }

            tmpNav = ((XsltCompiledContext)ctx).GetNavCache(this, node);
            tmpNav.MoveToParent();

            BaseIterator matches = filter.EvaluateNodeSet(new NullIterator(tmpNav, ctx));

            while (matches.MoveNext())
            {
                if (node.IsSamePosition(matches.Current))
                {
                    return(true);
                }
            }

            return(false);
        }