* xmlXPathLocationSetFilter: * @ctxt: the XPath Parser context * @locset: the location set to filter * @filterOpIndex: the index of the predicate/filter op * @minPos: minimum position in the filtered set (1-based) * @maxPos: maximum position in the filtered set (1-based) * * Filter a location set, keeping only nodes for which the predicate * expression matches. Afterwards, keep only nodes
| 10602 | * in the filtered result. |
| 10603 | */ |
| 10604 | static void |
| 10605 | xmlXPathLocationSetFilter(xmlXPathParserContextPtr ctxt, |
| 10606 | xmlLocationSetPtr locset, |
| 10607 | int filterOpIndex, |
| 10608 | int minPos, int maxPos) |
| 10609 | { |
| 10610 | xmlXPathContextPtr xpctxt; |
| 10611 | xmlNodePtr oldnode; |
| 10612 | xmlDocPtr olddoc; |
| 10613 | xmlXPathStepOpPtr filterOp; |
| 10614 | int oldcs, oldpp; |
| 10615 | int i, j, pos; |
| 10616 | |
| 10617 | if ((locset == NULL) || (locset->locNr == 0) || (filterOpIndex == -1)) |
| 10618 | return; |
| 10619 | |
| 10620 | xpctxt = ctxt->context; |
| 10621 | oldnode = xpctxt->node; |
| 10622 | olddoc = xpctxt->doc; |
| 10623 | oldcs = xpctxt->contextSize; |
| 10624 | oldpp = xpctxt->proximityPosition; |
| 10625 | filterOp = &ctxt->comp->steps[filterOpIndex]; |
| 10626 | |
| 10627 | xpctxt->contextSize = locset->locNr; |
| 10628 | |
| 10629 | for (i = 0, j = 0, pos = 1; i < locset->locNr; i++) { |
| 10630 | xmlNodePtr contextNode = locset->locTab[i]->user; |
| 10631 | int res; |
| 10632 | |
| 10633 | xpctxt->node = contextNode; |
| 10634 | xpctxt->proximityPosition = i + 1; |
| 10635 | |
| 10636 | /* |
| 10637 | * Also set the xpath document in case things like |
| 10638 | * key() are evaluated in the predicate. |
| 10639 | * |
| 10640 | * TODO: Get real doc for namespace nodes. |
| 10641 | */ |
| 10642 | if ((contextNode->type != XML_NAMESPACE_DECL) && |
| 10643 | (contextNode->doc != NULL)) |
| 10644 | xpctxt->doc = contextNode->doc; |
| 10645 | |
| 10646 | res = xmlXPathCompOpEvalToBoolean(ctxt, filterOp, 1); |
| 10647 | |
| 10648 | if (ctxt->error != XPATH_EXPRESSION_OK) |
| 10649 | break; |
| 10650 | if (res < 0) { |
| 10651 | /* Shouldn't happen */ |
| 10652 | xmlXPathErr(ctxt, XPATH_EXPR_ERROR); |
| 10653 | break; |
| 10654 | } |
| 10655 | |
| 10656 | if ((res != 0) && ((pos >= minPos) && (pos <= maxPos))) { |
| 10657 | if (i != j) { |
| 10658 | locset->locTab[j] = locset->locTab[i]; |
| 10659 | locset->locTab[i] = NULL; |
| 10660 | } |
| 10661 |
no test coverage detected