Item GenericPredicate::mapToItem(const Item &item, const DynamicContext::Ptr &context) const { const Item::Iterator::Ptr it(m_operand2->evaluateSequence(context)); const Item pcateItem(it->next()); if(!pcateItem) return Item(); /* The predicate evaluated to the empty sequence */ else if(pcateItem.isNode()) return item; /* Ok, now it must be an AtomicValue */ else if(BuiltinTypes::numeric->xdtTypeMatches(pcateItem.type())) { /* It's a positional predicate. */ if(it->next()) { context->error(QtXmlPatterns::tr("A positional predicate must " "evaluate to a single numeric " "value."), ReportContext::FORG0006, this); return Item(); } if(Double::isEqual(static_cast<xsDouble>(context->contextPosition()), pcateItem.as<Numeric>()->toDouble())) { return item; } else return Item(); } else if(Boolean::evaluateEBV(pcateItem, it, context)) /* It's a truth predicate. */ return item; else return Item(); }
Item PositionFN::evaluateSingleton(const DynamicContext::Ptr &context) const { Q_ASSERT(context); return Integer::fromValue(context->contextPosition()); }